1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/deadlock/src/org/apidesign/deadlock/logs/OverrideMePlease.java Sat Jun 14 09:54:32 2008 +0200
1.3 @@ -0,0 +1,19 @@
1.4 +package org.apidesign.deadlock.logs;
1.5 +
1.6 +import java.util.logging.Logger;
1.7 +
1.8 +
1.9 +public abstract class OverrideMePlease {
1.10 + boolean whatIsDefault;
1.11 +
1.12 + public OverrideMePlease() {
1.13 + whatIsDefault = overideMePlease();
1.14 + }
1.15 + // BEGIN: logs.override
1.16 + protected boolean overideMePlease() {
1.17 + Logger.getLogger(OverrideMePlease.class.getName()).warning("subclasses are supposed to override overideMePlease() method!");
1.18 + // some default
1.19 + return true;
1.20 + }
1.21 + // END: logs.override
1.22 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/OverrideMePleaseTest.java Sat Jun 14 09:54:32 2008 +0200
2.3 @@ -0,0 +1,43 @@
2.4 +package org.apidesign.deadlock.logs;
2.5 +
2.6 +import java.util.logging.Level;
2.7 +import org.junit.After;
2.8 +import org.junit.AfterClass;
2.9 +import org.junit.Before;
2.10 +import org.junit.BeforeClass;
2.11 +import org.junit.Test;
2.12 +import org.netbeans.junit.Log;
2.13 +import static org.junit.Assert.*;
2.14 +
2.15 +public class OverrideMePleaseTest {
2.16 +
2.17 + public OverrideMePleaseTest() {
2.18 + }
2.19 +
2.20 + @Test
2.21 + public void overideMePleaseNotOverriden() {
2.22 + CharSequence log = Log.enable("org.apidesign", Level.WARNING);
2.23 + OverrideMePlease instance = new OverrideMePlease() {
2.24 + };
2.25 + if (log.length() == 0) {
2.26 + fail("There should be a warning: " + log);
2.27 + }
2.28 + }
2.29 +
2.30 + @Test
2.31 + public void overideMePleaseOverriden() {
2.32 + // BEGIN: logs.override.test
2.33 + CharSequence log = Log.enable("org.apidesign", Level.WARNING);
2.34 + OverrideMePlease instance = new OverrideMePlease() {
2.35 + @Override
2.36 + protected boolean overideMePlease() {
2.37 + return true;
2.38 + }
2.39 + };
2.40 + if (log.length() != 0) {
2.41 + fail("There should be no warning: " + log);
2.42 + }
2.43 + // END: logs.override.test
2.44 + }
2.45 +
2.46 +}
2.47 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingTest.java Sat Jun 14 09:54:32 2008 +0200
3.3 @@ -0,0 +1,56 @@
3.4 +package org.apidesign.deadlock.startuplock;
3.5 +
3.6 +import java.io.File;
3.7 +import java.util.logging.Handler;
3.8 +import java.util.logging.Level;
3.9 +import java.util.logging.LogRecord;
3.10 +import java.util.logging.Logger;
3.11 +import org.junit.After;
3.12 +import org.junit.AfterClass;
3.13 +import org.junit.Before;
3.14 +import org.junit.BeforeClass;
3.15 +import org.junit.Test;
3.16 +import static org.junit.Assert.*;
3.17 +
3.18 +// BEGIN: test.capture.logs
3.19 +public class CLIHandlerBlockingTest {
3.20 +
3.21 + public CLIHandlerBlockingTest() {
3.22 + }
3.23 +
3.24 + @BeforeClass
3.25 + public static void initHandler() {
3.26 + Logger.getLogger("").addHandler(new H());
3.27 + Logger.getLogger("").setLevel(Level.ALL);
3.28 + }
3.29 +
3.30 + @Before
3.31 + public void setUp() {
3.32 + H.sb.setLength(0);
3.33 + }
3.34 +
3.35 + @Test
3.36 + public void start() throws Exception {
3.37 + File lockFile = File.createTempFile("pref", ".tmp");
3.38 + int result = CLIHandlerBlocking.start(lockFile);
3.39 + assertEquals("Show a failure" + H.sb, -10, result);
3.40 + }
3.41 +
3.42 + private static final class H extends Handler {
3.43 + static StringBuffer sb = new StringBuffer();
3.44 +
3.45 + @Override
3.46 + public void publish(LogRecord record) {
3.47 + sb.append(record.getMessage()).append('\n');
3.48 + }
3.49 +
3.50 + @Override
3.51 + public void flush() {
3.52 + }
3.53 +
3.54 + @Override
3.55 + public void close() throws SecurityException {
3.56 + }
3.57 + } // end of H
3.58 +// END: test.capture.logs
3.59 +}
3.60 \ No newline at end of file
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingWithNbTestCaseTest.java Sat Jun 14 09:54:32 2008 +0200
4.3 @@ -0,0 +1,35 @@
4.4 +package org.apidesign.deadlock.startuplock;
4.5 +
4.6 +import java.io.File;
4.7 +import java.util.logging.Handler;
4.8 +import java.util.logging.Level;
4.9 +import java.util.logging.LogRecord;
4.10 +import java.util.logging.Logger;
4.11 +import org.junit.After;
4.12 +import org.junit.AfterClass;
4.13 +import org.junit.Before;
4.14 +import org.junit.BeforeClass;
4.15 +import org.junit.Test;
4.16 +import org.netbeans.junit.NbTestCase;
4.17 +import static org.junit.Assert.*;
4.18 +
4.19 +// BEGIN: test.capture.logs.nbjunit
4.20 +public class CLIHandlerBlockingWithNbTestCaseTest extends NbTestCase {
4.21 +
4.22 + public CLIHandlerBlockingWithNbTestCaseTest(String s) {
4.23 + super(s);
4.24 + }
4.25 +
4.26 + @Override
4.27 + protected Level logLevel() {
4.28 + return Level.ALL;
4.29 + }
4.30 +
4.31 +
4.32 + public void testStart() throws Exception {
4.33 + File lockFile = File.createTempFile("pref", ".tmp");
4.34 + int result = CLIHandlerBlocking.start(lockFile);
4.35 + assertEquals("Show a failure", -10, result);
4.36 + }
4.37 +}
4.38 +// END: test.capture.logs.nbjunit