ClosedState extends ComponentStateImp { public static ClosedState getInstance() { if (instance == null) { instance = new ClosedState(); } return instance; } private  ClosedState(); @Override void requestInit(StateManagedComponent comp); @Override void requestStart(StateManagedComponent comp); static ClosedState getInstance();  }
@Test public void testInstance() throws Exception { ClosedState one = ClosedState.getInstance(); assertTrue(one == ClosedState.getInstance()); assertEquals(ClosedState.getInstance(), one); assertEquals(ClosedState.class.getSimpleName(), one.toString()); }
@Test public void testClosed_To_Stopped() throws Exception { MockConnection channel = new MockConnection(); ClosedState state = ClosedState.getInstance(); state.requestStop(channel); assertEquals(ClosedState.getInstance(), channel.retrieveComponentState()); assertEquals(0, channel.getInitCount()); assertEquals(0, channel.getStartCount()); assertEquals(0, channel.getStopCount()); assertEquals(0, channel.getCloseCount()); }
@Test public void testClosed_To_Closed() throws Exception { MockConnection channel = new MockConnection(); ClosedState state = ClosedState.getInstance(); state.requestClose(channel); assertEquals(ClosedState.getInstance(), channel.retrieveComponentState()); assertEquals(0, channel.getInitCount()); assertEquals(0, channel.getStartCount()); assertEquals(0, channel.getStopCount()); assertEquals(0, channel.getCloseCount()); }
@Test public void testRestart() throws Exception { MockConnection channel = new MockConnection(); ClosedState state = ClosedState.getInstance(); state.requestRestart(channel); assertEquals(StartedState.getInstance(), channel.retrieveComponentState()); assertEquals(1, channel.getInitCount()); assertEquals(1, channel.getStartCount()); assertEquals(0, channel.getStopCount()); assertEquals(0, channel.getCloseCount()); }