/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.trace;

import org.apache.log4j.Level;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Ignore;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
@SuppressWarnings({
    "all",
    "PMD",
    "NestedSynchronizedStatement"
})
public class ThreadInspectorTest {
    
    private static final AdvLogger LOGGER = LoggerUtils.getLogger();
    
    public ThreadInspectorTest() {
        LoggerUtils.initTest();
    }
    
    @Test
    public void testCount() {
        synchronized(new Lock1()) {
            synchronized(new Lock2()) {
                assertEquals(3,itestCount());
            }
        }
    }
    
    private int itestCount() {
        synchronized(new Lock3()) {
            return ThreadInspector.countLocks();
        }
    }

    @Ignore("manual")
    @Test
    public void testDump() {
        synchronized(new Lock1()) {
            synchronized(new Lock2()) {
                itestDump();
            }
        }
        assertTrue(true);
    }
    
    private void itestDump() {
        synchronized(new Lock3()) {
            ThreadInspector.printLocks(System.out);
        }
    }
    
    @Ignore("manual")
    @Test
    public void testTrace() {
        synchronized(new Lock1()) {
            synchronized(new Lock2()) {
                itestTrace();
            }
        }
        assertTrue(true);
    }
    
    private void itestTrace() {
        synchronized(new Lock3()) {
            ThreadInspector.logLocks(Level.DEBUG, LOGGER);
        }
    }
    
    private static class Lock1 { }
    private static class Lock2 { }
    private static class Lock3 { }
    
}
