Author: fdesbois Date: 2010-06-17 15:36:25 +0200 (Thu, 17 Jun 2010) New Revision: 1884 Url: http://nuiton.org/repositories/revision/nuiton-utils/1884 Log: Ano #687 : Clean test initialization Modified: trunk/src/test/java/org/nuiton/util/ApplicationConfigTest.java Modified: trunk/src/test/java/org/nuiton/util/ApplicationConfigTest.java =================================================================== --- trunk/src/test/java/org/nuiton/util/ApplicationConfigTest.java 2010-06-17 13:31:02 UTC (rev 1883) +++ trunk/src/test/java/org/nuiton/util/ApplicationConfigTest.java 2010-06-17 13:36:25 UTC (rev 1884) @@ -37,7 +37,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; import org.junit.Assert; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.util.ApplicationConfig.Action; @@ -49,30 +49,32 @@ private static final Log log = LogFactory.getLog(ApplicationConfigTest.class); - // says testsData is where we start tests. - protected File testsDataDir; + /** main folder for tests data **/ + protected static File DIR_TESTS_DATA; protected static final String SYSTEM_PROPERTY_USER_HOME = "user.home"; - @Before - public void setUp() throws IOException { + protected static int DUMMY_ACTION_CALL = 0; + + public static class DummyAction { + @Action.Step(1) + public void dummyAction(String s, int step) { + DUMMY_ACTION_CALL++; + System.out.println(s + ":" + step); + } + } + + @BeforeClass + public static void setUpClass() throws IOException { + // Initialize DIR_TESTS_DATA to target/surefire-data String basedirPath = System.getenv("basedir"); if (basedirPath == null) { basedirPath = new File("").getAbsolutePath(); } - testsDataDir = new File(basedirPath, + DIR_TESTS_DATA = new File(basedirPath, "target" + File.separator + "surefire-data"); - FileUtil.createDirectoryIfNecessary(testsDataDir); + FileUtil.createDirectoryIfNecessary(DIR_TESTS_DATA); } - - static int dummyActionCall = 0; - static public class DummyAction { - @Action.Step(1) - public void dummyAction(String s, int step) { - dummyActionCall++; - System.out.println(s + ":" + step); - } - } @Test public void testSaveForUser() { @@ -81,7 +83,7 @@ /** PREPARE DATA **/ // Initiliaze path and filename - String path = new File(testsDataDir, "user").getAbsolutePath(); + String path = new File(DIR_TESTS_DATA, "user").getAbsolutePath(); String filename = "test-saveForUser.properties"; // Set path to USER_HOME (keep old value) @@ -152,14 +154,14 @@ Action action = new Action(1, new DummyAction(), DummyAction.class.getMethod("dummyAction", String.class, Integer.TYPE), "coucou", "12"); instance.addAction(action); - dummyActionCall = 0; - Assert.assertEquals(0, dummyActionCall); + DUMMY_ACTION_CALL = 0; + Assert.assertEquals(0, DUMMY_ACTION_CALL); instance.doAction(0); - Assert.assertEquals(0, dummyActionCall); + Assert.assertEquals(0, DUMMY_ACTION_CALL); instance.doAction(1); - Assert.assertEquals(1, dummyActionCall); + Assert.assertEquals(1, DUMMY_ACTION_CALL); instance.doAction(2); - Assert.assertEquals(1, dummyActionCall); + Assert.assertEquals(1, DUMMY_ACTION_CALL); } /** @@ -264,9 +266,9 @@ Action result = instance.createAction( DummyAction.class.getName() + "#dummyAction", args); Assert.assertEquals(1, result.step); - dummyActionCall = 0; + DUMMY_ACTION_CALL = 0; result.doAction(); - Assert.assertEquals(1, dummyActionCall); + Assert.assertEquals(1, DUMMY_ACTION_CALL); } /** @@ -284,7 +286,7 @@ instance.addAlias("-m", "--" + DummyAction.class.getName() + "#dummyAction"); instance.parse(args); - dummyActionCall = 0; + DUMMY_ACTION_CALL = 0; Assert.assertEquals("file", instance.getOption("file")); Assert.assertEquals("true", instance.getOption("verbose")); Assert.assertEquals("true", instance.getOption("debug")); @@ -292,7 +294,7 @@ Assert.assertEquals(Arrays.asList("others", "args"), instance.getUnparsed()); instance.doAction(1); - Assert.assertEquals(1, dummyActionCall); + Assert.assertEquals(1, DUMMY_ACTION_CALL); } /**
participants (1)
-
fdesbois@users.nuiton.org