### Question:
SauceLabsRestApi { public int getMaxConcurrency() { LOGGER.entering(); if (maxTestCase == -1) { try { SauceLabsHttpResponse result = doSauceRequest("/limits"); JsonObject obj = result.getEntityAsJsonObject(); maxTestCase = obj.get("concurrency").getAsInt(); } catch (JsonSyntaxException | IllegalStateException | IOException e) { LOGGER.log(Level.SEVERE, "Unable to get max concurrency.", e); } } LOGGER.exiting(maxTestCase); return maxTestCase; } 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 getMaxConcurrency() throws Exception { SauceLabsHttpResponse mockHttpResponse = mock(SauceLabsHttpResponse.class); doReturn(mockApiResult).when(mockHttpResponse, "getEntity"); when(mockHttpResponse.getEntityAsJsonObject()).thenCallRealMethod(); SauceLabsRestApi apiMock = mock(SauceLabsRestApi.class); Whitebox.setInternalState(apiMock, "maxTestCase", -1); doReturn(mockHttpResponse).when(apiMock, "doSauceRequest", Mockito.anyString()); when(apiMock.getMaxConcurrency()).thenCallRealMethod(); assertEquals(apiMock.getMaxConcurrency(), 5); }