BearerTokenManager extends ComponentSupport { public boolean deleteToken() { final PrincipalCollection principals = securityHelper.subject().getPrincipals(); if (apiKeyStore.getApiKey(format, principals) != null) { apiKeyStore.deleteApiKey(format, securityHelper.subject().getPrincipals()); return true; } return false; } @Inject  BearerTokenManager(final ApiKeyStore apiKeyStore,
                            final SecurityHelper securityHelper,
                            final String format); boolean deleteToken();  }
@Test public void deleteKey() throws Exception { when(apiKeyStore.getApiKey(any(), any())).thenReturn(TOKEN.toCharArray()); assertTrue(underTest.deleteToken()); verify(apiKeyStore).deleteApiKey(FORMAT, principalCollection); }
@Test public void doNotDeleteKeyWhenNoKeyExists() throws Exception { when(apiKeyStore.getApiKey(any(), any())).thenReturn(null); assertFalse(underTest.deleteToken()); verify(apiKeyStore, never()).deleteApiKey(FORMAT, principalCollection); }