From 2aeb088b6b569428f677c2d17676ebd8e19ac872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 6 Mar 2012 01:31:25 +0100 Subject: [PATCH] Bugfixing und erste Unit Tests erstellt. --- .../ctdo/bunti/model/BuntiDMXDeviceTest.java | 87 +++++++++++++++++++ .../de/ctdo/bunti/model/Par56SpotTest.java | 62 +++++++++++++ .../de/ctdo/bunti/model/Strobe1500Test.java | 62 +++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java create mode 100644 src/test/java/de/ctdo/bunti/model/Par56SpotTest.java create mode 100644 src/test/java/de/ctdo/bunti/model/Strobe1500Test.java diff --git a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java new file mode 100644 index 0000000..a5e4a03 --- /dev/null +++ b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java @@ -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 options = new HashMap(); + options.put("red", 123); + assertTrue(dut.setValuesFromOptions(options)); + } + + + @Test + public void testGetChannelData() throws Exception { + Map options = new HashMap(); + 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 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 channelData = dut.getChannelData(); + assertEquals(6, channelData.size()); + } +} diff --git a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java new file mode 100644 index 0000000..d60f7c4 --- /dev/null +++ b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java @@ -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()); + } +} diff --git a/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java new file mode 100644 index 0000000..809534a --- /dev/null +++ b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java @@ -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()); + } +}