summaryrefslogtreecommitdiff
path: root/game-engine/src/test/kotlin/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-02-21 01:26:36 +0100
committerjbion <joffrey.bion@amadeus.com>2019-02-21 01:26:36 +0100
commit6d83b6fada8942650566e6ed46ead95eb05954b9 (patch)
tree0219c5817f68c4ed1b0dcadb96e4092fc4d7e96d /game-engine/src/test/kotlin/org
parentRemove non idiomatic usages of lists (diff)
downloadseven-wonders-6d83b6fada8942650566e6ed46ead95eb05954b9.tar.gz
seven-wonders-6d83b6fada8942650566e6ed46ead95eb05954b9.tar.bz2
seven-wonders-6d83b6fada8942650566e6ed46ead95eb05954b9.zip
Replace expected exceptions with assertFailsWith
Diffstat (limited to 'game-engine/src/test/kotlin/org')
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt19
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt12
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt42
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt6
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt52
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt12
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt34
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt13
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt53
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt10
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt14
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt12
12 files changed, 168 insertions, 111 deletions
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
index d8a10777..d1b7c239 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
@@ -2,13 +2,11 @@ package org.luxons.sevenwonders.game.boards
import junit.framework.TestCase.assertEquals
import org.junit.Assume.assumeTrue
-import org.junit.Rule
import org.junit.Test
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.FromDataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
-import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.boards.Board.InsufficientFundsException
import org.luxons.sevenwonders.game.cards.Color
@@ -26,6 +24,7 @@ import org.luxons.sevenwonders.game.test.testBoard
import org.luxons.sevenwonders.game.test.testCard
import org.luxons.sevenwonders.game.test.testSettings
import org.luxons.sevenwonders.game.test.testWonder
+import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertSame
import kotlin.test.assertTrue
@@ -33,10 +32,6 @@ import kotlin.test.assertTrue
@RunWith(Theories::class)
class BoardTest {
- @JvmField
- @Rule
- var thrown: ExpectedException = ExpectedException.none()
-
@Theory
fun initialGold_respectsSettings(@FromDataPoints("gold") goldAmountInSettings: Int) {
val settings = testSettings(initialGold = goldAmountInSettings)
@@ -72,10 +67,11 @@ class BoardTest {
) {
assumeTrue(goldRemoved >= 0)
assumeTrue(initialGold < goldRemoved)
- thrown.expect(InsufficientFundsException::class.java)
- val board = Board(testWonder(), 0, testSettings(initialGold = initialGold))
- board.removeGold(goldRemoved)
+ assertFailsWith<InsufficientFundsException> {
+ val board = Board(testWonder(), 0, testSettings(initialGold = initialGold))
+ board.removeGold(goldRemoved)
+ }
}
@Theory
@@ -121,8 +117,9 @@ class BoardTest {
val board = testBoard()
val card = testCard(color = color)
- thrown.expect(IllegalArgumentException::class.java)
- board.copiedGuild = card
+ assertFailsWith<IllegalArgumentException> {
+ board.copiedGuild = card
+ }
}
@Theory
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt
index dd2696f4..248d43dd 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt
@@ -1,22 +1,17 @@
package org.luxons.sevenwonders.game.boards
-import org.junit.Rule
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.FromDataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
-import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.boards.Military.UnknownAgeException
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
@RunWith(Theories::class)
class MilitaryTest {
- @JvmField
- @Rule
- var thrown = ExpectedException.none()
-
@Theory
fun victory_addsCorrectPoints(
@FromDataPoints("ages") age: Int,
@@ -32,8 +27,9 @@ class MilitaryTest {
@Theory
fun victory_failsIfUnknownAge(@FromDataPoints("points") nbPointsPerVictory: Int) {
val military = createMilitary(0, nbPointsPerVictory, 0)
- thrown.expect(UnknownAgeException::class.java)
- military.victory(1)
+ assertFailsWith<UnknownAgeException> {
+ military.victory(1)
+ }
}
@Theory
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt
index d42fca63..f6c45720 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt
@@ -1,42 +1,43 @@
package org.luxons.sevenwonders.game.cards
import org.junit.Assume.assumeTrue
-import org.junit.Rule
import org.junit.Test
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
-import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.cards.Decks.CardNotFoundException
import org.luxons.sevenwonders.game.test.sampleCards
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@RunWith(Theories::class)
class DecksTest {
- @JvmField
- @Rule
- val thrown: ExpectedException = ExpectedException.none()
-
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun getCard_failsOnEmptyNameWhenDeckIsEmpty() {
val decks = createDecks(0, 0)
- decks.getCard(0, "")
+ assertFailsWith<IllegalArgumentException> {
+ decks.getCard(0, "")
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun getCard_failsWhenDeckIsEmpty() {
val decks = createDecks(0, 0)
- decks.getCard(0, "Any name")
+ assertFailsWith<IllegalArgumentException> {
+ decks.getCard(0, "Any name")
+ }
}
- @Test(expected = CardNotFoundException::class)
+ @Test
fun getCard_failsWhenCardIsNotFound() {
val decks = createDecks(3, 20)
- decks.getCard(1, "Unknown name")
+ assertFailsWith<CardNotFoundException> {
+ decks.getCard(1, "Unknown name")
+ }
}
@Test
@@ -46,24 +47,29 @@ class DecksTest {
assertEquals("Test Card 3", name)
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deal_failsOnZeroPlayers() {
val decks = createDecks(3, 20)
- decks.deal(1, 0)
+ assertFailsWith<IllegalArgumentException> {
+ decks.deal(1, 0)
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deal_failsOnMissingAge() {
val decks = createDecks(2, 0)
- decks.deal(4, 10)
+ assertFailsWith<IllegalArgumentException> {
+ decks.deal(4, 10)
+ }
}
@Theory
fun deal_failsWhenTooFewPlayers(nbPlayers: Int, nbCards: Int) {
assumeTrue(nbCards % nbPlayers != 0)
- thrown.expect(IllegalArgumentException::class.java)
val decks = createDecks(1, nbCards)
- decks.deal(1, nbPlayers)
+ assertFailsWith<IllegalArgumentException> {
+ decks.deal(1, nbPlayers)
+ }
}
@Theory
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
index 5a71aeda..c7ff9106 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
@@ -11,16 +11,18 @@ import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.test.sampleCards
import org.luxons.sevenwonders.game.test.testTable
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@RunWith(Theories::class)
class HandsTest {
- @Test(expected = IndexOutOfBoundsException::class)
+ @Test
fun get_failsOnMissingPlayer() {
val hands = createHands(4, 7)
- hands[5]
+
+ assertFailsWith<IndexOutOfBoundsException> { hands[5] }
}
@Test
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt
index dbd5a9a2..9b44fad2 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt
@@ -15,6 +15,7 @@ import org.luxons.sevenwonders.game.effects.ProductionIncrease
import org.luxons.sevenwonders.game.effects.RawPointsIncrease
import org.luxons.sevenwonders.game.resources.Production
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
@RunWith(Theories::class)
class NumericEffectSerializerTest {
@@ -27,8 +28,7 @@ class NumericEffectSerializerTest {
.registerTypeAdapter(RawPointsIncrease::class.java, NumericEffectSerializer())
.registerTypeAdapter(GoldIncrease::class.java, NumericEffectSerializer())
// ProductionIncrease is not a numeric effect, it is here for negative testing purpose
- .registerTypeAdapter(ProductionIncrease::class.java, NumericEffectSerializer())
- .create()
+ .registerTypeAdapter(ProductionIncrease::class.java, NumericEffectSerializer()).create()
}
@Test
@@ -46,9 +46,11 @@ class NumericEffectSerializerTest {
assertEquals("null", gson.toJson(null, GoldIncrease::class.java))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun serialize_failOnUnknownType() {
- gson.toJson(ProductionIncrease(Production(), false))
+ assertFailsWith<IllegalArgumentException> {
+ gson.toJson(ProductionIncrease(Production(), false))
+ }
}
@Theory
@@ -87,39 +89,53 @@ class NumericEffectSerializerTest {
assertEquals(goldIncrease, gson.fromJson<GoldIncrease>(count.toString()))
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_militaryReinforcements_failOnEmptyString() {
- gson.fromJson<MilitaryReinforcements>("\"\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<MilitaryReinforcements>("\"\"")
+ }
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_rawPointsIncrease_failOnEmptyString() {
- gson.fromJson<RawPointsIncrease>("\"\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<RawPointsIncrease>("\"\"")
+ }
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_goldIncrease_failOnEmptyString() {
- gson.fromJson<GoldIncrease>("\"\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<GoldIncrease>("\"\"")
+ }
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_militaryReinforcements_failOnNonNumericString() {
- gson.fromJson<MilitaryReinforcements>("\"abc\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<MilitaryReinforcements>("\"abc\"")
+ }
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_rawPointsIncrease_failOnNonNumericString() {
- gson.fromJson<RawPointsIncrease>("\"abc\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<RawPointsIncrease>("\"abc\"")
+ }
}
- @Test(expected = NumberFormatException::class)
+ @Test
fun deserialize_goldIncrease_failOnNonNumericString() {
- gson.fromJson<GoldIncrease>("\"abc\"")
+ assertFailsWith<NumberFormatException> {
+ gson.fromJson<GoldIncrease>("\"abc\"")
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnUnknownType() {
- gson.fromJson<ProductionIncrease>("\"2\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<ProductionIncrease>("\"2\"")
+ }
}
companion object {
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt
index 8354ab21..31d695e8 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt
@@ -110,18 +110,22 @@ class ProductionIncreaseSerializerTest {
assertEquals("\"W/O/C\"", gson.toJson(prodIncrease))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun serialize_failIfMultipleChoices() {
val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.CLAY)
prodIncrease.production.addChoice(ResourceType.ORE, ResourceType.GLASS)
- gson.toJson(prodIncrease)
+ assertFailsWith<IllegalArgumentException> {
+ gson.toJson(prodIncrease)
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun serialize_failIfMixedFixedAndChoices() {
val prodIncrease = create(true, 1, 0, 0)
prodIncrease.production.addChoice(ResourceType.WOOD, ResourceType.CLAY)
- gson.toJson(prodIncrease)
+ assertFailsWith<IllegalArgumentException> {
+ gson.toJson(prodIncrease)
+ }
}
@Test
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt
index 82d99fb8..265087ba 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt
@@ -11,6 +11,7 @@ import org.luxons.sevenwonders.game.resources.Production
import org.luxons.sevenwonders.game.resources.ResourceType
import org.luxons.sevenwonders.game.resources.Resources
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertNull
class ProductionSerializerTest {
@@ -24,8 +25,7 @@ class ProductionSerializerTest {
.registerTypeAdapter(MutableResources::class.java, ResourcesSerializer())
.registerTypeAdapter(ResourceType::class.java, ResourceTypeSerializer())
.registerTypeAdapter(resourceTypeList, ResourceTypesSerializer())
- .registerTypeAdapter(Production::class.java, ProductionSerializer())
- .create()
+ .registerTypeAdapter(Production::class.java, ProductionSerializer()).create()
}
private fun create(wood: Int, stone: Int, clay: Int): Production {
@@ -107,18 +107,22 @@ class ProductionSerializerTest {
assertEquals("\"W/O/C\"", gson.toJson(prodIncrease))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun serialize_failIfMultipleChoices() {
val production = createChoice(ResourceType.WOOD, ResourceType.CLAY)
production.addChoice(ResourceType.ORE, ResourceType.GLASS)
- gson.toJson(production)
+ assertFailsWith<IllegalArgumentException> {
+ gson.toJson(production)
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun serialize_failIfMixedFixedAndChoices() {
val production = create(1, 0, 0)
production.addChoice(ResourceType.WOOD, ResourceType.CLAY)
- gson.toJson(production)
+ assertFailsWith<IllegalArgumentException> {
+ gson.toJson(production)
+ }
}
@Test
@@ -132,14 +136,18 @@ class ProductionSerializerTest {
assertEquals(prodIncrease, gson.fromJson("\"\""))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnGarbageString() {
- gson.fromJson<Production>("\"this is garbage\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<Production>("\"this is garbage\"")
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnGarbageStringWithSlashes() {
- gson.fromJson<Production>("\"this/is/garbage\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<Production>("\"this/is/garbage\"")
+ }
}
@Test
@@ -190,8 +198,10 @@ class ProductionSerializerTest {
assertEquals(prodIncrease, gson.fromJson("\"W/O/C\""))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnMultipleResourcesInChoice() {
- gson.fromJson<Production>("\"W/SS/C\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<Production>("\"W/SS/C\"")
+ }
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt
index eee04047..f2b07e84 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt
@@ -7,6 +7,7 @@ import org.junit.Before
import org.junit.Test
import org.luxons.sevenwonders.game.resources.ResourceType
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertNull
class ResourceTypeSerializerTest {
@@ -39,13 +40,17 @@ class ResourceTypeSerializerTest {
assertNull(gson.fromJson("null", ResourceType::class.java))
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failsOnEmptyString() {
- gson.fromJson<ResourceType>("\"\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<ResourceType>("\"\"")
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failsOnGarbageString() {
- gson.fromJson<ResourceType>("\"thisisgarbage\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<ResourceType>("\"thisisgarbage\"")
+ }
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt
index 1c95bb36..95d72517 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt
@@ -9,6 +9,7 @@ import org.luxons.sevenwonders.game.boards.ScienceType
import org.luxons.sevenwonders.game.effects.ScienceProgress
import org.luxons.sevenwonders.game.test.createScienceProgress
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
private const val TABLET_STR = "\"TABLET\""
@@ -60,44 +61,58 @@ class ScienceProgressSerializerTest {
assertEquals(JOKER_STR, json)
}
- @Test(expected = UnsupportedOperationException::class)
+ @Test
fun serialize_failOnMultipleCompasses() {
- val progress = createScienceProgress(2, 0, 0, 0)
- gson.toJson(progress)
+ assertFailsWith<UnsupportedOperationException> {
+ val progress = createScienceProgress(2, 0, 0, 0)
+ gson.toJson(progress)
+ }
}
- @Test(expected = UnsupportedOperationException::class)
+ @Test
fun serialize_failOnMultipleWheels() {
- val progress = createScienceProgress(0, 2, 0, 0)
- gson.toJson(progress)
+ assertFailsWith<UnsupportedOperationException> {
+ val progress = createScienceProgress(0, 2, 0, 0)
+ gson.toJson(progress)
+ }
}
- @Test(expected = UnsupportedOperationException::class)
+ @Test
fun serialize_failOnMultipleTablets() {
- val progress = createScienceProgress(0, 0, 2, 0)
- gson.toJson(progress)
+ assertFailsWith<UnsupportedOperationException> {
+ val progress = createScienceProgress(0, 0, 2, 0)
+ gson.toJson(progress)
+ }
}
- @Test(expected = UnsupportedOperationException::class)
+ @Test
fun serialize_failOnMultipleJokers() {
- val progress = createScienceProgress(0, 0, 0, 2)
- gson.toJson(progress)
+ assertFailsWith<UnsupportedOperationException> {
+ val progress = createScienceProgress(0, 0, 0, 2)
+ gson.toJson(progress)
+ }
}
- @Test(expected = UnsupportedOperationException::class)
+ @Test
fun serialize_failOnMixedElements() {
- val progress = createScienceProgress(1, 1, 0, 0)
- gson.toJson(progress)
+ assertFailsWith<UnsupportedOperationException> {
+ val progress = createScienceProgress(1, 1, 0, 0)
+ gson.toJson(progress)
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnEmptyString() {
- gson.fromJson<ScienceProgress>("\"\"")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<ScienceProgress>("\"\"")
+ }
}
- @Test(expected = IllegalArgumentException::class)
+ @Test
fun deserialize_failOnGarbageString() {
- gson.fromJson<ScienceProgress>("thisisgarbage")
+ assertFailsWith<IllegalArgumentException> {
+ gson.fromJson<ScienceProgress>("thisisgarbage")
+ }
}
@Test
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
index 524124b4..aae3be8e 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
@@ -13,6 +13,7 @@ import org.luxons.sevenwonders.game.cards.Color
import org.luxons.sevenwonders.game.test.createGuildCard
import org.luxons.sevenwonders.game.test.testTable
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@RunWith(Theories::class)
@@ -52,11 +53,13 @@ class SpecialAbilityActivationTest {
assertEquals(directPointsFromGuildCard, effect.computePoints(player))
}
- @Test(expected = IllegalStateException::class)
+ @Test
fun computePoints_copyGuild_failWhenNoChosenGuild() {
val effect = SpecialAbilityActivation(SpecialAbility.COPY_GUILD)
val player = SimplePlayer(0, testTable(5))
- effect.computePoints(player)
+ assertFailsWith<IllegalStateException> {
+ effect.computePoints(player)
+ }
}
companion object {
@@ -67,7 +70,8 @@ class SpecialAbilityActivationTest {
@JvmStatic
@DataPoints
- fun neighbours(): Array<RelativeBoardPosition> = arrayOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)
+ fun neighbours(): Array<RelativeBoardPosition> =
+ arrayOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)
@JvmStatic
@DataPoints
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
index b0667d67..21b92872 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
@@ -11,20 +11,24 @@ import org.luxons.sevenwonders.game.test.testCard
import org.luxons.sevenwonders.game.test.testSettings
import org.luxons.sevenwonders.game.test.testTable
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.fail
class BuildWonderMoveTest {
- @Test(expected = InvalidMoveException::class)
+ @Test
fun init_failsWhenCardNotInHand() {
val table = testTable(3)
val hand = sampleCards(7)
val playerContext = PlayerContext(0, table, hand)
val anotherCard = testCard("Card that is not in the hand")
- createMove(playerContext, anotherCard, MoveType.UPGRADE_WONDER)
+
+ assertFailsWith<InvalidMoveException> {
+ createMove(playerContext, anotherCard, MoveType.UPGRADE_WONDER)
+ }
}
- @Test(expected = InvalidMoveException::class)
+ @Test
fun init_failsWhenWonderIsCompletelyBuilt() {
val settings = testSettings(3)
val table = testTable(settings)
@@ -33,7 +37,9 @@ class BuildWonderMoveTest {
fillPlayerWonderLevels(settings, table, hand)
// should fail because the wonder is already full
- buildOneWonderLevel(settings, table, hand, 4)
+ assertFailsWith<InvalidMoveException> {
+ buildOneWonderLevel(settings, table, hand, 4)
+ }
}
private fun fillPlayerWonderLevels(settings: Settings, table: Table, hand: List<Card>) {
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt
index ba20bc62..634a25c7 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt
@@ -1,8 +1,6 @@
package org.luxons.sevenwonders.game.resources
-import org.junit.Rule
import org.junit.Test
-import org.junit.rules.ExpectedException
import org.luxons.sevenwonders.game.resources.ResourceType.CLAY
import org.luxons.sevenwonders.game.resources.ResourceType.GLASS
import org.luxons.sevenwonders.game.resources.ResourceType.LOOM
@@ -12,15 +10,12 @@ import org.luxons.sevenwonders.game.resources.ResourceType.STONE
import org.luxons.sevenwonders.game.resources.ResourceType.WOOD
import java.util.NoSuchElementException
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class ResourcesTest {
- @JvmField
- @Rule
- var thrown = ExpectedException.none()
-
@Test
fun init_shouldBeEmpty() {
val resources = emptyResources()
@@ -143,8 +138,9 @@ class ResourcesTest {
fun remove_tooMany() {
val resources = mutableResourcesOf(WOOD to 2)
- thrown.expect(NoSuchElementException::class.java)
- resources.remove(WOOD, 3)
+ assertFailsWith<NoSuchElementException> {
+ resources.remove(WOOD, 3)
+ }
}
@Test
bgstack15