ResourceChecker { public DataCenterVO checkIfDataCenterExists(final Long dataCenterId) { logger.debug("Checking if data center" + dataCenterId + " exists"); final DataCenterVO zone = dataCenterDao.findById(dataCenterId); if (zone == null) { final InvalidParameterValueException e = new InvalidParameterValueException("Can't find data center by the id: " + dataCenterId); e.addProxyObject(String.valueOf(dataCenterId), "dcId"); throw e; } logger.debug("Data center " + dataCenterId + "exists"); return zone; } 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_checkIfDataCenterExists_whenDataCenterDoesNotExist() throws Exception { when(dataCenterDao.findById(1L)).thenReturn(null); final ResourceChecker resourceChecker = buildResourceChecker(); resourceChecker.checkIfDataCenterExists(1L); }
@Test public void test_checkIfDataCenterExists_whenDataCenterExists() throws Exception { final DataCenterVO dataCenter = new DataCenterVO(); when(dataCenterDao.findById(1L)).thenReturn(dataCenter); final ResourceChecker resourceChecker = buildResourceChecker(); assertThat(resourceChecker.checkIfDataCenterExists(1L), is(dataCenter)); }