### Question:
OpenStackFlavorVerifier { public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } }  void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups);  }### Answer:
@Test public void testAllFlavorsFound() { List<Group> instanceGroups = ImmutableList.of(createGroup("flavor1"), createGroup("flavor2")); doReturn(ImmutableList.of(createFlavor("flavor1"), createFlavor("flavor2"))).when(flavorService).list(); underTest.flavorsExist(osClient, instanceGroups); }
@Test(expected = CloudConnectorException.class) public void nullInstanceGroup() { try { underTest.flavorsExist(osClient, null); } catch (Exception e) { Assert.assertEquals("Cannot validate Flavors if InstanceGroup is null", e.getMessage()); throw e; } }
@Test(expected = CloudConnectorException.class) public void openStackNullFlavor() { try { Group g1 = new Group("name", InstanceGroupType.GATEWAY, new ArrayList<>(), null, null, null, "loginUserName", "publicKey", 50, Optional.empty()); List<Group> instanceGroups = ImmutableList.of(g1); when(flavorService.list()).thenReturn(null); underTest.flavorsExist(osClient, instanceGroups); } catch (Exception e) { Assert.assertEquals("No flavor found on OpenStack", e.getMessage()); throw e; } }
@Test(expected = CloudConnectorException.class) public void openStackFlavorsNotFound() { try { List<Group> instanceGroups = ImmutableList.of(createGroup("flavor3"), createGroup("flavor2")); doReturn(ImmutableList.of(createFlavor("flavor1"), createFlavor("flavor2"))).when(flavorService).list(); underTest.flavorsExist(osClient, instanceGroups); } catch (Exception e) { Assert.assertEquals("Not found flavors: [flavor3]", e.getMessage()); throw e; } }