package de.ctdo.bunti.dmx;

import org.junit.Before;
import org.junit.Test;

import java.util.Collection;

import static junit.framework.Assert.*;

/**
 * @author: lucas
 * @date: 07.03.12 22:01
 */
public class DMXChannelsTest {
    DMXChannels dut;

    @Before
    public void setUp() throws Exception {
        dut = new DMXChannels();
    }

    @Test
    public void testGetCount1() throws Exception {
        assertEquals(0, dut.getCount());
    }

    @Test
    public void testGetCount2() throws Exception {
        dut.addChannel(new DMXChannel(1, "name"));
        assertEquals(1, dut.getCount());
    }

    @Test
    public void testGetChannelByName() throws Exception {
        dut.addChannel(new DMXChannel(23, "name"));
        assertNotNull(dut.getChannelByName("name"));
        assertEquals(23, dut.getChannelByName("name").getOffset());
    }

    @Test
    public void testAddChannel1() throws Exception {
        assertTrue(dut.addChannel(new DMXChannel(42, "name")));
    }

    @Test
    public void testAddChannel2() throws Exception {
        assertTrue(dut.addChannel(new DMXChannel(42, "name")));
        assertFalse(dut.addChannel(new DMXChannel(42, "name")));
    }

    @Test
    public void testAddChannel3() throws Exception {
        assertFalse(dut.addChannel(new DMXChannel(42, null)));
    }

    @Test
    public void testAddChannel4() throws Exception {
        assertFalse(dut.addChannel(null));
    }

    @Test
    public void testGetAllChannels1() throws Exception {
        assertEquals(0, dut.getAllChannels().size());
    }

    @Test
    public void testGetAllChannels2() throws Exception {
        dut.addChannel(new DMXChannel(23, "name"));
        Collection<DMXChannel> channels = dut.getAllChannels();
        assertEquals(1, channels.size());
    }
}
