@Test public void changeProtocol() { final Protocol protocol = context.mock(Protocol.class); context.checking( new Expectations() { { oneOf(protocol).init(mockedClient); } }); prot.setCurrentProtocol(protocol); context.assertIsSatisfied(); assertSame(protocol, prot.getCurrentProtocol()); }
@Test public void changesToCorrectProtocol() throws IOException { final Protocol protocol = context.mock(Protocol.class); final ProtocolProvider provider = context.mock(ProtocolProvider.class); context.checking( new Expectations() { { allowing(provider).getProtocol(123); will(returnValue(protocol)); oneOf(protocol).parseFirst(with(any(InputStream.class))); oneOf(protocol).init(mockedClient); } }); prot.addProtocolProvider(provider); ByteArrayOutputStream out = new ByteArrayOutputStream(); CData.writeU16(out, 1); CData.writeByte(out, 123); prot.messageReceived(mockedClient, new ByteArrayInputStream(out.toByteArray())); assertSame(protocol, prot.getCurrentProtocol()); context.assertIsSatisfied(); }
@Test public void defaultProtocolIsItself() { assertSame(prot, prot.getCurrentProtocol()); }