### Question:
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public String testConnection(String crn) { return testConnection(getByCrn(crn)); }  Set<DatabaseServerConfig> findAll(Long workspaceId, String environmentCrn); DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test); DatabaseServerConfig update(DatabaseServerConfig resource); DatabaseServerConfig release(String resourceCrn); @Override DatabaseServerConfig delete(DatabaseServerConfig resource); DatabaseServerConfig getByName(Long workspaceId, String environmentCrn, String name); DatabaseServerConfig getByCrn(String resourceCrn); Optional<DatabaseServerConfig> getByCrn(Crn resourceCrn); Optional<DatabaseServerConfig> getByClusterCrn(String clusterCrn); DatabaseServerConfig deleteByCrn(String crn); @Override JpaRepository repository(); Set<DatabaseServerConfig> getByCrns(Set<String> crns); String testConnection(String crn); String testConnection(DatabaseServerConfig resource); String createDatabaseOnServer(String serverCrn, String databaseName, String databaseType, Optional<String> databaseDescription); @Override AuthorizationResourceType getResourceType(); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount();  }### Answer:
@Test public void testTestConnectionSuccess() { when(repository.findByResourceCrn(SERVER_CRN)).thenReturn(Optional.of(server)); String result = underTest.testConnection(SERVER_CRN.toString()); assertEquals("success", result); verify(connectionValidator).validate(eq(server), any(Errors.class)); }
@Test public void testTestConnectionFailure() { when(repository.findByResourceCrn(SERVER_CRN)).thenReturn(Optional.of(server)); doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Errors errors = invocation.getArgument(1); errors.rejectValue("databaseVendor", "", "bad vendor"); errors.reject("", "epic fail"); return null; } }).when(connectionValidator).validate(eq(server), any(Errors.class)); String result = underTest.testConnection(SERVER_CRN.toString()); assertTrue(result.contains("epic fail")); assertTrue(result.contains("databaseVendor: bad vendor")); verify(connectionValidator).validate(eq(server), any(Errors.class)); }