ProtocolVersion { public static void checkVersion(byte[] greetings) throws InvalidFrameException, InvalidProtocolVersionException { if (greetings[0] != 0) throw new InvalidFrameException("cannot extract version from server greetings"); if (greetings[1] != 0) throw new InvalidFrameException("cannot extract version from server greetings"); if (greetings[2] != 'V') throw new InvalidFrameException("cannot extract version from server greetings"); if (!AUTHORIZED_RELEASE.contains(greetings[3])) { throw new InvalidProtocolVersionException(VERSION, greetings[3]); } } protected  ProtocolVersion(); static void checkVersion(byte[] greetings); static final byte VERSION; static final byte[] GREETINGS; }
@Test public void Protocol_should_validate_version_of_server_via_greetings_frame() throws ProtocolVersion.InvalidFrameException, ProtocolVersion.InvalidProtocolVersionException { byte[] greeting = new byte[]{0, 0, 'V', ProtocolVersion.VERSION}; ProtocolVersion.checkVersion(greeting); }
@Test(expected = ProtocolVersion.InvalidProtocolVersionException.class) public void Protocol_should_invalidate_bad_version_of_server_via_greetings() throws ProtocolVersion.InvalidFrameException, ProtocolVersion.InvalidProtocolVersionException { byte[] greeting = new byte[]{0, 0, 'V', ProtocolVersion.VERSION + 1}; ProtocolVersion.checkVersion(greeting); }
@Test(expected = ProtocolVersion.InvalidFrameException.class) public void Protocol_should_refuse_bad_greetings_frame_1() throws ProtocolVersion.InvalidFrameException, ProtocolVersion.InvalidProtocolVersionException { byte[] bad = new byte[]{1, 0, 'V', 1}; ProtocolVersion.checkVersion(bad); }
@Test(expected = ProtocolVersion.InvalidFrameException.class) public void Protocol_should_refuse_bad_greetings_frame_2() throws ProtocolVersion.InvalidFrameException, ProtocolVersion.InvalidProtocolVersionException { byte[] bad = new byte[]{0, 1, 'V', 1}; ProtocolVersion.checkVersion(bad); }
@Test(expected = ProtocolVersion.InvalidFrameException.class) public void Protocol_should_refuse_bad_greetings_frame_3() throws ProtocolVersion.InvalidFrameException, ProtocolVersion.InvalidProtocolVersionException { byte[] bad = new byte[]{0, 0, 3, 1}; ProtocolVersion.checkVersion(bad); }