### Question:
CredentialsService { @PreAuthorize("@fideliusRoleService.isAuthorized(#credential.application, #credential.account)") public Credential createCredential(Credential credential) { List<HistoryEntry> existingCredentials = getCredentialHistory(tableName, credential.getAccount(), credential.getRegion(), credential.getApplication(), credential.getEnvironment(), credential.getComponent(), credential.getShortKey()); if (!existingCredentials.isEmpty()) { throw new FideliusException("Credential already exists!", HttpStatus.BAD_REQUEST); } return putCredential(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(expected = FideliusException.class) public void createCredentialShouldNotCreateDuplicateCredentials() throws FideliusException { List<DBCredential> fakeData = new ArrayList<>(); DBCredential fakeCred = new DBCredential(); fakeCred.setName("APP.dev.testComponent.testKey"); fakeCred.setVersion("0001"); fakeCred.setUpdatedBy("Jon Snow"); fakeCred.setUpdatedDate("2018-04-04T12:51:37.803Z"); fakeData.add(fakeCred); Credential credential = new Credential(); credential.setAccount("dev"); credential.setRegion("us-east-1"); credential.setApplication("APP"); credential.setEnvironment("dev"); credential.setComponent("testComponent"); credential.setShortKey("testKey"); credential.setSecret("secretPassword"); when(dynamoDBService.queryDynamoDB(any(), eq(DBCredential.class), any())).thenReturn(fakeData); Credential result = credentialsService.createCredential(credential); }