### Question:
HelloAggregate extends EventSourcedBehaviorWithEnforcedReplies<HelloCommand, HelloEvent, HelloState> { public static HelloAggregate create(EntityContext<HelloCommand> entityContext) { return new HelloAggregate(entityContext); } HelloAggregate(EntityContext<HelloCommand> entityContext); static HelloAggregate create(EntityContext<HelloCommand> entityContext); @Override HelloState emptyState(); @Override CommandHandlerWithReply<HelloCommand, HelloEvent, HelloState> commandHandler(); @Override EventHandler<HelloState, HelloEvent> eventHandler(); @Override Set<String> tagsFor(HelloEvent shoppingCartEvent); static EntityTypeKey<HelloCommand> ENTITY_TYPE_KEY; }### Answer:
@Test public void testHello() { String id = "Alice"; ActorRef<HelloCommand> ref = testKit.spawn( HelloAggregate.create( new EntityContext(HelloAggregate.ENTITY_TYPE_KEY, id, null) ) ); TestProbe<HelloCommand.Greeting> probe = testKit.createTestProbe(HelloCommand.Greeting.class); ref.tell(new HelloCommand.Hello(id,probe.getRef())); probe.expectMessage(new HelloCommand.Greeting("Hello, Alice!")); }
@Test public void testUpdateGreeting() { String id = "Alice"; ActorRef<HelloCommand> ref = testKit.spawn( HelloAggregate.create( new EntityContext(HelloAggregate.ENTITY_TYPE_KEY, id, null) ) ); TestProbe<HelloCommand.Confirmation> probe1 = testKit.createTestProbe(HelloCommand.Confirmation.class); ref.tell(new HelloCommand.UseGreetingMessage("Hi", probe1.getRef())); probe1.expectMessage(new HelloCommand.Accepted()); TestProbe<HelloCommand.Greeting> probe2 = testKit.createTestProbe(HelloCommand.Greeting.class); ref.tell(new HelloCommand.Hello(id,probe2.getRef())); probe2.expectMessage(new HelloCommand.Greeting("Hi, Alice!")); }