### Question:
NodeApiVersions { @Override public String toString() { return toString(false); } NodeApiVersions(Collection<ApiVersion> nodeApiVersions); static NodeApiVersions create(); static NodeApiVersions create(Collection<ApiVersion> overrides); short usableVersion(ApiKeys apiKey); short usableVersion(ApiKeys apiKey, Short desiredVersion); @Override String toString(); String toString(boolean lineBreaks); ApiVersion apiVersion(ApiKeys apiKey);  }### Answer:
@Test public void testUnsupportedVersionsToString() { NodeApiVersions versions = new NodeApiVersions(Collections.<ApiVersion>emptyList()); StringBuilder bld = new StringBuilder(); String prefix = "("; for (ApiKeys apiKey : ApiKeys.values()) { bld.append(prefix).append(apiKey.name). append("(").append(apiKey.id).append("): UNSUPPORTED"); prefix = ", "; } bld.append(")"); assertEquals(bld.toString(), versions.toString()); }
@Test public void testUnknownApiVersionsToString() { ApiVersion unknownApiVersion = new ApiVersion((short) 337, (short) 0, (short) 1); NodeApiVersions versions = new NodeApiVersions(Collections.singleton(unknownApiVersion)); assertTrue(versions.toString().endsWith("UNKNOWN(337): 0 to 1)")); }
@Test public void testVersionsToString() { List<ApiVersion> versionList = new ArrayList<>(); for (ApiKeys apiKey : ApiKeys.values()) { if (apiKey == ApiKeys.CONTROLLED_SHUTDOWN_KEY) { versionList.add(new ApiVersion(apiKey.id, (short) 0, (short) 0)); } else if (apiKey == ApiKeys.DELETE_TOPICS) { versionList.add(new ApiVersion(apiKey.id, (short) 10000, (short) 10001)); } else { versionList.add(new ApiVersion(apiKey)); } } NodeApiVersions versions = new NodeApiVersions(versionList); StringBuilder bld = new StringBuilder(); String prefix = "("; for (ApiKeys apiKey : ApiKeys.values()) { bld.append(prefix); if (apiKey == ApiKeys.CONTROLLED_SHUTDOWN_KEY) { bld.append("ControlledShutdown(7): 0 [unusable: node too old]"); } else if (apiKey == ApiKeys.DELETE_TOPICS) { bld.append("DeleteTopics(20): 10000 to 10001 [unusable: node too new]"); } else { bld.append(apiKey.name).append("("). append(apiKey.id).append("): "); if (apiKey.oldestVersion() == apiKey.latestVersion()) { bld.append(apiKey.oldestVersion()); } else { bld.append(apiKey.oldestVersion()). append(" to "). append(apiKey.latestVersion()); } bld.append(" [usable: ").append(apiKey.latestVersion()). append("]"); } prefix = ", "; } bld.append(")"); assertEquals(bld.toString(), versions.toString()); }