samples/deadlock/test/org/apidesign/deadlock/startuplock/CLIHandlerBlockingTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:59:27 +0200
changeset 181 81d72f69fa42
parent 180 131332825eab
child 263 7e8e995065c5
permissions -rw-r--r--
Incorporating Patrick's changes. I am not reall sure about the changes after the war, it is really 'or' it cannot be 'and'. I will change that when I do the reading through the whole chapter.
     1 package org.apidesign.deadlock.startuplock;
     2 
     3 import java.io.File;
     4 import java.util.logging.Handler;
     5 import java.util.logging.Level;
     6 import java.util.logging.LogRecord;
     7 import java.util.logging.Logger;
     8 import org.junit.After;
     9 import org.junit.AfterClass;
    10 import org.junit.Before;
    11 import org.junit.BeforeClass;
    12 import org.junit.Test;
    13 import static org.junit.Assert.*;
    14 
    15 // BEGIN: test.capture.logs
    16 public class CLIHandlerBlockingTest {
    17 
    18     public CLIHandlerBlockingTest() {
    19     }
    20     
    21     @BeforeClass
    22     public static void initHandler() {
    23         Logger.getLogger("").addHandler(new H());
    24         Logger.getLogger("").setLevel(Level.ALL);
    25     }
    26 
    27     @Before
    28     public void setUp() {
    29         H.sb.setLength(0);
    30     }
    31 
    32     @Test
    33     public void start() throws Exception {
    34         File lockFile = File.createTempFile("pref", ".tmp");
    35         int result = CLIHandlerBlocking.start(lockFile);
    36         assertEquals("Show a failure" + H.sb, -10, result);
    37     }
    38 
    39     private static final class H extends Handler {
    40         static StringBuffer sb = new StringBuffer();
    41         
    42         @Override
    43         public void publish(LogRecord record) {
    44             sb.append(record.getMessage()).append('\n');
    45         }
    46 
    47         @Override
    48         public void flush() {
    49         }
    50 
    51         @Override
    52         public void close() throws SecurityException {
    53         }
    54     } // end of H
    55 }
    56 // END: test.capture.logs