From 0a79ca0e973921b2e2a49f560242b023e59bc316 Mon Sep 17 00:00:00 2001 From: Morpheus Date: Sun, 31 Mar 2024 22:19:24 +0000 Subject: [PATCH] Replace leftover hamcrest usage with junit and drop dependency (#2493) --- build.gradle.kts | 1 - gradle/libs.versions.toml | 1 - .../spongepowered/api/data/DataQueryTest.java | 52 ++++----- .../spongepowered/api/event/CauseTest.java | 37 +++--- .../SpongeAbstractDamageEntityEventTest.java | 107 ++++++++---------- .../api/event/SpongeAbstractEventTest.java | 11 +- .../api/matcher/OptionalIsPresent.java | 48 -------- .../api/matcher/OptionalValueIs.java | 63 ----------- .../api/matcher/SpongeMatchers.java | 55 --------- .../api/matcher/package-info.java | 31 ----- 10 files changed, 89 insertions(+), 317 deletions(-) delete mode 100644 src/test/java/org/spongepowered/api/matcher/OptionalIsPresent.java delete mode 100644 src/test/java/org/spongepowered/api/matcher/OptionalValueIs.java delete mode 100644 src/test/java/org/spongepowered/api/matcher/SpongeMatchers.java delete mode 100644 src/test/java/org/spongepowered/api/matcher/package-info.java diff --git a/build.gradle.kts b/build.gradle.kts index c04a6415c2..9409899b2f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -127,7 +127,6 @@ dependencies { testImplementation(libs.junit.params) testRuntimeOnly(libs.junit.engine) testRuntimeOnly(libs.junit.launcher) - testImplementation(libs.hamcrest) testImplementation(libs.mockito) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fb8c18d8a4..0aa6e15d28 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -47,7 +47,6 @@ spoon = { module = "fr.inria.gforge.spoon:spoon-core", version = "10.4.2" } # bu # testing -hamcrest = { module = "org.hamcrest:hamcrest", version = "2.2" } junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } junit-api = { module = "org.junit.jupiter:junit-jupiter-api" } junit-params = { module = "org.junit.jupiter:junit-jupiter-params" } diff --git a/src/test/java/org/spongepowered/api/data/DataQueryTest.java b/src/test/java/org/spongepowered/api/data/DataQueryTest.java index e7ba20e129..ffe5022d87 100644 --- a/src/test/java/org/spongepowered/api/data/DataQueryTest.java +++ b/src/test/java/org/spongepowered/api/data/DataQueryTest.java @@ -24,11 +24,7 @@ */ package org.spongepowered.api.data; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; - -import org.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.spongepowered.api.data.persistence.DataQuery; @@ -55,12 +51,12 @@ void testOfForSeparatorPath() { final DataQuery second = DataQuery.of(',', "this,test,equals"); final DataQuery complex = DataQuery.of('蒂', "this蒂test蒂equals"); final DataQuery test = DataQuery.of("this", "test", "equals"); - MatcherAssert.assertThat(first, is(equalTo(test))); - MatcherAssert.assertThat(first, is(equalTo(second))); - MatcherAssert.assertThat(first, is(equalTo(complex))); - MatcherAssert.assertThat(second, is(equalTo(complex))); - MatcherAssert.assertThat(second, is(equalTo(first))); - MatcherAssert.assertThat(second, is(equalTo(test))); + Assertions.assertEquals(first, test); + Assertions.assertEquals(first, second); + Assertions.assertEquals(first, complex); + Assertions.assertEquals(second, complex); + Assertions.assertEquals(second, first); + Assertions.assertEquals(second, test); } /** @@ -70,8 +66,8 @@ void testOfForSeparatorPath() { void testOfParts() { final DataQuery first = DataQuery.of("this", "parts", "equal"); final DataQuery second = DataQuery.of('.', "this.parts.equal"); - MatcherAssert.assertThat(first, is(equalTo(second))); - MatcherAssert.assertThat(second, is(equalTo(first))); + Assertions.assertEquals(first, second); + Assertions.assertEquals(second, first); } /** @@ -84,7 +80,7 @@ void testGetParts() { parts.add("this"); parts.add("parts"); parts.add("test"); - MatcherAssert.assertThat(query.parts(), is(equalTo(parts))); + Assertions.assertEquals(query.parts(), parts); } /** @@ -95,8 +91,8 @@ void testThen() { final DataQuery query = DataQuery.of("this", "testing"); final DataQuery other = DataQuery.of("this"); final DataQuery test = other.then(DataQuery.of("testing")); - MatcherAssert.assertThat(query, is(equalTo(test))); - MatcherAssert.assertThat(test, is(equalTo(query))); + Assertions.assertEquals(query, test); + Assertions.assertEquals(test, query); } /** @@ -110,10 +106,10 @@ void testGetQueryParts() { final DataQuery part3 = DataQuery.of("query"); final List parts = full.queryParts(); final List built = List.of(part1, part2, part3); - MatcherAssert.assertThat(parts, equalTo(built)); - MatcherAssert.assertThat(built, equalTo(parts)); - MatcherAssert.assertThat(built.containsAll(parts), is(true)); - MatcherAssert.assertThat(parts.containsAll(built), is(true)); + Assertions.assertEquals(parts, built); + Assertions.assertEquals(built, parts); + Assertions.assertTrue(built.containsAll(parts)); + Assertions.assertTrue(parts.containsAll(built)); } /** @@ -123,13 +119,13 @@ void testGetQueryParts() { void testPop() { final DataQuery prePopped = DataQuery.of("this", "test", "query"); final DataQuery expected = DataQuery.of("this", "test"); - MatcherAssert.assertThat(prePopped.pop(), equalTo(expected)); + Assertions.assertEquals(prePopped.pop(), expected); final DataQuery empty = DataQuery.of(); final DataQuery emptyPopped = empty.pop(); - MatcherAssert.assertThat(emptyPopped, equalTo(empty)); + Assertions.assertEquals(emptyPopped, empty); final DataQuery single = DataQuery.of("single"); - MatcherAssert.assertThat(single.pop(), equalTo(empty)); + Assertions.assertEquals(single.pop(), empty); } /** @@ -139,8 +135,8 @@ void testPop() { void testLast() { final DataQuery full = DataQuery.of("first", "test"); final DataQuery lastExpected = DataQuery.of("test"); - MatcherAssert.assertThat(full.last(), equalTo(lastExpected)); - MatcherAssert.assertThat(lastExpected, equalTo(full.last())); + Assertions.assertEquals(full.last(), lastExpected); + Assertions.assertEquals(lastExpected, full.last()); } /** @@ -151,9 +147,9 @@ void testEquals() { final DataQuery query1 = DataQuery.of("test"); final DataQuery query2 = DataQuery.of("test"); final DataQuery nonEqual = DataQuery.of("nope"); - MatcherAssert.assertThat(query1, equalTo(query1)); - MatcherAssert.assertThat(query1, equalTo(query2)); - MatcherAssert.assertThat(query1, is(not(nonEqual))); + Assertions.assertEquals(query1, query1); + Assertions.assertEquals(query1, query2); + Assertions.assertNotEquals(query1, nonEqual); } } diff --git a/src/test/java/org/spongepowered/api/event/CauseTest.java b/src/test/java/org/spongepowered/api/event/CauseTest.java index 903a6699c1..85ae8d7391 100644 --- a/src/test/java/org/spongepowered/api/event/CauseTest.java +++ b/src/test/java/org/spongepowered/api/event/CauseTest.java @@ -24,18 +24,8 @@ */ package org.spongepowered.api.event; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.Matchers.equalToObject; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.core.Is.is; - -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.spongepowered.api.matcher.SpongeMatchers; import java.util.List; import java.util.Optional; @@ -56,9 +46,10 @@ void testNullCause() { void testWithCause() { final Cause old = Cause.of(EventContext.empty(), "foo"); final Cause newCause = old.with("bar"); - MatcherAssert.assertThat(old, is(not(newCause))); + Assertions.assertNotEquals(old, newCause); final List list = newCause.all(); - MatcherAssert.assertThat(list, containsInAnyOrder("foo", "bar")); + Assertions.assertTrue(list.contains("foo")); + Assertions.assertTrue(list.contains("bar")); } @Test @@ -71,44 +62,44 @@ void testWithNullCause() { void testToString() { final Cause cause = Cause.builder().append("foo").append("bar").append(1).append(2).build(EventContext.empty()); final String causeString = cause.toString(); - MatcherAssert.assertThat(causeString, not(emptyString())); + Assertions.assertFalse(causeString.isEmpty()); } @Test void testBefore() { final Cause cause = Cause.builder().append("foo").append(1).append(2).build(EventContext.empty()); final Optional optional = cause.before(Integer.class); - MatcherAssert.assertThat(optional, is(SpongeMatchers.present())); - MatcherAssert.assertThat(optional, SpongeMatchers.valueIs(equalToObject("foo"))); + Assertions.assertTrue(optional.isPresent()); + Assertions.assertEquals(optional.get(), "foo"); } @Test void testAfter() { final Cause cause = Cause.builder().append("foo").append(1).append(2).build(EventContext.empty()); final Optional optional = cause.after(Integer.class); - MatcherAssert.assertThat(optional, is(SpongeMatchers.present())); - MatcherAssert.assertThat(optional, SpongeMatchers.valueIs(equalToObject(2))); + Assertions.assertTrue(optional.isPresent()); + Assertions.assertEquals(optional.get(), 2); } @Test void testNoneAfter() { final Cause cause = Cause.builder().append("foo").append(1).build(EventContext.empty()); final Optional optional = cause.after(Integer.class); - MatcherAssert.assertThat(optional, is(not(SpongeMatchers.present()))); + Assertions.assertTrue(optional.isEmpty()); } @Test void testNoneBefore() { final Cause cause = Cause.builder().append("foo").append(1).build(EventContext.empty()); final Optional optional = cause.before(String.class); - MatcherAssert.assertThat(optional, is(not(SpongeMatchers.present()))); + Assertions.assertTrue(optional.isEmpty()); } @Test void testNoneOf() { final Cause cause = Cause.builder().append("foo").append(1).append(2).append(3).build(EventContext.empty()); - MatcherAssert.assertThat(cause.noneOf(Integer.class), hasSize(1)); - MatcherAssert.assertThat(cause.noneOf(Integer.class).get(0), is("foo")); + Assertions.assertEquals(cause.noneOf(Integer.class).size(), 1); + Assertions.assertEquals(cause.noneOf(Integer.class).get(0), "foo"); } @Test @@ -116,8 +107,8 @@ void testListedArray() { final List fooList = List.of("foo", "bar", "baz", "floof"); final Cause cause = Cause.builder().append("foo").append("bar").append("baz").append("floof").build(EventContext.empty()); final List stringList = cause.allOf(String.class); - MatcherAssert.assertThat(stringList, is(not(empty()))); - MatcherAssert.assertThat(stringList, is(fooList)); + Assertions.assertFalse(stringList.isEmpty()); + Assertions.assertEquals(stringList, fooList); } } diff --git a/src/test/java/org/spongepowered/api/event/SpongeAbstractDamageEntityEventTest.java b/src/test/java/org/spongepowered/api/event/SpongeAbstractDamageEntityEventTest.java index 2f2ce05b62..6e3b4bbba9 100644 --- a/src/test/java/org/spongepowered/api/event/SpongeAbstractDamageEntityEventTest.java +++ b/src/test/java/org/spongepowered/api/event/SpongeAbstractDamageEntityEventTest.java @@ -24,12 +24,6 @@ */ package org.spongepowered.api.event; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.aMapWithSize; -import static org.hamcrest.Matchers.closeTo; - -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.spongepowered.api.entity.Entity; @@ -56,11 +50,11 @@ void testParams() { final DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), targetEntity, new ArrayList<>(), originalDamage); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.finalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.baseDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.finalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.baseDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); } @Test @@ -71,16 +65,16 @@ void testSetBaseDamage() { final DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), targetEntity, new ArrayList<>(), originalDamage); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); event.setBaseDamage(20); - MatcherAssert.assertThat(event.baseDamage(), is(closeTo(20, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.finalDamage(), is(closeTo(20, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.baseDamage(), 20, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.finalDamage(), 20, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); } @Test @@ -103,24 +97,22 @@ void testUseModifiers() { targetEntity, originalFunctions, originalDamage); final List originalFunctions1 = event.originalFunctions(); - MatcherAssert.assertThat(originalFunctions1, is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(originalFunctions1, originalFunctions); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR); final Map originalDamages = event.originalDamages(); - MatcherAssert.assertThat(originalDamages, is(aMapWithSize(originalFunctions.size()))); + Assertions.assertEquals(originalDamages.size(), originalFunctions.size()); - MatcherAssert.assertThat(originalDamages.get(firstModifer), is(closeTo(firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(originalDamages.get(secondModifier), is(closeTo(secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(originalDamages.get(firstModifer), firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(originalDamages.get(secondModifier), secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalModifierDamage(firstModifer), is(closeTo(firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalModifierDamage(secondModifier), is(closeTo(secondModifierDamage, - SpongeAbstractDamageEntityEventTest.ERROR - ))); + Assertions.assertEquals(event.originalModifierDamage(firstModifer), firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalModifierDamage(secondModifier), secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalFunctions(), is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(event.originalFunctions(), originalFunctions); } @Test @@ -147,28 +139,25 @@ void testSetModifiers() { final DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), targetEntity, originalFunctions, originalDamage); - MatcherAssert.assertThat(event.originalFunctions(), is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(event.originalFunctions(), originalFunctions); final DoubleUnaryOperator newFunction = p -> p; event.setDamage(firstModifer, newFunction); - MatcherAssert.assertThat(event.damage(firstModifer), is(closeTo(firstChangedDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.damage(secondModifier), is(closeTo(secondChangedDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.damage(firstModifer), firstChangedDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.damage(secondModifier), secondChangedDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalModifierDamage(firstModifer), is(closeTo(firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalModifierDamage(secondModifier), is(closeTo(secondModifierDamage, - SpongeAbstractDamageEntityEventTest.ERROR - ))); + Assertions.assertEquals(event.originalModifierDamage(firstModifer), firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalModifierDamage(secondModifier), secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.finalDamage(), is(closeTo(modifiedFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.finalDamage(), modifiedFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalFunctions(), is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(event.originalFunctions(), originalFunctions); - MatcherAssert.assertThat(event.modifiers(), - is(Matchers.equalTo(Arrays.asList(DamageFunction.of(firstModifer, newFunction), originalFunctions.get(1))))); + Assertions.assertEquals(event.modifiers(), Arrays.asList(DamageFunction.of(firstModifer, newFunction), originalFunctions.get(1))); } @Test @@ -192,7 +181,7 @@ void testAddModifier() { final DoubleUnaryOperator thirdFunction = p -> p; final List - originalFunctions = Arrays.asList(DamageFunction.of(firstModifier, p -> p * 2), DamageFunction.of(secondModifier, p -> p * 5)); + originalFunctions = Arrays.asList(DamageFunction.of(firstModifier, p -> p * 2), DamageFunction.of(secondModifier, p -> p * 5)); final List newFunctions = new ArrayList<>(originalFunctions); newFunctions.add(DamageFunction.of(thirdModifier, thirdFunction)); @@ -200,28 +189,26 @@ void testAddModifier() { final DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), targetEntity, originalFunctions, originalDamage); - MatcherAssert.assertThat(event.originalFunctions(), is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(event.originalFunctions(), originalFunctions); - MatcherAssert.assertThat(event.isModifierApplicable(thirdModifier), is(false)); + Assertions.assertFalse(event.isModifierApplicable(thirdModifier)); event.setDamage(thirdModifier, thirdFunction); - MatcherAssert.assertThat(event.damage(firstModifier), is(closeTo(firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.damage(secondModifier), is(closeTo(secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.damage(thirdModifier), is(closeTo(thirdDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.damage(firstModifier), firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.damage(secondModifier), secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.damage(thirdModifier), thirdDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalModifierDamage(firstModifier), is(closeTo(firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalModifierDamage(secondModifier), is(closeTo(secondModifierDamage, - SpongeAbstractDamageEntityEventTest.ERROR - ))); + Assertions.assertEquals(event.originalModifierDamage(firstModifier), firstModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalModifierDamage(secondModifier), secondModifierDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalDamage(), is(closeTo(originalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.originalFinalDamage(), is(closeTo(originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); - MatcherAssert.assertThat(event.finalDamage(), is(closeTo(modifiedFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR))); + Assertions.assertEquals(event.originalDamage(), originalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.originalFinalDamage(), originalFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR); + Assertions.assertEquals(event.finalDamage(), modifiedFinalDamage, SpongeAbstractDamageEntityEventTest.ERROR); - MatcherAssert.assertThat(event.originalFunctions(), is(Matchers.equalTo(originalFunctions))); + Assertions.assertEquals(event.originalFunctions(), originalFunctions); - MatcherAssert.assertThat(event.modifiers(), is(Matchers.equalTo(newFunctions))); + Assertions.assertEquals(event.modifiers(), newFunctions); } @Test @@ -232,14 +219,14 @@ void testModifiersApplicable() { final DamageModifier secondModifier = this.mockParam(DamageModifier.class); final List - originalFunctions = Arrays.asList(DamageFunction.of(firstModifer, p -> p), DamageFunction.of(secondModifier, p -> p)); + originalFunctions = Arrays.asList(DamageFunction.of(firstModifer, p -> p), DamageFunction.of(secondModifier, p -> p)); final DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), targetEntity, originalFunctions, 0); - MatcherAssert.assertThat(event.isModifierApplicable(firstModifer), is(true)); - MatcherAssert.assertThat(event.isModifierApplicable(secondModifier), is(true)); - MatcherAssert.assertThat(event.isModifierApplicable(this.mockParam(DamageModifier.class)), is(false)); + Assertions.assertTrue(event.isModifierApplicable(firstModifer)); + Assertions.assertTrue(event.isModifierApplicable(secondModifier)); + Assertions.assertFalse(event.isModifierApplicable(this.mockParam(DamageModifier.class))); } @Test @@ -249,7 +236,7 @@ void testNotApplicableModifer() { final DamageModifier modifier = this.mockParam(DamageModifier.class); - MatcherAssert.assertThat(event.isModifierApplicable(modifier), is(false)); + Assertions.assertFalse(event.isModifierApplicable(modifier)); Assertions.assertThrows(IllegalArgumentException.class, () -> event.originalModifierDamage(modifier)); } diff --git a/src/test/java/org/spongepowered/api/event/SpongeAbstractEventTest.java b/src/test/java/org/spongepowered/api/event/SpongeAbstractEventTest.java index aa74dd4dcf..fab0fa4da6 100644 --- a/src/test/java/org/spongepowered/api/event/SpongeAbstractEventTest.java +++ b/src/test/java/org/spongepowered/api/event/SpongeAbstractEventTest.java @@ -24,10 +24,7 @@ */ package org.spongepowered.api.event; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; - -import org.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.spongepowered.api.data.DataHolder; import org.spongepowered.api.data.DataTransactionResult; @@ -48,12 +45,12 @@ void testValueChangeEvent() { final DataTransactionResult modified = DataTransactionResult.successNoData(); final ChangeDataHolderEvent.ValueChange event = SpongeEventFactory.createChangeDataHolderEventValueChange( - Cause.of(EventContext.empty(), "none"), original, this.mockParam(DataHolder.Mutable.class)); + Cause.of(EventContext.empty(), "none"), original, this.mockParam(DataHolder.Mutable.class)); - MatcherAssert.assertThat(event.originalChanges(), is(equalTo(original))); + Assertions.assertEquals(event.originalChanges(), original); event.proposeChanges(modified); - MatcherAssert.assertThat(event.endResult(), is(equalTo(modified))); + Assertions.assertEquals(event.endResult(), modified); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/spongepowered/api/matcher/OptionalIsPresent.java b/src/test/java/org/spongepowered/api/matcher/OptionalIsPresent.java deleted file mode 100644 index 42d3a99f8d..0000000000 --- a/src/test/java/org/spongepowered/api/matcher/OptionalIsPresent.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.api.matcher; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; - -import java.util.Optional; - -final class OptionalIsPresent extends TypeSafeMatcher> { - - @Override - protected boolean matchesSafely(final Optional item) { - return item.isPresent(); - } - - @Override - public void describeTo(final Description description) { - description.appendText("a present optional"); - } - - @Override - protected void describeMismatchSafely(final Optional item, final Description mismatchDescription) { - mismatchDescription.appendText("was not present"); - } -} diff --git a/src/test/java/org/spongepowered/api/matcher/OptionalValueIs.java b/src/test/java/org/spongepowered/api/matcher/OptionalValueIs.java deleted file mode 100644 index 4a893590c5..0000000000 --- a/src/test/java/org/spongepowered/api/matcher/OptionalValueIs.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.api.matcher; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; - -import java.util.Optional; - -final class OptionalValueIs extends TypeSafeDiagnosingMatcher> { - - private final Matcher elementMatcher; - - OptionalValueIs(final Matcher elementMatcher) { - this.elementMatcher = elementMatcher; - } - - @Override - protected boolean matchesSafely(final Optional item, final Description mismatchDescription) { - if (!item.isPresent()) { - mismatchDescription.appendText("was not present"); - return false; - } - - if (!this.elementMatcher.matches(item.get())) { - mismatchDescription.appendText("was present but "); - this.elementMatcher.describeMismatch(item.get(), mismatchDescription); - return false; - } - - return true; - } - - @Override - public void describeTo(final Description description) { - description.appendText("a present Optional with value ") - .appendDescriptionOf(this.elementMatcher); - } - -} diff --git a/src/test/java/org/spongepowered/api/matcher/SpongeMatchers.java b/src/test/java/org/spongepowered/api/matcher/SpongeMatchers.java deleted file mode 100644 index 55840780f7..0000000000 --- a/src/test/java/org/spongepowered/api/matcher/SpongeMatchers.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.api.matcher; - -import org.hamcrest.Matcher; -import org.hamcrest.Matchers; - -import java.util.Objects; -import java.util.Optional; - -public final class SpongeMatchers { - - private static final OptionalIsPresent OPTIONAL_IS_PRESENT = new OptionalIsPresent<>(); - - @SuppressWarnings({"unchecked", "rawtypes"}) - public static Matcher> present() { - return (Matcher) SpongeMatchers.OPTIONAL_IS_PRESENT; - } - - public static Matcher> valueIs(final Matcher valueMatcher) { - Objects.requireNonNull(valueMatcher, "valueMatcher"); - return new OptionalValueIs<>(valueMatcher); - } - - public static Matcher> valueIs(final V value) { - Objects.requireNonNull(value, "value"); - return new OptionalValueIs<>(Matchers.equalTo(value)); - } - - private SpongeMatchers() { - } - -} diff --git a/src/test/java/org/spongepowered/api/matcher/package-info.java b/src/test/java/org/spongepowered/api/matcher/package-info.java deleted file mode 100644 index 58442b1256..0000000000 --- a/src/test/java/org/spongepowered/api/matcher/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -/** - * An API section where "blocks" are represented. A block is a tile in the 3D - * game universe. Each "block" has a - * {@link org.spongepowered.api.block.BlockState} that can be changed. - */ -@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class) -package org.spongepowered.api.matcher;