Commit 45091647 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add unit test for cassandra health checker"

Closes gh-15583
parent db22a817
...@@ -27,6 +27,7 @@ import org.springframework.data.cassandra.core.CassandraOperations; ...@@ -27,6 +27,7 @@ import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.cql.CqlOperations; import org.springframework.data.cassandra.core.cql.CqlOperations;
import static org.assertj.core.api.Assertions.assertThat; 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.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -36,12 +37,12 @@ import static org.mockito.Mockito.mock; ...@@ -36,12 +37,12 @@ import static org.mockito.Mockito.mock;
* *
* @author Oleksii Bondar * @author Oleksii Bondar
*/ */
public class CassandraHealthIndicatorTests { public class CassandraHealthIndicatorTests {
@Test(expected = IllegalArgumentException.class) @Test
public void throwsExceptionOnNullCassandraOperations() { public void createWhenCassandraOperationsIsNullShouldThrowException() {
new CassandraHealthIndicator(null); assertThatIllegalArgumentException()
.isThrownBy(() -> new CassandraHealthIndicator(null));
} }
@Test @Test
...@@ -54,9 +55,7 @@ public class CassandraHealthIndicatorTests { ...@@ -54,9 +55,7 @@ public class CassandraHealthIndicatorTests {
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations); given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet); given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
given(resultSet.isExhausted()).willReturn(true); given(resultSet.isExhausted()).willReturn(true);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
} }
...@@ -74,9 +73,7 @@ public class CassandraHealthIndicatorTests { ...@@ -74,9 +73,7 @@ public class CassandraHealthIndicatorTests {
given(resultSet.one()).willReturn(row); given(resultSet.one()).willReturn(row);
String expectedVersion = "1.0.0"; String expectedVersion = "1.0.0";
given(row.getString(0)).willReturn(expectedVersion); given(row.getString(0)).willReturn(expectedVersion);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo(expectedVersion); assertThat(health.getDetails().get("version")).isEqualTo(expectedVersion);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment