From c62d26e808f994c991a6759cbd4014706a1cc821 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 8 May 2017 21:52:08 +0200 Subject: Refac resources --- .../sevenwonders/game/resources/ResourcesTest.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'backend/src/test/java/org') diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java index cd352c8b..a2bad8b9 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java @@ -1,6 +1,10 @@ package org.luxons.sevenwonders.game.resources; +import java.util.NoSuchElementException; + +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -8,6 +12,9 @@ import static org.junit.Assert.assertTrue; public class ResourcesTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void init_shouldBeEmpty() { Resources resources = new Resources(); @@ -48,6 +55,31 @@ public class ResourcesTest { assertEquals(5, resources.getQuantity(ResourceType.GLASS)); } + @Test + public void remove_some() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 3); + resources.remove(ResourceType.WOOD, 2); + assertEquals(1, resources.getQuantity(ResourceType.WOOD)); + } + + @Test + public void remove_all() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 3); + resources.remove(ResourceType.WOOD, 3); + assertEquals(0, resources.getQuantity(ResourceType.WOOD)); + } + + @Test + public void remove_tooMany() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 2); + + thrown.expect(NoSuchElementException.class); + resources.remove(ResourceType.WOOD, 3); + } + @Test public void addAll_empty() { Resources resources = new Resources(); -- cgit