diff --git a/nbjunit/apichanges.xml b/nbjunit/apichanges.xml --- a/nbjunit/apichanges.xml +++ b/nbjunit/apichanges.xml @@ -395,7 +395,23 @@ - + + + NbModuleSuite.Configuration.addTest(Class < ? extends Test> test) + + + + + +

NbModuleSuite.Configuration now has a + addTest(java.lang.Class) + method which allows one to append one or more command line + arguments which will be used to start the application. +

+
+ + +
diff --git a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java b/nbjunit/src/org/netbeans/junit/NbModuleSuite.java --- a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java +++ b/nbjunit/src/org/netbeans/junit/NbModuleSuite.java @@ -125,6 +125,7 @@ final List clusterRegExp; /** each odd is cluster reg exp, each even is module reg exp */ final List moduleRegExp; + final List startupArgs; final ClassLoader parentClassLoader; final boolean reuseUserDir; final boolean gui; @@ -136,6 +137,7 @@ private Configuration( List clusterRegExp, List moduleRegExp, + List startupArgs, ClassLoader parent, List testItems, Class latestTestCase, @@ -148,6 +150,7 @@ ) { this.clusterRegExp = clusterRegExp; this.moduleRegExp = moduleRegExp; + this.startupArgs = startupArgs; this.parentClassLoader = parent; this.tests = testItems; this.reuseUserDir = reuseUserDir; @@ -161,7 +164,7 @@ static Configuration create(Class clazz) { return new Configuration( - null, null, ClassLoader.getSystemClassLoader().getParent(), + null, null, null, ClassLoader.getSystemClassLoader().getParent(), Collections.emptyList(), clazz, false, true, true, false , null, null); } @@ -189,7 +192,7 @@ list = null; } return new Configuration( - list, moduleRegExp, parentClassLoader, tests, + list, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager , failOnMessage, failOnException); @@ -230,14 +233,43 @@ arr.add(clusterRegExp); arr.add(moduleRegExp); return new Configuration( - this.clusterRegExp, arr, parentClassLoader, + this.clusterRegExp, arr, startupArgs, parentClassLoader, + tests, latestTestCaseClass, reuseUserDir, gui, + enableClasspathModules, honorAutoEager, failOnMessage, failOnException); + } + + /** + * Appends one or more command line arguments which will be used to + * start the application. + * + * @param arguments command line arguments to append; each value + * specified here will be passed a separate argument when starting + * the application under test. + * @return clone of this configuration object with the specified + * command line arguments appended to any which may have already + * been present + * @since 1.66 + */ + public Configuration addStartupArgument(String... arguments) { + if (arguments == null || arguments.length < 1){ + throw new IllegalStateException("Must specify at least one startup argument"); + } + + List newArgs = new ArrayList(); + if (startupArgs != null) { + newArgs.addAll(startupArgs); + } + newArgs.addAll(Arrays.asList(arguments)); + + return new Configuration( + clusterRegExp, moduleRegExp, newArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager, failOnMessage, failOnException); } Configuration classLoader(ClassLoader parent) { return new Configuration( - clusterRegExp, moduleRegExp, parent, tests, + clusterRegExp, moduleRegExp, startupArgs, parent, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager , failOnMessage, failOnException); @@ -261,7 +293,7 @@ List newTests = new ArrayList(tests); newTests.add(new Item(true, latestTestCaseClass, testNames)); return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager, failOnMessage, failOnException); } @@ -287,7 +319,7 @@ newTests.add(new Item(true, test, testNames)); } return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, newTests, test, reuseUserDir, gui, enableClasspathModules, honorAutoEager , failOnMessage, failOnException); @@ -295,7 +327,7 @@ /** * Add new {@link junit.framework.Test} to run. The implementation must - * have no parametter constructor. TastCase can be also passed as an argument + * have no parameter constructor. TastCase can be also passed as an argument * of this method than it's delegated to * {@link Configuration#addTest(java.lang.Class, java.lang.String[]) } * @@ -312,7 +344,7 @@ List newTests = new ArrayList(tests); newTests.add(new Item(false, test, null)); return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager , failOnMessage, failOnException); @@ -329,7 +361,7 @@ */ public Configuration enableClasspathModules(boolean enable) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enable, honorAutoEager, failOnMessage, failOnException); } @@ -347,7 +379,7 @@ */ public Configuration honorAutoloadEager(boolean honor) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honor , failOnMessage, failOnException); @@ -362,7 +394,7 @@ */ public Configuration failOnMessage(Level level) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager , level, failOnException); @@ -377,7 +409,7 @@ */ public Configuration failOnException(Level level) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules, honorAutoEager , failOnMessage, level); @@ -398,8 +430,9 @@ private Configuration getReady() { List newTests = new ArrayList(tests); addLatest(newTests); + return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, newTests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules ,honorAutoEager, failOnMessage, failOnException); @@ -416,7 +449,7 @@ */ public Configuration gui(boolean gui) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuseUserDir, gui, enableClasspathModules ,honorAutoEager, failOnMessage, failOnException); @@ -430,7 +463,7 @@ */ public Configuration reuseUserDir(boolean reuse) { return new Configuration( - clusterRegExp, moduleRegExp, parentClassLoader, tests, + clusterRegExp, moduleRegExp, startupArgs, parentClassLoader, tests, latestTestCaseClass, reuse, gui, enableClasspathModules ,honorAutoEager, failOnMessage, failOnException); } @@ -762,6 +795,10 @@ if (!config.gui) { args.add("--nogui"); } + + if (config.startupArgs != null) { + args.addAll(config.startupArgs); + } Test handler = NbModuleLogHandler.registerBuffer(config.failOnMessage, config.failOnException); m.invoke(null, (Object)args.toArray(new String[0])); diff --git a/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java b/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java --- a/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java +++ b/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteTest.java @@ -389,4 +389,18 @@ assertProperty("t.one", "OK"); } + + public void testAddStartupArgument()throws Exception{ + System.setProperty("t.arg", "No"); + + Test instance = NbModuleSuite.create( + NbModuleSuite.createConfiguration(NbModuleSuiteT.class) + .gui(false) + .addStartupArgument("--branding", "sample") + ); + + junit.textui.TestRunner.run(instance); + + assertProperty("t.arg", "OK"); + } } diff --git a/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java b/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java --- a/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java +++ b/nbjunit/test/unit/src/test/pkg/not/in/junit/NbModuleSuiteT.java @@ -1,6 +1,7 @@ package test.pkg.not.in.junit; import junit.framework.TestCase; +import org.openide.util.NbBundle; public class NbModuleSuiteT extends TestCase { @@ -15,4 +16,10 @@ public void testFullhack() { System.setProperty("t.hack", System.getProperty("netbeans.full.hack")); } + + public void testStartupArg() { + if ("sample".equals(NbBundle.getBranding())) { + System.setProperty("t.arg", "OK"); + } + } }