Skip to content

Commit e3f2a09

Browse files
committed
Convert test base class to custom assertion to promote best practices
1 parent c1a976e commit e3f2a09

24 files changed

+52
-33
lines changed

junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/AbstractEqualsAndHashCodeTests.java renamed to junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/EqualsAndHashCodeAssertions.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
import static org.assertj.core.api.Assertions.assertThat;
1414

1515
/**
16-
* Abstract base class for unit tests that wish to test
16+
* Assertions for unit tests that wish to test
1717
* {@link Object#equals(Object)} and {@link Object#hashCode()}.
1818
*
1919
* @since 1.3
2020
*/
21-
public abstract class AbstractEqualsAndHashCodeTests {
21+
public class EqualsAndHashCodeAssertions {
2222

23-
protected final <T> void assertEqualsAndHashCode(T equal1, T equal2, T different) {
23+
private EqualsAndHashCodeAssertions() {
24+
}
25+
26+
@SuppressWarnings("EqualsWithItself")
27+
public static <T> void assertEqualsAndHashCode(T equal1, T equal2, T different) {
2428
assertThat(equal1).isNotNull();
2529
assertThat(equal2).isNotNull();
2630
assertThat(different).isNotNull();

jupiter-tests/src/test/java/org/junit/jupiter/api/parallel/LockTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
package org.junit.jupiter.api.parallel;
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
1415
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ;
1516
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ_WRITE;
1617
import static org.junit.jupiter.api.parallel.ResourceLocksProvider.Lock;
1718

18-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
1919
import org.junit.jupiter.api.Test;
2020

2121
/**
2222
* Unit tests for {@link Lock}.
2323
*
2424
* @since 5.12
2525
*/
26-
class LockTests extends AbstractEqualsAndHashCodeTests {
26+
class LockTests {
2727

2828
@Test
2929
void readWriteModeSetByDefault() {

platform-tests/src/test/java/org/junit/platform/engine/discovery/ClassSelectorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.junit.jupiter.api.Assertions.assertThrows;
15+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
1516

16-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
1717
import org.junit.jupiter.api.Test;
1818
import org.junit.platform.commons.PreconditionViolationException;
1919

@@ -23,7 +23,7 @@
2323
* @since 1.3
2424
* @see DiscoverySelectorsTests
2525
*/
26-
class ClassSelectorTests extends AbstractEqualsAndHashCodeTests {
26+
class ClassSelectorTests {
2727

2828
@Test
2929
void equalsAndHashCode() {

platform-tests/src/test/java/org/junit/platform/engine/discovery/ClasspathResourceSelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
package org.junit.platform.engine.discovery;
1212

13-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
13+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
14+
1415
import org.junit.jupiter.api.Test;
1516

1617
/**
@@ -19,7 +20,7 @@
1920
* @since 1.3
2021
* @see DiscoverySelectorsTests
2122
*/
22-
class ClasspathResourceSelectorTests extends AbstractEqualsAndHashCodeTests {
23+
class ClasspathResourceSelectorTests {
2324

2425
@Test
2526
void equalsAndHashCode() {

platform-tests/src/test/java/org/junit/platform/engine/discovery/ClasspathRootSelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
package org.junit.platform.engine.discovery;
1212

13+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
14+
1315
import java.net.URI;
1416

15-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
1617
import org.junit.jupiter.api.Test;
1718

1819
/**
@@ -21,7 +22,7 @@
2122
* @since 1.3
2223
* @see DiscoverySelectorsTests
2324
*/
24-
class ClasspathRootSelectorTests extends AbstractEqualsAndHashCodeTests {
25+
class ClasspathRootSelectorTests {
2526

2627
@Test
2728
void equalsAndHashCode() throws Exception {

platform-tests/src/test/java/org/junit/platform/engine/discovery/DirectorySelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
package org.junit.platform.engine.discovery;
1212

13-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
13+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
14+
1415
import org.junit.jupiter.api.Test;
1516

1617
/**
@@ -19,7 +20,7 @@
1920
* @since 1.3
2021
* @see DiscoverySelectorsTests
2122
*/
22-
class DirectorySelectorTests extends AbstractEqualsAndHashCodeTests {
23+
class DirectorySelectorTests {
2324

2425
@Test
2526
void equalsAndHashCode() {

platform-tests/src/test/java/org/junit/platform/engine/discovery/FilePositionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.junit.jupiter.api.Assertions.assertEquals;
1515
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
1617
import static org.junit.jupiter.params.provider.Arguments.arguments;
1718

1819
import java.util.stream.Stream;
1920

20-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
2121
import org.junit.jupiter.api.DisplayName;
2222
import org.junit.jupiter.api.Test;
2323
import org.junit.jupiter.params.ParameterizedTest;
@@ -31,7 +31,7 @@
3131
* @since 1.7
3232
*/
3333
@DisplayName("FilePosition unit tests")
34-
class FilePositionTests extends AbstractEqualsAndHashCodeTests {
34+
class FilePositionTests {
3535

3636
@Test
3737
@DisplayName("factory method preconditions")

platform-tests/src/test/java/org/junit/platform/engine/discovery/FileSelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
package org.junit.platform.engine.discovery;
1212

13-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
13+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
14+
1415
import org.junit.jupiter.api.Test;
1516

1617
/**
@@ -19,7 +20,7 @@
1920
* @since 1.3
2021
* @see DiscoverySelectorsTests
2122
*/
22-
class FileSelectorTests extends AbstractEqualsAndHashCodeTests {
23+
class FileSelectorTests {
2324

2425
@Test
2526
void equalsAndHashCode() {

platform-tests/src/test/java/org/junit/platform/engine/discovery/MethodSelectorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
15+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
1516

1617
import java.util.stream.Stream;
1718

18-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
1919
import org.junit.jupiter.api.Test;
2020
import org.junit.platform.commons.JUnitException;
2121
import org.junit.platform.commons.PreconditionViolationException;
@@ -26,7 +26,7 @@
2626
* @since 1.3
2727
* @see DiscoverySelectorsTests
2828
*/
29-
class MethodSelectorTests extends AbstractEqualsAndHashCodeTests {
29+
class MethodSelectorTests {
3030

3131
private static final String TEST_CASE_NAME = TestCase.class.getName();
3232

platform-tests/src/test/java/org/junit/platform/engine/discovery/ModuleSelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
package org.junit.platform.engine.discovery;
1212

13-
import org.junit.jupiter.api.AbstractEqualsAndHashCodeTests;
13+
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
14+
1415
import org.junit.jupiter.api.Test;
1516

1617
/**
@@ -19,7 +20,7 @@
1920
* @since 1.3
2021
* @see DiscoverySelectorsTests
2122
*/
22-
class ModuleSelectorTests extends AbstractEqualsAndHashCodeTests {
23+
class ModuleSelectorTests {
2324

2425
@Test
2526
void equalsAndHashCode() {

0 commit comments

Comments
 (0)