@Test public void createProtocol() { final Protocol protocol = context.mock(Protocol.class); final ProtocolProvider provider = context.mock(ProtocolProvider.class); context.checking( new Expectations() { { allowing(provider).getProtocol(1337); will(returnValue(protocol)); allowing(provider).getProtocol(with(any(Integer.class))); will(returnValue(null)); } }); prot.addProtocolProvider(provider); assertEquals(protocol, prot.getProtocolById(1337)); assertNull(prot.getProtocolById(1)); }
@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(); }