### Question:
KnoxTokenCredentialCollector extends AbstractCredentialCollector { @Override public void collect() throws CredentialCollectionException { try { String knoxtoken = getCachedKnoxToken(); if (knoxtoken != null) { Map<String, String> attrs = JsonUtils.getMapFromJsonString(knoxtoken); value = attrs.get("access_token"); targetUrl = attrs.get("target_url"); tokenType = attrs.get("token_type"); endpointPublicCertPem = attrs.get("endpoint_public_cert"); expiresIn = Long.parseLong(attrs.get("expires_in")); if (expiresIn > 0) { Date expires = new Date(expiresIn); if (expires.before(new Date())) { throw new CredentialCollectionException("Cached knox token has expired. Please relogin through knoxinit."); } } } else { throw new CredentialCollectionException("Cached knox token cannot be found. Please login through knoxinit."); } } catch (IOException e) { throw new CredentialCollectionException("Cached knox token cannot be read. Please login through knoxinit.", e); } }  @Override void collect(); String getTargetUrl(); String getTokenType(); String getEndpointClientCertPEM(); long getExpiresIn(); @Override String type(); static final String COLLECTOR_TYPE; }### Answer:
@Test public void testEmptyTokenCache() { try { File tokenCacheFile = getTokenCacheFile(); if (tokenCacheFile.exists()) { tokenCacheFile.delete(); } assertTrue(tokenCacheFile.createNewFile()); } catch (Exception e) { fail("Could not create empty Knox token cache file: " + e.getMessage()); } boolean caughtCredentialCollectionException = false; KnoxTokenCredentialCollector collector = new KnoxTokenCredentialCollector(); try { collector.collect(); } catch (CredentialCollectionException e) { caughtCredentialCollectionException = true; } catch (Exception e) { fail("Unexpected exception: " + e.getMessage()); } finally { try { getTokenCacheFile().delete(); } catch (Exception e) { } } assertTrue("Expected exception not thrown.", caughtCredentialCollectionException); }