samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingTest.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingTest.java Sat Jun 14 09:54:32 2008 +0200
1.3 @@ -0,0 +1,56 @@
1.4 +package org.apidesign.deadlock.startuplock;
1.5 +
1.6 +import java.io.File;
1.7 +import java.util.logging.Handler;
1.8 +import java.util.logging.Level;
1.9 +import java.util.logging.LogRecord;
1.10 +import java.util.logging.Logger;
1.11 +import org.junit.After;
1.12 +import org.junit.AfterClass;
1.13 +import org.junit.Before;
1.14 +import org.junit.BeforeClass;
1.15 +import org.junit.Test;
1.16 +import static org.junit.Assert.*;
1.17 +
1.18 +// BEGIN: test.capture.logs
1.19 +public class CLIHandlerBlockingTest {
1.20 +
1.21 + public CLIHandlerBlockingTest() {
1.22 + }
1.23 +
1.24 + @BeforeClass
1.25 + public static void initHandler() {
1.26 + Logger.getLogger("").addHandler(new H());
1.27 + Logger.getLogger("").setLevel(Level.ALL);
1.28 + }
1.29 +
1.30 + @Before
1.31 + public void setUp() {
1.32 + H.sb.setLength(0);
1.33 + }
1.34 +
1.35 + @Test
1.36 + public void start() throws Exception {
1.37 + File lockFile = File.createTempFile("pref", ".tmp");
1.38 + int result = CLIHandlerBlocking.start(lockFile);
1.39 + assertEquals("Show a failure" + H.sb, -10, result);
1.40 + }
1.41 +
1.42 + private static final class H extends Handler {
1.43 + static StringBuffer sb = new StringBuffer();
1.44 +
1.45 + @Override
1.46 + public void publish(LogRecord record) {
1.47 + sb.append(record.getMessage()).append('\n');
1.48 + }
1.49 +
1.50 + @Override
1.51 + public void flush() {
1.52 + }
1.53 +
1.54 + @Override
1.55 + public void close() throws SecurityException {
1.56 + }
1.57 + } // end of H
1.58 +// END: test.capture.logs
1.59 +}
1.60 \ No newline at end of file