samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:05 +0200
changeset 152 eb6f29070331
parent 107 907f5d8e343c
child 153 b5cbb797ec0a
permissions -rw-r--r--
Checking that all examples pair the opening and closing brackets
jtulach@107
     1
package org.apidesign.deadlock.startuplock;
jtulach@107
     2
jtulach@107
     3
import java.io.File;
jtulach@107
     4
import java.util.logging.Handler;
jtulach@107
     5
import java.util.logging.Level;
jtulach@107
     6
import java.util.logging.LogRecord;
jtulach@107
     7
import java.util.logging.Logger;
jtulach@107
     8
import org.junit.After;
jtulach@107
     9
import org.junit.AfterClass;
jtulach@107
    10
import org.junit.Before;
jtulach@107
    11
import org.junit.BeforeClass;
jtulach@107
    12
import org.junit.Test;
jtulach@107
    13
import static org.junit.Assert.*;
jtulach@107
    14
jtulach@107
    15
// BEGIN: test.capture.logs
jtulach@107
    16
public class CLIHandlerBlockingTest {
jtulach@107
    17
jtulach@107
    18
    public CLIHandlerBlockingTest() {
jtulach@107
    19
    }
jtulach@107
    20
    
jtulach@107
    21
    @BeforeClass
jtulach@107
    22
    public static void initHandler() {
jtulach@107
    23
        Logger.getLogger("").addHandler(new H());
jtulach@107
    24
        Logger.getLogger("").setLevel(Level.ALL);
jtulach@107
    25
    }
jtulach@107
    26
jtulach@107
    27
    @Before
jtulach@107
    28
    public void setUp() {
jtulach@107
    29
        H.sb.setLength(0);
jtulach@107
    30
    }
jtulach@107
    31
jtulach@107
    32
    @Test
jtulach@107
    33
    public void start() throws Exception {
jtulach@107
    34
        File lockFile = File.createTempFile("pref", ".tmp");
jtulach@107
    35
        int result = CLIHandlerBlocking.start(lockFile);
jtulach@107
    36
        assertEquals("Show a failure" + H.sb, -10, result);
jtulach@107
    37
    }
jtulach@107
    38
jtulach@107
    39
    private static final class H extends Handler {
jtulach@107
    40
        static StringBuffer sb = new StringBuffer();
jtulach@107
    41
        
jtulach@107
    42
        @Override
jtulach@107
    43
        public void publish(LogRecord record) {
jtulach@107
    44
            sb.append(record.getMessage()).append('\n');
jtulach@107
    45
        }
jtulach@107
    46
jtulach@107
    47
        @Override
jtulach@107
    48
        public void flush() {
jtulach@107
    49
        }
jtulach@107
    50
jtulach@107
    51
        @Override
jtulach@107
    52
        public void close() throws SecurityException {
jtulach@107
    53
        }
jtulach@107
    54
    } // end of H
jtulach@152
    55
}
jtulach@107
    56
// END: test.capture.logs