### Question:
SauceLabsRestApi { public int getNumberOfTCRunningForSubAccount(String user) { LOGGER.entering(user); int tcRunning = -1; try { SauceLabsHttpResponse result = doSauceRequest("/activity"); JsonObject obj = result.getEntityAsJsonObject(); tcRunning = obj.getAsJsonObject("subaccounts").getAsJsonObject(user).get("all").getAsInt(); } catch (JsonSyntaxException | IllegalStateException | IOException e) { LOGGER.log(Level.SEVERE, "Unable to get number of test cases running for sub-account.", e); } LOGGER.exiting(tcRunning); return tcRunning; } SauceLabsRestApi(); int getNumberOfTCRunning(); int getNumberOfTCRunningForSubAccount(String user); int getMaxConcurrency(); synchronized boolean isAuthenticated(String username, String apiKey); static final int MAX_CACHE; }### Answer:
@Test public void getNumberOfTCRunningForSubAccount() throws Exception { SauceLabsHttpResponse mockHttpResponse = mock(SauceLabsHttpResponse.class); doReturn(mockApiResult).when(mockHttpResponse, "getEntity"); when(mockHttpResponse.getEntityAsJsonObject()).thenCallRealMethod(); SauceLabsRestApi apiMock = mock(SauceLabsRestApi.class); doReturn(mockHttpResponse).when(apiMock, "doSauceRequest", Mockito.anyString()); when(apiMock.getNumberOfTCRunningForSubAccount(Mockito.anyString())).thenCallRealMethod(); assertEquals(apiMock.getNumberOfTCRunningForSubAccount("foobar"), 1); }