### Question:
HandshakeSessionHandler implements MinecraftSessionHandler { @VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; } HandshakeSessionHandler(MinecraftConnection connection, VelocityServer server); @Override boolean handle(LegacyPing packet); @Override boolean handle(LegacyHandshake packet); @Override boolean handle(Handshake handshake); @Override void handleGeneric(MinecraftPacket packet); @Override void handleUnknown(ByteBuf buf);  }### Answer:
@Test void cleanVhostHandlesGoodHostname() { assertEquals("localhost", cleanVhost("localhost")); assertEquals("mc.example.com", cleanVhost("mc.example.com")); }
@Test void cleanVhostHandlesTrailingOctet() { assertEquals("localhost", cleanVhost("localhost.")); assertEquals("mc.example.com", cleanVhost("mc.example.com.")); }
@Test void cleanVhostHandlesForge() { assertEquals("localhost", cleanVhost("localhost" + HANDSHAKE_HOSTNAME_TOKEN)); assertEquals("mc.example.com", cleanVhost("mc.example.com" + HANDSHAKE_HOSTNAME_TOKEN)); }
@Test void cleanVhostHandlesOctetsAndForge() { assertEquals("localhost", cleanVhost("localhost." + HANDSHAKE_HOSTNAME_TOKEN)); assertEquals("mc.example.com", cleanVhost("mc.example.com." + HANDSHAKE_HOSTNAME_TOKEN)); }
@Test void cleanVhostHandlesEmptyHostnames() { assertEquals("", cleanVhost("")); assertEquals("", cleanVhost(HANDSHAKE_HOSTNAME_TOKEN)); assertEquals("", cleanVhost(".")); assertEquals("", cleanVhost("." + HANDSHAKE_HOSTNAME_TOKEN)); }