@Test public void testExecuteForNullResult() { ResourceService resourceService = Mockito.mock(ResourceService.class); try { Mockito.when(resourceService.discoverCluster(addClusterCmd)).thenReturn(null); } catch (ResourceInUseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DiscoveryException e) { // TODO Auto-generated catch block e.printStackTrace(); } addClusterCmd._resourceService = resourceService; try { addClusterCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add cluster", exception.getDescription()); } }
@Test public void testExecuteForEmptyResult() { ResourceService resourceService = Mockito.mock(ResourceService.class); addClusterCmd._resourceService = resourceService; try { addClusterCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add cluster", exception.getDescription()); } }
@Test public void testExecuteForResult() throws Exception { resourceService = Mockito.mock(ResourceService.class); responseGenerator = Mockito.mock(ResponseGenerator.class); addClusterCmd._resourceService = resourceService; addClusterCmd._responseGenerator = responseGenerator; Cluster cluster = Mockito.mock(Cluster.class); Cluster[] clusterArray = new Cluster[] {cluster}; Mockito.when(resourceService.discoverCluster(addClusterCmd)) .thenReturn(Arrays.asList(clusterArray)); addClusterCmd.execute(); }