Bugfixing und erste Unit Tests erstellt.

This commit is contained in:
Lucas Pleß 2012-03-06 01:31:25 +01:00
parent bae9549aff
commit 2aeb088b6b
3 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,87 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
import org.apache.commons.collections.map.HashedMap;
import org.junit.Before;
import org.junit.Test;
import sun.org.mozilla.javascript.internal.ast.NewExpression;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
public class BuntiDMXDeviceTest {
private static final int STARTADDRESS = 42;
BuntiDMXDevice dut;
@Before
public void setUp() throws Exception {
dut = new Par56Spot(23,STARTADDRESS,"device");
}
@Test
public void testGetLastSendOut() throws Exception {
assertEquals(0, dut.getLastSendOut());
dut.setSendOutNow();
long value = dut.getLastSendOut();
assertTrue(value > 0 && value <= System.currentTimeMillis());
}
@Test
public void testSetSendOutNow() throws Exception {
dut.setSendOutNow();
long value = dut.getLastSendOut();
assertTrue(value > 0 && value <= System.currentTimeMillis());
}
@Test
public void testGetStartAddress() throws Exception {
assertEquals(42, dut.getStartAddress());
}
@Test
public void testSetStartAddress() throws Exception {
dut.setStartAddress(333);
assertEquals(333, dut.getStartAddress());
}
@Test
public void testSetValuesFromOptions() throws Exception {
Map<String, Object> options = new HashMap<String, Object>();
options.put("red", 123);
assertTrue(dut.setValuesFromOptions(options));
}
@Test
public void testGetChannelData() throws Exception {
Map<String, Object> options = new HashMap<String, Object>();
options.put("blue", 99);
options.put("red", 66);
options.put("green", 77);
options.put("speed", 111);
options.put("mode", 222);
assertTrue(dut.setValuesFromOptions(options));
Map<Integer,Integer> channelData = dut.getChannelData();
assertEquals(channelData.size(), 5);
assertEquals(new Integer(222), channelData.get(STARTADDRESS + 0 + DMX.DMX_STARTADDRESS_OFFSET));
assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1 + DMX.DMX_STARTADDRESS_OFFSET));
assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2 + DMX.DMX_STARTADDRESS_OFFSET));
assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3 + DMX.DMX_STARTADDRESS_OFFSET));
assertEquals(new Integer(111), channelData.get(STARTADDRESS + 4 + DMX.DMX_STARTADDRESS_OFFSET));
}
@Test
public void testAddChannel() throws Exception {
dut.addChannel(new DMXChannel(5, "channel"));
Map<Integer,Integer> channelData = dut.getChannelData();
assertEquals(6, channelData.size());
}
}

View File

@ -0,0 +1,62 @@
package de.ctdo.bunti.model;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class Par56SpotTest {
Par56Spot dut;
@Before
public void setUp() throws Exception {
dut = new Par56Spot(23,42,"device");
}
@Test
public void testColorRed() throws Exception {
dut.setColorRed(0);
assertEquals(0,dut.getColorRed());
dut.setColorRed(128);
assertEquals(128,dut.getColorRed());
dut.setColorRed(255);
assertEquals(255,dut.getColorRed());
}
@Test
public void testColorGreen() throws Exception {
dut.setColorGreen(0);
assertEquals(0,dut.getColorGreen());
dut.setColorGreen(128);
assertEquals(128,dut.getColorGreen());
dut.setColorGreen(255);
assertEquals(255,dut.getColorGreen());
}
@Test
public void testColorBlue() throws Exception {
dut.setColorBlue(0);
assertEquals(0,dut.getColorBlue());
dut.setColorBlue(128);
assertEquals(128,dut.getColorBlue());
dut.setColorBlue(255);
assertEquals(255,dut.getColorBlue());
}
@Test
public void testSwitchOff() throws Exception {
dut.switchOff();
assertEquals(0,dut.getColorRed());
assertEquals(0,dut.getColorGreen());
assertEquals(0,dut.getColorBlue());
}
@Test
public void testSwitchOn() throws Exception {
dut.switchOn();
assertEquals(255,dut.getColorRed());
assertEquals(255,dut.getColorGreen());
assertEquals(255,dut.getColorBlue());
}
}

View File

@ -0,0 +1,62 @@
package de.ctdo.bunti.model;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Strobe1500Test {
Strobe1500 dut;
@Before
public void setUp() throws Exception {
dut = new Strobe1500(23,42,"device");
}
@Test
public void testSpeed() throws Exception {
dut.setSpeed(0);
assertEquals(0,dut.getSpeed());
dut.setSpeed(128);
assertEquals(128,dut.getSpeed());
dut.setSpeed(255);
assertEquals(255,dut.getSpeed());
}
@Test
public void testIntensity() throws Exception {
dut.setIntensity(0);
assertEquals(0,dut.getIntensity());
dut.setIntensity(128);
assertEquals(128,dut.getIntensity());
dut.setIntensity(255);
assertEquals(255,dut.getIntensity());
}
@Test
public void testMode() throws Exception {
dut.setMode(0);
assertEquals(0,dut.getMode());
dut.setMode(128);
assertEquals(128,dut.getMode());
dut.setMode(255);
assertEquals(255,dut.getMode());
}
@Test
public void testSwitchOff() throws Exception {
dut.switchOff();
assertEquals(0,dut.getSpeed());
assertEquals(0,dut.getIntensity());
assertEquals(0,dut.getMode());
}
@Test
public void testSwitchOn() throws Exception {
dut.switchOn();
assertEquals(255,dut.getSpeed());
assertEquals(255,dut.getIntensity());
assertEquals(0,dut.getMode());
}
}