aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-12-20 11:20:39 +0100
committerJiri Vanek <[email protected]>2013-12-20 11:20:39 +0100
commit99428f6f586269f4b5856f93adb71385f6c64c97 (patch)
treef13560c1d4d7200583dc858b1ad8c387023f5013 /tests
parentc3b3c491051c08e035593a25850e537168bb1db9 (diff)
singletons logic, logs and test cleanup/fixes
Diffstat (limited to 'tests')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/logging/JavaConsoleTest.java1
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/util/logging/NoStdOutErrTest.java65
2 files changed, 38 insertions, 28 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/logging/JavaConsoleTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/logging/JavaConsoleTest.java
index 8b36bac..b4ab4c8 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/util/logging/JavaConsoleTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/logging/JavaConsoleTest.java
@@ -21,7 +21,6 @@ public class JavaConsoleTest {
@Test
public void CreatePluginHeaderTestOK() throws Exception{
PluginMessage p1 = new PluginMessage(s1);
- System.out.println(p1.header + p1.restOfMessage);
PluginMessage p3 = new PluginMessage(s3);
Assert.assertFalse(p1.wasError);
Assert.assertFalse(p3.wasError);
diff --git a/tests/test-extensions/net/sourceforge/jnlp/util/logging/NoStdOutErrTest.java b/tests/test-extensions/net/sourceforge/jnlp/util/logging/NoStdOutErrTest.java
index ee9e977..456c9d2 100644
--- a/tests/test-extensions/net/sourceforge/jnlp/util/logging/NoStdOutErrTest.java
+++ b/tests/test-extensions/net/sourceforge/jnlp/util/logging/NoStdOutErrTest.java
@@ -34,11 +34,11 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
*/
+
package net.sourceforge.jnlp.util.logging;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import net.sourceforge.jnlp.ServerAccess;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -54,36 +54,47 @@ import org.junit.BeforeClass;
* by junit classlaoder is visible from itw, but not vice verse.
*/
public class NoStdOutErrTest {
-
+
private static boolean origialStds;
-
private static final String setLogToStreams = "setLogToStreams";
-
- @BeforeClass
- public static void disableStds() throws Exception {
- //init logger and log and flush message
- //it is crucial for junit to grip it
- OutputController.getLogger().log("initialising");
- //one more times: if TESTED class is the first which creates instance of logger
- //then when junit can not access this class, and creates its own for its purposes
- //when junit creates this class, then also TESTED class have access to it and so it behaves as expected
- OutputController.getLogger().flush();
- origialStds = LogConfig.getLogConfig().isLogToStreams();
- invokeSetLogToStreams(false);
+ /*
+ * "printed" exceptions are otherwise consumed via junit if thrown :-/
+ */
+
+ @BeforeClass
+ public static synchronized void disableStds() {
+ try {
+ //init logger and log and flush message
+ //it is crucial for junit to grip it
+ OutputController.getLogger().log("initialising");
+ //one more times: if TESTED class is the first which creates instance of logger
+ //then when junit can not access this class, and creates its own for its purposes
+ //when junit creates this class, then also TESTED class have access to it and so it behaves as expected
+ OutputController.getLogger().flush();
+ origialStds = LogConfig.getLogConfig().isLogToStreams();
+ invokeSetLogToStreams(false);
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ }
}
-
+
@AfterClass
- public static void restoreStds() throws Exception {
- OutputController.getLogger().flush();
- invokeSetLogToStreams(origialStds);
+ public static synchronized void restoreStds() {
+ try {
+ OutputController.getLogger().flush();
+ invokeSetLogToStreams(origialStds);
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ }
}
- private static void invokeSetLogToStreams(boolean state) throws IllegalAccessException, SecurityException, NoSuchMethodException, InvocationTargetException, IllegalArgumentException {
- Method lcs = LogConfig.class.getDeclaredMethod(setLogToStreams, boolean.class);
- lcs.setAccessible(true);
- lcs.invoke(LogConfig.getLogConfig(), state);
+ private static synchronized void invokeSetLogToStreams(boolean state) {
+ try {
+ Method lcs = LogConfig.class.getDeclaredMethod(setLogToStreams, boolean.class);
+ lcs.setAccessible(true);
+ lcs.invoke(LogConfig.getLogConfig(), state);
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ }
}
-
-
-
}