From 3a25d47f187fe7499d2d481d9a0a3411a92bfa11 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 21 Aug 2016 01:14:38 +0200 Subject: Switched from ant to gradle, had to refactor some of the tests because of the new build structure, a bit ugly but should pass --- .../equalparts/cardbase/cli/CardbaseCLITest.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test/eu/equalparts/cardbase/cli/CardbaseCLITest.java') diff --git a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java index 87755db..64a1030 100644 --- a/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java +++ b/test/eu/equalparts/cardbase/cli/CardbaseCLITest.java @@ -5,9 +5,12 @@ import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.PrintStream; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Scanner; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -33,7 +36,7 @@ public class CardbaseCLITest { * The test remote URL to "query" from, this is actually the same directory * as the test class. Test files need to be placed accordingly. */ - private final String TEST_REMOTE = getClass().getResource("").toString(); + private static String TEST_REMOTE; @Rule public ExpectedException exception = ExpectedException.none(); @@ -41,12 +44,17 @@ public class CardbaseCLITest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); + @BeforeClass + public static void setUpBeforeClass() throws Exception { + TEST_REMOTE = getResourceLocation("SetList.json"); + } + @Before public void setUp() throws Exception { uut = new CardbaseCLI(TEST_REMOTE); testOutput.reset(); } - + /*********************************************************************************** * Start up tests, happy path ***********************************************************************************/ @@ -1566,6 +1574,17 @@ public class CardbaseCLITest { /*********************************************************************************** * Utility methods for dealing with files ***********************************************************************************/ + /** + * For deriving the location of local resources for this class from the location + * of a specific resource. + * + * @return the URI of the resource directory as a string. + */ + private static String getResourceLocation(String resourceName) throws URISyntaxException { + URI location = new URI(CardbaseCLITest.class.getResource(resourceName).getPath()); + return "file:" + location.resolve(".").toString(); + } + /** * Returns the contents of a resource file by reading it with a {@code Scanner}. The file is * loaded using {@code getClass().getResourceAsStream()}, so make sure to address it relative -- cgit v1.2.3