AutonomiccsServiceOfferingService { protected ServiceOfferingVO searchServiceOfferingByName(String name) { List<ServiceOfferingVO> allServiceOffering = serviceOfferingDao.listAll(); for(ServiceOfferingVO so : allServiceOffering){ if (name.equals(so.getUniqueName())) { return so; } } throw new CloudRuntimeException(String.format("Could not find Autonomiccs System VMs service offering using name [%s]", name)); }  ServiceOfferingVO searchAutonomiccsServiceOffering(); ServiceOfferingVO searchServiceOfferingById(long id); void createAutonomiccsServiceOffering();  }
@Test public void searchServiceOfferingByNameTest() { List<ServiceOfferingVO> allServiceOffering = createServiceOfferingVOList(1); Mockito.doReturn(allServiceOffering).when(serviceOfferingDao).listAll(); ServiceOfferingVO result = spy.searchServiceOfferingByName("serviceOfferingVoName"); Mockito.verify(serviceOfferingDao).listAll(); Assert.assertEquals(allServiceOffering.get(0), result); }
@Test(expected = CloudRuntimeException.class) public void searchServiceOfferingByNameTestExpectCloudRuntimeException() { List<ServiceOfferingVO> allServiceOffering = createServiceOfferingVOList(1); Mockito.doReturn(allServiceOffering).when(serviceOfferingDao).listAll(); spy.searchServiceOfferingByName("thisNameDoesNotExist"); }