### Question:
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") public Credential putCredential(Credential credential) { setFideliusEnvironment(credential.getAccount(), credential.getRegion()); String user = fideliusRoleService.getUserProfile().getUserId(); try { String version = fideliusService.putCredential(credential.getShortKey(), credential.getSecret(), credential.getApplication(), credential.getEnvironment(), credential.getComponent(), tableName, user, kmsKey); credential.setLastUpdatedBy(user); credential.setSecret(null); } catch (Exception e) { this.logger.info("Credential not created " + e.toString()); return null; } return credential; }  @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<Credential> getAllCredentials(String tableName, String account, String region, String application); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") Credential getCredential(String account, String region, String application, String longKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account, \"LIST_CREDENTIALS\")") List<HistoryEntry> getCredentialHistory(String tableName, String account, String region, String application, String environment, String component, String key); @PreAuthorize("@fideliusRoleService.isAuthorized(#application, #account)") Credential getCredentialSecret(String account, String region, String application, String environment,
                                      String component, String shortKey); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential putCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") Credential createCredential(Credential credential); @PreAuthorize("@fideliusRoleService.isAuthorizedToDelete(#credential.getApplication(), #credential.getAccount())") Credential deleteCredential(Credential credential);  }### Answer:
@Test public void putCredentialDoesNotGetCreated() throws Exception { Credential credential = new Credential(); credential.setAccount("dev"); credential.setRegion("us-east-1"); credential.setApplication("membership"); credential.setEnvironment("environment"); credential.setComponent("testComponent"); credential.setShortKey("shortKey"); credential.setSecret("secretPassword"); doThrow(new Exception("Error Created Credential.")).when(fideliusService).putCredential(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); Credential actual = credentialsService.putCredential(credential); assertNull(actual); }
@Test public void putCredential() throws Exception { Credential credential = new Credential(); credential.setAccount("dev"); credential.setRegion("us-east-1"); credential.setApplication("membership"); credential.setEnvironment("environment"); credential.setComponent("testComponent"); credential.setShortKey("shortKey"); credential.setSecret("secretPassword"); Mockito.doReturn("000000000000000001").when(fideliusService).putCredential(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); Credential actual = credentialsService.putCredential(credential); assertEquals(credential, actual); }