tests: Move to JUnit 5 (#3357)

This commit is contained in:
Alex 2021-12-13 10:41:36 +01:00 committed by GitHub
parent f086826942
commit 858b6b5471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 51 deletions

View File

@ -30,14 +30,12 @@ import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.EnumSet; import java.util.EnumSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
class ClickStripTransformTest { class ClickStripTransformTest {
@ -53,7 +51,7 @@ class ClickStripTransformTest {
) )
); );
var transformedComponent = transform.transform(component); var transformedComponent = transform.transform(component);
assertNull(transformedComponent.clickEvent()); Assertions.assertNull(transformedComponent.clickEvent());
} }
@Test @Test
@ -68,7 +66,7 @@ class ClickStripTransformTest {
var component = Component.text("Hello") var component = Component.text("Hello")
.clickEvent(originalClickEvent); .clickEvent(originalClickEvent);
var transformedComponent = transform.transform(component); var transformedComponent = transform.transform(component);
assertEquals(originalClickEvent, transformedComponent.clickEvent()); Assertions.assertEquals(originalClickEvent, transformedComponent.clickEvent());
} }
@Test @Test
@ -88,9 +86,9 @@ class ClickStripTransformTest {
inner.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://example.org")) inner.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://example.org"))
); );
var transformedComponent = transform.transform(component); var transformedComponent = transform.transform(component);
assertFalse(transformedComponent.children().isEmpty()); // child still exists Assertions.assertFalse(transformedComponent.children().isEmpty()); // child still exists
assertEquals(inner, transformedComponent.children().get(0)); // only the click event has changed Assertions.assertEquals(inner, transformedComponent.children().get(0)); // only the click event has changed
assertNull(transformedComponent.children().get(0).clickEvent()); Assertions.assertNull(transformedComponent.children().get(0).clickEvent());
} }
} }

View File

@ -32,10 +32,9 @@ import com.plotsquared.core.plot.flag.implementations.UseFlag;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.junit.Before; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
public class FlagTest { public class FlagTest {
@ -43,7 +42,7 @@ public class FlagTest {
private ItemType testBlock; private ItemType testBlock;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
//EventUtil.manager = new EventUtilTest(); //EventUtil.manager = new EventUtilTest();
DBFunc.dbManager = new AbstractDBTest(); DBFunc.dbManager = new AbstractDBTest();
@ -72,7 +71,7 @@ public class FlagTest {
@Test @Test
public void testFlagName() { public void testFlagName() {
String flagName = PlotFlag.getFlagName(UseFlag.class); String flagName = PlotFlag.getFlagName(UseFlag.class);
assertEquals("use", flagName); Assertions.assertEquals("use", flagName);
} }
} }

View File

@ -25,19 +25,13 @@
*/ */
package com.plotsquared.core.plot; package com.plotsquared.core.plot;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class PlotRangeIteratorTest { public class PlotRangeIteratorTest {
@Test @Test
@ -45,10 +39,10 @@ public class PlotRangeIteratorTest {
// an iterator that should only contain the given plot // an iterator that should only contain the given plot
PlotId id = PlotId.of(3, 7); PlotId id = PlotId.of(3, 7);
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id, id); PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id, id);
assertTrue(range.hasNext()); Assertions.assertTrue(range.hasNext());
assertEquals(id, range.next()); Assertions.assertEquals(id, range.next());
assertFalse(range.hasNext()); Assertions.assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next); Assertions.assertThrows(NoSuchElementException.class, range::next);
} }
// the tests below assume a specific order (first increasing y, then increasing x) // the tests below assume a specific order (first increasing y, then increasing x)
@ -63,11 +57,11 @@ public class PlotRangeIteratorTest {
List<PlotId> all = Arrays.asList(id00, id01, id10, id11); List<PlotId> all = Arrays.asList(id00, id01, id10, id11);
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id11); PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id11);
for (PlotId id : all) { for (PlotId id : all) {
assertTrue(range.hasNext()); Assertions.assertTrue(range.hasNext());
assertEquals(id, range.next()); Assertions.assertEquals(id, range.next());
} }
assertFalse(range.hasNext()); Assertions.assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next); Assertions.assertThrows(NoSuchElementException.class, range::next);
} }
@Test @Test
@ -82,11 +76,11 @@ public class PlotRangeIteratorTest {
List<PlotId> all = Arrays.asList(id00, id01, id02, id10, id11, id12); List<PlotId> all = Arrays.asList(id00, id01, id02, id10, id11, id12);
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id12); PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id12);
for (PlotId id : all) { for (PlotId id : all) {
assertTrue(range.hasNext()); Assertions.assertTrue(range.hasNext());
assertEquals(id, range.next()); Assertions.assertEquals(id, range.next());
} }
assertFalse(range.hasNext()); Assertions.assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next); Assertions.assertThrows(NoSuchElementException.class, range::next);
} }
@Test @Test
@ -101,11 +95,11 @@ public class PlotRangeIteratorTest {
List<PlotId> all = Arrays.asList(id00, id01, id10, id11, id20, id21); List<PlotId> all = Arrays.asList(id00, id01, id10, id11, id20, id21);
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id21); PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id21);
for (PlotId id : all) { for (PlotId id : all) {
assertTrue(range.hasNext()); Assertions.assertTrue(range.hasNext());
assertEquals(id, range.next()); Assertions.assertEquals(id, range.next());
} }
assertFalse(range.hasNext()); Assertions.assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next); Assertions.assertThrows(NoSuchElementException.class, range::next);
} }
@Test @Test
@ -115,9 +109,9 @@ public class PlotRangeIteratorTest {
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id01); PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id01);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
assertNotEquals(0, range.next().getY()); Assertions.assertNotEquals(0, range.next().getY());
} }
assertFalse(range.hasNext()); Assertions.assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next); Assertions.assertThrows(NoSuchElementException.class, range::next);
} }
} }

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.plot;
import com.plotsquared.core.PlotVersion; import com.plotsquared.core.PlotVersion;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class PlotVersionTest { public class PlotVersionTest {

View File

@ -25,6 +25,7 @@
*/ */
package com.plotsquared.core.synchronization; package com.plotsquared.core.synchronization;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -32,9 +33,6 @@ import org.junit.jupiter.api.Test;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
class LockRepositoryTest { class LockRepositoryTest {
private LockKey key; private LockKey key;
@ -55,11 +53,9 @@ class LockRepositoryTest {
throw new IllegalStateException("Expected a ReentrantLock"); throw new IllegalStateException("Expected a ReentrantLock");
} }
assertThrows(IllegalStateException.class, () -> { Assertions.assertThrows(IllegalStateException.class, () -> this.lockRepository.useLock(this.key, () -> {
this.lockRepository.useLock(this.key, () -> {
throw new IllegalStateException(); throw new IllegalStateException();
}); }));
}); Assertions.assertFalse(lock.isLocked());
assertFalse(lock.isLocked());
} }
} }

View File

@ -67,7 +67,6 @@ val javadocDir = rootDir.resolve("docs").resolve("javadoc").resolve(project.name
allprojects { allprojects {
dependencies { dependencies {
// Tests // Tests
testImplementation("junit:junit:4.13.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2") testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
} }