ResourceChecker { public void checkIfPodIsUsable(final DataCenter dataCenter, final HostPodVO hostPod) { final long hostPodId = hostPod.getId(); logger.debug("Checking if pod " + hostPodId + " is usable."); if (!hostPod.belongsToDataCenter(dataCenter.getId())) { final String hostPodUuid = hostPod.getUuid(); final String dataCenterUuid = dataCenter.getUuid(); final InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified pod " + hostPodUuid + " doesn't belong to the zone with specified dataCenter " + dataCenterUuid); ex.addProxyObject(hostPodUuid, "podId"); ex.addProxyObject(dataCenterUuid, "dcId"); throw ex; } logger.debug("Pod " + hostPodId + "is usable"); } private  ResourceChecker(final Builder builder); static Builder builder(); DataCenterVO checkIfDataCenterExists(final Long dataCenterId); void checkIfDataCenterIsUsable(final DataCenter dataCenter, final Account account); HostPodVO checkIfPodExists(final Long hostPodId); void checkIfPodIsUsable(final DataCenter dataCenter, final HostPodVO hostPod);  }
@Test(expected = InvalidParameterValueException.class) public void test_checkIfPodIsUsable_whenPodDoesNotBelongToDataCenter() throws Exception { final DataCenterVO dataCenter = new DataCenterVO(); dataCenter.setId(1L); dataCenter.setUuid("DataCenterUUID"); final HostPodVO hostPod = new HostPodVO(); hostPod.setDataCenterId(2L); hostPod.setUuid("HostPodUUID"); final ResourceChecker resourceChecker = buildResourceChecker(); resourceChecker.checkIfPodIsUsable(dataCenter, hostPod); }
@Test public void test_checkIfPodIsUsable_whenPodBelongsToDataCenter() throws Exception { final DataCenterVO dataCenter = new DataCenterVO(); dataCenter.setId(1L); dataCenter.setUuid("DataCenterUUID"); final HostPodVO hostPod = new HostPodVO(); hostPod.setDataCenterId(1L); hostPod.setUuid("HostPodUUID"); final ResourceChecker resourceChecker = buildResourceChecker(); try { resourceChecker.checkIfPodIsUsable(dataCenter, hostPod); } catch (final InvalidParameterValueException e) { fail("No InvalidParameterValueException should have been generated"); } }