### Question:
DatabaseCriteriaResolver { @NotNull AttemptResult<Object> resolveResultByCriteria(DatabaseOperation databaseOperation, DatabaseServerV4Response rdsStatus, Cluster cluster) { checkArgument(databaseOperation != null, "DatabaseOperation should not be null"); checkArgument(rdsStatus != null, "DatabaseServerV4Response should not be null"); AttemptResult<Object> result; if (databaseOperation.getExitCriteria().apply(rdsStatus.getStatus())) { result = AttemptResults.finishWith(rdsStatus); } else { if (databaseOperation.getFailureCriteria().apply(rdsStatus.getStatus())) { result = rdsStatus.getStatusReason() != null && rdsStatus.getStatusReason().contains("does not exist") ? AttemptResults.finishWith(null) : AttemptResults.breakFor(getDatabaseOperationFailedResultMessage(cluster, rdsStatus)); } else { result = AttemptResults.justContinue(); } } return result; }    }### Answer:
@Test void nullDatabaseOperationThrows() { assertThatThrownBy(() -> underTest.resolveResultByCriteria(null, database, cluster)); }
@Test void nullDatabaseThrows() { assertThatThrownBy(() -> underTest.resolveResultByCriteria(DatabaseOperation.CREATION, null, cluster)); }
@Test void exitCriteria() { database.setStatus(Status.AVAILABLE); AttemptResult<Object> result = underTest.resolveResultByCriteria(DatabaseOperation.CREATION, database, cluster); assertThat(result.getState()).isEqualTo(AttemptState.FINISH); assertThat(result.getResult()).isEqualTo(database); }
@Test void failCriteriaDatabaseNotFound() { database.setStatus(Status.DELETE_COMPLETED); database.setStatusReason("does not exist"); AttemptResult<Object> result = underTest.resolveResultByCriteria(DatabaseOperation.CREATION, database, cluster); assertThat(result.getState()).isEqualTo(AttemptState.FINISH); assertThat(result.getResult()).isNull(); }
@Test void failCriteriaDatabaseFail() { database.setStatus(Status.CREATE_FAILED); AttemptResult<Object> result = underTest.resolveResultByCriteria(DatabaseOperation.CREATION, database, cluster); assertThat(result.getState()).isEqualTo(AttemptState.BREAK); assertThat(result.getResult()).isNull(); }
@Test void neitherExitNorFailure() { database.setStatus(Status.CREATE_IN_PROGRESS); AttemptResult<Object> result = underTest.resolveResultByCriteria(DatabaseOperation.CREATION, database, cluster); assertThat(result.getState()).isEqualTo(AttemptState.CONTINUE); assertThat(result.getResult()).isNull(); }