
package org.tros.utils;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.tros.torgo.TorgoInfo;
import org.tros.utils.logging.Logging;

/**
 *
 * @author matta
 */
public class HaltMonitorTest {

    private final static Logger LOGGER;
    
    static {
        Logging.initLogging(TorgoInfo.INSTANCE);
        LOGGER = Logger.getLogger(HaltMonitorTest.class.getName());
    }

    public HaltMonitorTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of getName method, of class HaltMonitor.
     */
    @Test
    public void testGetName() {
        LOGGER.info("getName");
        HaltMonitor instance = new HaltMonitor();
        instance.setName("name");
        String result = instance.getName();
        assertEquals("name", result);
    }

    /**
     * Test of setName method, of class HaltMonitor.
     */
    @Test
    public void testSetName() {
        LOGGER.info("setName");
        HaltMonitor instance = new HaltMonitor();
        instance.setName("name");
        String result = instance.getName();
        assertEquals("name", result);
    }

    /**
     * Test of addHaltListener method, of class HaltMonitor.
     */
    @Test
    public void testAddHaltListener() {
        LOGGER.info("addHaltListener");
        final AtomicBoolean called = new AtomicBoolean(false);
        HaltListener listener = new HaltListener() {
            @Override
            public void halted(ImmutableHaltMonitor monitor) {
                called.set(true);
            }
        };
        HaltMonitor instance = new HaltMonitor();
        instance.addHaltListener(listener);
        instance.halt();
        assertTrue(called.get());
        assertTrue(instance.isHalted());
    }

    /**
     * Test of removeHaltListener method, of class HaltMonitor.
     */
    @Test
    public void testRemoveHaltListener() {
        LOGGER.info("removeHaltListener");
        final AtomicBoolean called = new AtomicBoolean(false);
        HaltListener listener = new HaltListener() {
            @Override
            public void halted(ImmutableHaltMonitor monitor) {
                called.set(true);
            }
        };
        HaltMonitor instance = new HaltMonitor();
        instance.addHaltListener(listener);
        instance.removeHaltListener(listener);
        instance.halt();
        assertFalse(called.get());
        assertTrue(instance.isHalted());

    }

}
