Skip to content

Commit

Permalink
Use assertThat instead of assertNotEquals (apache#29858)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jan 25, 2024
1 parent 2691ec9 commit 5e6575b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.OrderByItemSegment;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock;

class OrderByItemTest {

@SuppressWarnings({"SimplifiableAssertion", "ConstantValue"})
@Test
void assertEqualsWhenObjIsNull() {
assertNotEquals(null, new OrderByItem(mock(OrderByItemSegment.class)));
assertFalse(new OrderByItem(mock(OrderByItemSegment.class)).equals(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

class DataNodeTest {
Expand All @@ -50,13 +50,14 @@ void assertNewValidDataNodeWithInvalidDelimiter() {
assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode("ds_0,tbl_0"));
}

@SuppressWarnings({"SimplifiableAssertion", "ConstantValue"})
@Test
void assertEquals() {
DataNode dataNode = new DataNode("ds_0.tbl_0");
assertThat(dataNode, is(new DataNode("ds_0.tbl_0")));
assertThat(dataNode, is(dataNode));
assertThat(dataNode, not(new DataNode("ds_0.tbl_1")));
assertNotEquals(null, dataNode);
assertFalse(dataNode.equals(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -98,9 +98,10 @@ void assertEquals() {
is(new DataSourcePoolProperties(MockedDataSource.class.getName(), createUserProperties("root"))));
}

@SuppressWarnings({"SimplifiableAssertion", "ConstantValue"})
@Test
void assertNotEqualsWithNullValue() {
assertNotEquals(null, new DataSourcePoolProperties(MockedDataSource.class.getName(), new HashMap<>()));
assertFalse(new DataSourcePoolProperties(MockedDataSource.class.getName(), new HashMap<>()).equals(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

class RecordSingleTableInventoryCalculatedResultTest {

Expand Down Expand Up @@ -64,14 +64,14 @@ void assertFullTypeRecordsEqualsWithDifferentDecimalScale() {
void assertRecordsCountNotEquals() {
RecordSingleTableInventoryCalculatedResult result1 = new RecordSingleTableInventoryCalculatedResult(1000, Collections.singletonList(buildFixedFullTypeRecord()));
RecordSingleTableInventoryCalculatedResult result2 = new RecordSingleTableInventoryCalculatedResult(1000, Collections.emptyList());
assertNotEquals(result1, result2);
assertThat(result1, not(result2));
}

@Test
void assertMaxUniqueKeyValueNotEquals() {
RecordSingleTableInventoryCalculatedResult result1 = new RecordSingleTableInventoryCalculatedResult(1000, Collections.singletonList(buildFixedFullTypeRecord()));
RecordSingleTableInventoryCalculatedResult result2 = new RecordSingleTableInventoryCalculatedResult(1001, Collections.singletonList(buildFixedFullTypeRecord()));
assertNotEquals(result1, result2);
assertThat(result1, not(result2));
}

@Test
Expand All @@ -81,7 +81,7 @@ void assertRandomColumnValueNotEquals() {
record.forEach((key, value) -> {
RecordSingleTableInventoryCalculatedResult result2 = new RecordSingleTableInventoryCalculatedResult(1000,
Collections.singletonList(modifyColumnValueRandomly(buildFixedFullTypeRecord(), key)));
assertNotEquals(result1, result2);
assertThat(result1, not(result2));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

import java.util.Properties;

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

class TableDataConsistencyCheckerFactoryTest {

Expand All @@ -41,6 +42,6 @@ void assertNewInstanceTypeMatched() {
void assertNewInstancesDifferent() {
TableDataConsistencyChecker actual1 = TableDataConsistencyCheckerFactory.newInstance("DATA_MATCH", new Properties());
TableDataConsistencyChecker actual2 = TableDataConsistencyCheckerFactory.newInstance("DATA_MATCH", new Properties());
assertNotEquals(actual1, actual2);
assertThat(actual1, not(actual2));
}
}

0 comments on commit 5e6575b

Please sign in to comment.