### Question:
FlavorInRegionToHardware implements Function<FlavorInRegion, Hardware> { @Override public Hardware apply(FlavorInRegion flavorInRegion) { Location location = locationIndex.get().get(flavorInRegion.getRegion()); checkState(location != null, "location %s not in locationIndex: %s", flavorInRegion.getRegion(), locationIndex.get()); Flavor flavor = flavorInRegion.getFlavor(); return new HardwareBuilder().id(flavorInRegion.slashEncode()).providerId(flavor.getId()).name(flavor.getName()) .ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume( new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build(); } @Inject  FlavorInRegionToHardware(Supplier<Map<String, Location>> locationIndex); @Override Hardware apply(FlavorInRegion flavorInRegion);  }### Answer:
@Test public void testConversionWhereLocationFound() { UUID id = UUID.randomUUID(); FlavorInRegion flavorInRegionToConvert = new FlavorInRegion(Flavor.builder().id(id.toString()) .name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "az-1.region-a.geo-1"); Hardware converted = new FlavorInRegionToHardware(locationIndex).apply(flavorInRegionToConvert); Flavor flavorToConvert = flavorInRegionToConvert.getFlavor(); assertEquals(converted.getName(), flavorToConvert.getName()); assertEquals(converted.getId(), flavorInRegionToConvert.slashEncode()); assertEquals(converted.getProviderId(), flavorToConvert.getId()); assertEquals(converted.getLocation(), locationIndex.get().get("az-1.region-a.geo-1")); assertEquals(converted.getRam(), flavorToConvert.getRam()); assertNotNull(converted.getProcessors()); assertFalse(converted.getProcessors().isEmpty()); assertEquals(converted.getProcessors().iterator().next().getCores(), (double) flavorToConvert.getVcpus()); assertNotNull(converted.getVolumes()); assertFalse(converted.getVolumes().isEmpty()); assertEquals(converted.getVolumes().iterator().next().getSize(), Float.valueOf(flavorToConvert.getDisk())); }
@Test(expectedExceptions = IllegalStateException.class) public void testConversionWhereLocationNotFound() { UUID id = UUID.randomUUID(); FlavorInRegion flavorInRegionToConvert = new FlavorInRegion(Flavor.builder().id(id.toString()) .name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "South"); new FlavorInRegionToHardware(locationIndex).apply(flavorInRegionToConvert); }