ResourceManager { public List<? extends Resource> getAvailableResources(String accountId) throws NotFoundException, ServerException { final Account account = accountManager.getById(accountId); final AvailableResourcesProvider availableResourcesProvider = accountTypeToAvailableResourcesProvider.get(account.getType()); if (availableResourcesProvider == null) { return defaultAvailableResourcesProvider.getAvailableResources(accountId); } return availableResourcesProvider.getAvailableResources(accountId); } @Inject  ResourceManager(
      ResourceAggregator resourceAggregator,
      Set<ResourcesProvider> resourcesProviders,
      Set<ResourceUsageTracker> usageTrackers,
      AccountManager accountManager,
      Map<String, AvailableResourcesProvider> accountTypeToAvailableResourcesProvider,
      DefaultAvailableResourcesProvider defaultAvailableResourcesProvider); List<? extends Resource> getTotalResources(String accountId); List<? extends Resource> getAvailableResources(String accountId); List<? extends Resource> getUsedResources(String accountId); void checkResourcesAvailability(String accountId, List<? extends Resource> resources); ResourcesDetails getResourceDetails(String accountId);  }
@Test public void testGetsAvailableResources() throws Exception { final List<ResourceImpl> availableResources = ImmutableList.of(new ResourceImpl("RAM", 2048, "mb")); doReturn(availableResources) .when(accountTypeToAvailableResourcesProvider) .getAvailableResources(ACCOUNT_ID); List<? extends Resource> actual = resourceManager.getAvailableResources(ACCOUNT_ID); assertEquals(actual.size(), availableResources.size()); assertTrue(actual.containsAll(availableResources)); }
@Test(expectedExceptions = NotFoundException.class) public void testThrowsNotFoundExceptionWhenAccountWithGivenIdNotFound() throws Exception { doThrow(NotFoundException.class).when(accountManager).getById(ACCOUNT_ID); resourceManager.getAvailableResources(ACCOUNT_ID); }
@Test(expectedExceptions = NotFoundException.class) public void testThrowsNotFoundExceptionWhenAvailableResourcesForGivenAccountNotFound() throws Exception { doThrow(NotFoundException.class) .when(accountTypeToAvailableResourcesProvider) .getAvailableResources(ACCOUNT_ID); resourceManager.getAvailableResources(ACCOUNT_ID); }
@Test(expectedExceptions = ServerException.class) public void testThrowsServerExceptionWhenErrorOccursWhileGettingAvailableResources() throws Exception { doThrow(ServerException.class).when(accountManager).getById(ACCOUNT_ID); resourceManager.getAvailableResources(ACCOUNT_ID); }