### Question:
NodeApiVersions { public short usableVersion(ApiKeys apiKey) { return usableVersion(apiKey, null); } 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 testUsableVersionCalculation() { List<ApiVersion> versionList = new ArrayList<>(); versionList.add(new ApiVersion(ApiKeys.CONTROLLED_SHUTDOWN_KEY.id, (short) 0, (short) 0)); versionList.add(new ApiVersion(ApiKeys.FETCH.id, (short) 1, (short) 2)); NodeApiVersions versions = new NodeApiVersions(versionList); try { versions.usableVersion(ApiKeys.CONTROLLED_SHUTDOWN_KEY); Assert.fail("expected UnsupportedVersionException"); } catch (UnsupportedVersionException e) { } assertEquals(2, versions.usableVersion(ApiKeys.FETCH)); }
@Test(expected = UnsupportedVersionException.class) public void testUsableVersionCalculationNoKnownVersions() { List<ApiVersion> versionList = new ArrayList<>(); NodeApiVersions versions = new NodeApiVersions(versionList); versions.usableVersion(ApiKeys.FETCH); }
@Test public void testUsableVersionLatestVersions() { List<ApiVersion> versionList = new LinkedList<>(); for (ApiVersion apiVersion: ApiVersionsResponse.API_VERSIONS_RESPONSE.apiVersions()) { versionList.add(apiVersion); } versionList.add(new ApiVersion((short) 100, (short) 0, (short) 1)); NodeApiVersions versions = new NodeApiVersions(versionList); for (ApiKeys apiKey: ApiKeys.values()) { assertEquals(apiKey.latestVersion(), versions.usableVersion(apiKey)); } }