@Test public void testCreateSuccess() { RegionService regionService = Mockito.mock(RegionService.class); Region region = Mockito.mock(Region.class); Mockito.when( regionService.addRegion( Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(region); addRegionCmd._regionService = regionService; responseGenerator = Mockito.mock(ResponseGenerator.class); RegionResponse regionResponse = Mockito.mock(RegionResponse.class); Mockito.when(responseGenerator.createRegionResponse(region)).thenReturn(regionResponse); addRegionCmd._responseGenerator = responseGenerator; addRegionCmd.execute(); }
@Test public void testCreateFailure() { RegionService regionService = Mockito.mock(RegionService.class); Region region = Mockito.mock(Region.class); Mockito.when( regionService.addRegion( Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(null); addRegionCmd._regionService = regionService; try { addRegionCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add Region", exception.getDescription()); } }