### Question:
Mammoth { public void timePasses() { if (state.getClass().equals(PeacefulState.class)) { changeStateTo(new AngryState(this)); } else { changeStateTo(new PeacefulState(this)); } } Mammoth(); void timePasses(); @Override String toString(); void observe();  }### Answer:
@Test public void testTimePasses() { final var mammoth = new Mammoth(); mammoth.observe(); assertEquals("The mammoth is calm and peaceful.", appender.getLastMessage()); assertEquals(1, appender.getLogSize()); mammoth.timePasses(); assertEquals("The mammoth gets angry!", appender.getLastMessage()); assertEquals(2, appender.getLogSize()); mammoth.observe(); assertEquals("The mammoth is furious!", appender.getLastMessage()); assertEquals(3, appender.getLogSize()); mammoth.timePasses(); assertEquals("The mammoth calms down.", appender.getLastMessage()); assertEquals(4, appender.getLogSize()); mammoth.observe(); assertEquals("The mammoth is calm and peaceful.", appender.getLastMessage()); assertEquals(5, appender.getLogSize()); }
@Test public void testTimePasses() { final Mammoth mammoth = new Mammoth(); mammoth.observe(); assertEquals("The mammoth is calm and peaceful.", appender.getLastMessage()); assertEquals(1, appender.getLogSize()); mammoth.timePasses(); assertEquals("The mammoth gets angry!", appender.getLastMessage()); assertEquals(2, appender.getLogSize()); mammoth.observe(); assertEquals("The mammoth is furious!", appender.getLastMessage()); assertEquals(3, appender.getLogSize()); mammoth.timePasses(); assertEquals("The mammoth calms down.", appender.getLastMessage()); assertEquals(4, appender.getLogSize()); mammoth.observe(); assertEquals("The mammoth is calm and peaceful.", appender.getLastMessage()); assertEquals(5, appender.getLogSize()); }
@Test public void testTimePasses() { final InOrder inOrder = Mockito.inOrder(this.stdOutMock); final Mammoth mammoth = new Mammoth(); mammoth.observe(); inOrder.verify(this.stdOutMock).println("The mammoth is calm and peaceful."); inOrder.verifyNoMoreInteractions(); mammoth.timePasses(); inOrder.verify(this.stdOutMock).println("The mammoth gets angry!"); inOrder.verifyNoMoreInteractions(); mammoth.observe(); inOrder.verify(this.stdOutMock).println("The mammoth is furious!"); inOrder.verifyNoMoreInteractions(); mammoth.timePasses(); inOrder.verify(this.stdOutMock).println("The mammoth calms down."); inOrder.verifyNoMoreInteractions(); mammoth.observe(); inOrder.verify(this.stdOutMock).println("The mammoth is calm and peaceful."); inOrder.verifyNoMoreInteractions(); }