ServerNameIndicationExtensionPreparator extends ExtensionPreparator<ServerNameIndicationExtensionMessage> { @Override public void prepareExtensionContent() { LOGGER.debug("Preparing ServerNameIndicationExtensionMessage"); stream = new ByteArrayOutputStream(); for (ServerNamePair pair : msg.getServerNameList()) { ServerNamePairPreparator preparator = new ServerNamePairPreparator(chooser, pair); preparator.prepare(); ServerNamePairSerializier serializer = new ServerNamePairSerializier(pair); try { stream.write(serializer.serialize()); } catch (IOException ex) { throw new PreparationException("Could not write byte[] from ServerNamePair", ex); } } prepareServerNameListBytes(msg); prepareServerNameListLength(msg); } ServerNameIndicationExtensionPreparator(Chooser chooser, ServerNameIndicationExtensionMessage message,
            ServerNameIndicationExtensionSerializer serializer); @Override void prepareExtensionContent();  }
@Test public void testPrepareExtensionContentWithOnePair() { List<ServerNamePair> pairList = new LinkedList<>(); ServerNamePair pair = new ServerNamePair(); pair.setServerNameConfig(new byte[] { 0x01, 0x02 }); pair.setServerNameTypeConfig((byte) 1); pair.setServerNameLength(2); pairList.add(pair); message.setServerNameList(pairList); ServerNameIndicationExtensionPreparator serverprep = new ServerNameIndicationExtensionPreparator(chooser, message, serializer); serverprep.prepareExtensionContent(); assertArrayEquals(new byte[] { 0x01, 0x00, 0x02, 0x01, 0x02 }, serverprep.getObject().getServerNameListBytes() .getValue()); assertEquals(5, (long) serverprep.getObject().getServerNameListLength().getOriginalValue()); }
@Test public void testPrepareExtensionContentWithTwoPairs() { List<ServerNamePair> pairList = new LinkedList<>(); ServerNamePair pair = new ServerNamePair(); pair.setServerNameConfig(new byte[] { 0x01, 0x02 }); pair.setServerNameTypeConfig((byte) 1); pair.setServerNameLength(2); pairList.add(pair); ServerNamePair pair2 = new ServerNamePair(); pair2.setServerNameConfig(new byte[] { 0x03, 0x04, 0x05, 0x06 }); pair2.setServerNameTypeConfig((byte) 2); pair2.setServerNameLength(4); pairList.add(pair2); message.setServerNameList(pairList); ServerNameIndicationExtensionPreparator serverprep = new ServerNameIndicationExtensionPreparator(chooser, message, serializer); serverprep.prepareExtensionContent(); assertArrayEquals(new byte[] { 0x01, 0x00, 0x02, 0x01, 0x02, 0x02, 0x00, 0x04, 0x03, 0x04, 0x05, 0x06 }, serverprep.getObject().getServerNameListBytes().getValue()); assertEquals(12, (long) serverprep.getObject().getServerNameListLength().getOriginalValue()); }