OffHeapConfigValidator implements ConfigValidator { protected Map<String, ResourceType> createOffHeapResourceMap(OffheapResourcesType offheapResourcesType) { return offheapResourcesType.getResource().stream().collect(Collectors.toMap( ResourceType::getName, Function.identity())); } OffHeapConfigValidator(Function<Element, OffheapResourcesType> resourcesTypeSupplier); void validateAgainst(Element oneFragment, Element otherFragment);  }
@Test public void testCreateOffHeapResourceMap() { Function<Element, OffheapResourcesType> OffheapResourcesType = mock(Function.class); OffHeapConfigValidator validator = new OffHeapConfigValidator(OffheapResourcesType); OffheapResourcesType offHeapResources = new OffheapResourcesType(); ResourceType resourceType1 = new ResourceType(); resourceType1.setUnit(MemoryUnit.MB); resourceType1.setValue(BigInteger.valueOf(64L)); resourceType1.setName("resource1"); ResourceType resourceType2 = new ResourceType(); resourceType2.setUnit(MemoryUnit.MB); resourceType2.setValue(BigInteger.valueOf(128L)); resourceType2.setName("resource2"); ResourceType resourceType3 = new ResourceType(); resourceType3.setUnit(MemoryUnit.GB); resourceType3.setValue(BigInteger.valueOf(64L)); resourceType3.setName("resource3"); offHeapResources.getResource().add(resourceType1); offHeapResources.getResource().add(resourceType2); offHeapResources.getResource().add(resourceType3); Map<String, ResourceType> resourceMap = validator.createOffHeapResourceMap(offHeapResources); assertThat(resourceMap, notNullValue()); assertThat(resourceMap.size(), is(3)); Set<String> expectedResourceNames = new HashSet<>(); expectedResourceNames.add("resource1"); expectedResourceNames.add("resource2"); expectedResourceNames.add("resource3"); assertThat(resourceMap.keySet().equals(expectedResourceNames), is(true)); assertThat(resourceMap.get("resource1") == resourceType1, is(true)); assertThat(resourceMap.get("resource2") == resourceType2, is(true)); assertThat(resourceMap.get("resource3") == resourceType3, is(true)); }