Skip to content

Commit

Permalink
Replace leftover hamcrest usage with junit and drop dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMorpheus committed Mar 31, 2024
1 parent f14291e commit 40b4111
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 317 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ dependencies {
testImplementation(libs.junit.params)
testRuntimeOnly(libs.junit.engine)
testRuntimeOnly(libs.junit.launcher)
testImplementation(libs.hamcrest)
testImplementation(libs.mockito)
}

Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
52 changes: 24 additions & 28 deletions src/test/java/org/spongepowered/api/data/DataQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -110,10 +106,10 @@ void testGetQueryParts() {
final DataQuery part3 = DataQuery.of("query");
final List<DataQuery> parts = full.queryParts();
final List<DataQuery> 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));
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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);
}

}
37 changes: 14 additions & 23 deletions src/test/java/org/spongepowered/api/event/CauseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -71,53 +62,53 @@ 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
void testListedArray() {
final List<String> 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<String> stringList = cause.allOf(String.class);
MatcherAssert.assertThat(stringList, is(not(empty())));
MatcherAssert.assertThat(stringList, is(fooList));
Assertions.assertFalse(stringList.isEmpty());
Assertions.assertEquals(stringList, fooList);
}

}
Loading

0 comments on commit 40b4111

Please sign in to comment.