From 6984d035794c6276034b3b006fe911d97fe0025e Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sun, 4 Feb 2024 00:00:08 +0100 Subject: [PATCH 1/5] tests: migrate from TestNG to JUnit 3 (forge-game) Since our final objective is to migrate to JUnit 5, the JAR is JUnit4 (wich is compatible with JUnit 3). --- forge-game/pom.xml | 6 ++-- .../forge/game/ability/AbilityKeyTest.java | 12 +++---- .../game/mana/ManaCostBeingPaidTest.java | 33 ++++++++----------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/forge-game/pom.xml b/forge-game/pom.xml index 400013a0682..0a11e1213c8 100644 --- a/forge-game/pom.xml +++ b/forge-game/pom.xml @@ -24,9 +24,9 @@ 1.2 - org.testng - testng - 7.4.0 + junit + junit + 4.13.2 test diff --git a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java index 17153e069cc..26a4490efb7 100644 --- a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java +++ b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java @@ -1,26 +1,24 @@ package forge.game.ability; -import org.testng.annotations.Test; -import org.testng.AssertJUnit; import java.util.Map; import com.google.common.collect.Maps; -public class AbilityKeyTest { +import junit.framework.TestCase; - @Test +public class AbilityKeyTest extends TestCase { public void testFromStringWorksForAllKeys() { for (AbilityKey key : AbilityKey.values()) { - AssertJUnit.assertEquals(key, AbilityKey.fromString(key.toString())); + assertEquals(key, AbilityKey.fromString(key.toString())); } } - @Test public void testCopyingEmptyMapWorks() { Map map = Maps.newHashMap(); + Map newMap = AbilityKey.newMap(map); // An actual copy should be made. - AssertJUnit.assertNotSame(map, newMap); + assertNotSame(map, newMap); } } diff --git a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java index 1faae85f1c7..8941f1faa5b 100644 --- a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java +++ b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java @@ -1,7 +1,5 @@ package forge.game.mana; -import org.testng.annotations.Test; -import org.testng.AssertJUnit; import static forge.card.MagicColor.COLORLESS; import static forge.card.MagicColor.GREEN; import static forge.card.MagicColor.RED; @@ -9,32 +7,27 @@ import forge.card.mana.ManaCost; import forge.card.mana.ManaCostParser; +import junit.framework.TestCase; -public class ManaCostBeingPaidTest { - - @Test +public class ManaCostBeingPaidTest extends TestCase { public void testPayManaViaConvoke() { - runConvokeTest("1 W W", new byte[] { WHITE, COLORLESS, WHITE }, new String[] { "{1}{W}{W}", "{1}{W}", "{W}" }); - runConvokeTest("1 W W", new byte[] { COLORLESS, WHITE, WHITE }, new String[] { "{1}{W}{W}", "{W}{W}", "{W}" }); - runConvokeTest("1 W W", new byte[] { GREEN, WHITE, WHITE }, new String[] { "{1}{W}{W}", "{W}{W}", "{W}" }); - runConvokeTest("1 W G", new byte[] { GREEN, RED, WHITE }, new String[] { "{1}{W}{G}", "{1}{W}", "{W}" }); + runConvokeTest("1 W W", new byte[]{WHITE, COLORLESS, WHITE}, new String[]{"{1}{W}{W}", "{1}{W}", "{W}"}); + runConvokeTest("1 W W", new byte[]{COLORLESS, WHITE, WHITE}, new String[]{"{1}{W}{W}", "{W}{W}", "{W}"}); + runConvokeTest("1 W W", new byte[]{GREEN, WHITE, WHITE}, new String[]{"{1}{W}{W}", "{W}{W}", "{W}"}); + runConvokeTest("1 W G", new byte[]{GREEN, RED, WHITE}, new String[]{"{1}{W}{G}", "{1}{W}", "{W}"}); } private void runConvokeTest(String initialCost, byte[] colorsToPay, String[] expectedRemainder) { - ManaCostBeingPaid costBeingPaid = createManaCostBeingPaid(initialCost); - + ManaCostBeingPaid cost = createManaCostBeingPaid(initialCost); for (int i = 0; i < colorsToPay.length; i++) { - AssertJUnit.assertEquals(expectedRemainder[i], costBeingPaid.toString()); - costBeingPaid.payManaViaConvoke(colorsToPay[i]); + assertEquals(expectedRemainder[i], cost.toString()); + cost.payManaViaConvoke(colorsToPay[i]); } - - AssertJUnit.assertEquals("0", costBeingPaid.toString()); + assertEquals("0", cost.toString()); } - private ManaCostBeingPaid createManaCostBeingPaid(String costString) { - ManaCostParser parsedCostString = new ManaCostParser(costString); - ManaCost manaCost = new ManaCost(parsedCostString); - - return new ManaCostBeingPaid(manaCost); + private ManaCostBeingPaid createManaCostBeingPaid(String cost) { + ManaCostParser parser = new ManaCostParser(cost); + return new ManaCostBeingPaid(new ManaCost(parser)); } } From 0f336dd2915fc375b6ea272a5dcba05dd1db6dbd Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sun, 4 Feb 2024 00:11:12 +0100 Subject: [PATCH 2/5] tests: migrate from JUnit 3 to JUnit 4 (forge-game) We are now ready to migrate to JUnit 5. --- .../java/forge/game/ability/AbilityKeyTest.java | 14 +++++++++----- .../forge/game/mana/ManaCostBeingPaidTest.java | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java index 26a4490efb7..9f4eccd0108 100644 --- a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java +++ b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java @@ -2,23 +2,27 @@ import java.util.Map; +import org.junit.Assert; +import org.junit.Test; + import com.google.common.collect.Maps; -import junit.framework.TestCase; -public class AbilityKeyTest extends TestCase { +public class AbilityKeyTest { + + @Test public void testFromStringWorksForAllKeys() { for (AbilityKey key : AbilityKey.values()) { - assertEquals(key, AbilityKey.fromString(key.toString())); + Assert.assertEquals(key, AbilityKey.fromString(key.toString())); } } + @Test public void testCopyingEmptyMapWorks() { Map map = Maps.newHashMap(); - Map newMap = AbilityKey.newMap(map); // An actual copy should be made. - assertNotSame(map, newMap); + Assert.assertNotSame(map, newMap); } } diff --git a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java index 8941f1faa5b..04463a10392 100644 --- a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java +++ b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java @@ -5,11 +5,15 @@ import static forge.card.MagicColor.RED; import static forge.card.MagicColor.WHITE; +import org.junit.Assert; +import org.junit.Test; + import forge.card.mana.ManaCost; import forge.card.mana.ManaCostParser; -import junit.framework.TestCase; -public class ManaCostBeingPaidTest extends TestCase { +public class ManaCostBeingPaidTest { + + @Test public void testPayManaViaConvoke() { runConvokeTest("1 W W", new byte[]{WHITE, COLORLESS, WHITE}, new String[]{"{1}{W}{W}", "{1}{W}", "{W}"}); runConvokeTest("1 W W", new byte[]{COLORLESS, WHITE, WHITE}, new String[]{"{1}{W}{W}", "{W}{W}", "{W}"}); @@ -20,10 +24,10 @@ public void testPayManaViaConvoke() { private void runConvokeTest(String initialCost, byte[] colorsToPay, String[] expectedRemainder) { ManaCostBeingPaid cost = createManaCostBeingPaid(initialCost); for (int i = 0; i < colorsToPay.length; i++) { - assertEquals(expectedRemainder[i], cost.toString()); + Assert.assertEquals(expectedRemainder[i], cost.toString()); cost.payManaViaConvoke(colorsToPay[i]); } - assertEquals("0", cost.toString()); + Assert.assertEquals("0", cost.toString()); } private ManaCostBeingPaid createManaCostBeingPaid(String cost) { From c5e1beaf94eb400f7840b47c1696fc768f59ce99 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sun, 4 Feb 2024 00:57:03 +0100 Subject: [PATCH 3/5] tests: run JUnit 4 tests on JUnit 5 (forge-game) --- forge-game/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forge-game/pom.xml b/forge-game/pom.xml index 0a11e1213c8..ce4bbf9c7d0 100644 --- a/forge-game/pom.xml +++ b/forge-game/pom.xml @@ -24,9 +24,9 @@ 1.2 - junit - junit - 4.13.2 + org.junit.vintage + junit-vintage-engine + 5.10.1 test From 18dc3a86fd6ef03ba40191e44144470c0ecd1610 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sun, 4 Feb 2024 01:16:09 +0100 Subject: [PATCH 4/5] tests: migrate from JUnit 4 to JUnit 5 (forge-game) --- forge-game/pom.xml | 10 +++++++--- .../test/java/forge/game/ability/AbilityKeyTest.java | 10 ++++++---- .../java/forge/game/mana/ManaCostBeingPaidTest.java | 9 +++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/forge-game/pom.xml b/forge-game/pom.xml index ce4bbf9c7d0..6d0bd7079fd 100644 --- a/forge-game/pom.xml +++ b/forge-game/pom.xml @@ -12,6 +12,10 @@ forge-game Forge Game + + 5.10.1 + + forge @@ -24,9 +28,9 @@ 1.2 - org.junit.vintage - junit-vintage-engine - 5.10.1 + org.junit.jupiter + junit-jupiter + ${junit.version} test diff --git a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java index 9f4eccd0108..1ae7711c832 100644 --- a/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java +++ b/forge-game/src/test/java/forge/game/ability/AbilityKeyTest.java @@ -2,8 +2,10 @@ import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import org.junit.jupiter.api.Test; import com.google.common.collect.Maps; @@ -13,7 +15,7 @@ public class AbilityKeyTest { @Test public void testFromStringWorksForAllKeys() { for (AbilityKey key : AbilityKey.values()) { - Assert.assertEquals(key, AbilityKey.fromString(key.toString())); + assertEquals(key, AbilityKey.fromString(key.toString())); } } @@ -23,6 +25,6 @@ public void testCopyingEmptyMapWorks() { Map newMap = AbilityKey.newMap(map); // An actual copy should be made. - Assert.assertNotSame(map, newMap); + assertNotSame(map, newMap); } } diff --git a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java index 04463a10392..92573072c7e 100644 --- a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java +++ b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java @@ -5,8 +5,9 @@ import static forge.card.MagicColor.RED; import static forge.card.MagicColor.WHITE; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; import forge.card.mana.ManaCost; import forge.card.mana.ManaCostParser; @@ -24,10 +25,10 @@ public void testPayManaViaConvoke() { private void runConvokeTest(String initialCost, byte[] colorsToPay, String[] expectedRemainder) { ManaCostBeingPaid cost = createManaCostBeingPaid(initialCost); for (int i = 0; i < colorsToPay.length; i++) { - Assert.assertEquals(expectedRemainder[i], cost.toString()); + assertEquals(expectedRemainder[i], cost.toString()); cost.payManaViaConvoke(colorsToPay[i]); } - Assert.assertEquals("0", cost.toString()); + assertEquals("0", cost.toString()); } private ManaCostBeingPaid createManaCostBeingPaid(String cost) { From ed30ba99937b9fa16756e9ce7b04b95c3d357ec5 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Sun, 4 Feb 2024 01:22:26 +0100 Subject: [PATCH 5/5] tests: rename (forge-game) --- .../test/java/forge/game/mana/ManaCostBeingPaidTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java index 92573072c7e..9418e71d9eb 100644 --- a/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java +++ b/forge-game/src/test/java/forge/game/mana/ManaCostBeingPaidTest.java @@ -23,12 +23,12 @@ public void testPayManaViaConvoke() { } private void runConvokeTest(String initialCost, byte[] colorsToPay, String[] expectedRemainder) { - ManaCostBeingPaid cost = createManaCostBeingPaid(initialCost); + ManaCostBeingPaid costBeingPaid = createManaCostBeingPaid(initialCost); for (int i = 0; i < colorsToPay.length; i++) { - assertEquals(expectedRemainder[i], cost.toString()); - cost.payManaViaConvoke(colorsToPay[i]); + assertEquals(expectedRemainder[i], costBeingPaid.toString()); + costBeingPaid.payManaViaConvoke(colorsToPay[i]); } - assertEquals("0", cost.toString()); + assertEquals("0", costBeingPaid.toString()); } private ManaCostBeingPaid createManaCostBeingPaid(String cost) {