mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish "Add unit test for cassandra health checker"
Closes gh-15583
This commit is contained in:
parent
db22a81742
commit
4509164789
@ -27,6 +27,7 @@ import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.cql.CqlOperations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -36,12 +37,12 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Oleksii Bondar
|
||||
*/
|
||||
|
||||
public class CassandraHealthIndicatorTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionOnNullCassandraOperations() {
|
||||
new CassandraHealthIndicator(null);
|
||||
@Test
|
||||
public void createWhenCassandraOperationsIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new CassandraHealthIndicator(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -54,9 +55,7 @@ public class CassandraHealthIndicatorTests {
|
||||
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
|
||||
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
|
||||
given(resultSet.isExhausted()).willReturn(true);
|
||||
|
||||
Health health = healthIndicator.health();
|
||||
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@ -74,9 +73,7 @@ public class CassandraHealthIndicatorTests {
|
||||
given(resultSet.one()).willReturn(row);
|
||||
String expectedVersion = "1.0.0";
|
||||
given(row.getString(0)).willReturn(expectedVersion);
|
||||
|
||||
Health health = healthIndicator.health();
|
||||
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails().get("version")).isEqualTo(expectedVersion);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user