Migrate tests to JUnit 5 (#8519)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.e3dc.dto;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock;
|
||||
import org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock;
|
||||
import org.openhab.binding.modbus.e3dc.internal.dto.StringBlock;
|
||||
@@ -36,7 +36,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
public class DataBlockTest {
|
||||
private Parser mc;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
byte[] dataBlock = new byte[] { 0, -14, 0, 0, -2, -47, -1, -1, 2, 47, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 99, 99, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
@@ -50,10 +50,10 @@ public class DataBlockTest {
|
||||
Optional<Data> dataOpt = mc.parse(DataType.POWER);
|
||||
assertTrue(dataOpt.isPresent());
|
||||
PowerBlock b = (PowerBlock) dataOpt.get();
|
||||
assertEquals("PV Supply", "242.0 W", b.pvPowerSupply.toString());
|
||||
assertEquals("Grid Supply", "14.0 W", b.gridPowerSupply.toString());
|
||||
assertEquals("Grid Consumption", "0.0 W", b.gridPowerConsumpition.toString());
|
||||
assertEquals("Battery Supply", "303.0 W", b.batteryPowerSupply.toString());
|
||||
assertEquals("242.0 W", b.pvPowerSupply.toString(), "PV Supply");
|
||||
assertEquals("14.0 W", b.gridPowerSupply.toString(), "Grid Supply");
|
||||
assertEquals("0.0 W", b.gridPowerConsumpition.toString(), "Grid Consumption");
|
||||
assertEquals("303.0 W", b.batteryPowerSupply.toString(), "Battery Supply");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,10 +65,10 @@ public class DataBlockTest {
|
||||
Optional<WallboxBlock> o = a.getWallboxBlock(0);
|
||||
WallboxBlock b = o.get();
|
||||
assertNotNull(b);
|
||||
assertEquals("Wallbox available", OnOffType.ON, b.wbAvailable);
|
||||
assertEquals("Wallbox Sunmode", OnOffType.ON, b.wbSunmode);
|
||||
assertEquals("Wallbox 1phase", OnOffType.OFF, b.wb1phase);
|
||||
assertEquals("Wallbox charging", OnOffType.OFF, b.wbCharging);
|
||||
assertEquals(OnOffType.ON, b.wbAvailable, "Wallbox available");
|
||||
assertEquals(OnOffType.ON, b.wbSunmode, "Wallbox Sunmode");
|
||||
assertEquals(OnOffType.OFF, b.wb1phase, "Wallbox 1phase");
|
||||
assertEquals(OnOffType.OFF, b.wbCharging, "Wallbox charging");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,14 +76,14 @@ public class DataBlockTest {
|
||||
Optional<Data> dataOpt = mc.parse(DataType.EMERGENCY);
|
||||
assertTrue(dataOpt.isPresent());
|
||||
EmergencyBlock b = (EmergencyBlock) dataOpt.get();
|
||||
assertEquals("EMS Status", EmergencyBlock.EP_NOT_SUPPORTED, b.epStatus.toFullString());
|
||||
assertEquals("Battery charging locked", OnOffType.OFF, b.batteryChargingLocked);
|
||||
assertEquals("Battery discharging locked", OnOffType.OFF, b.batteryDischargingLocked);
|
||||
assertEquals("EP possible", OnOffType.OFF, b.epPossible);
|
||||
assertEquals("Weather Predicted charging", OnOffType.OFF, b.weatherPredictedCharging);
|
||||
assertEquals("Regulation Status", OnOffType.OFF, b.regulationStatus);
|
||||
assertEquals("Charge Lock Time", OnOffType.OFF, b.chargeLockTime);
|
||||
assertEquals("Discharge Lock Time", OnOffType.OFF, b.dischargeLockTime);
|
||||
assertEquals(EmergencyBlock.EP_NOT_SUPPORTED, b.epStatus.toFullString(), "EMS Status");
|
||||
assertEquals(OnOffType.OFF, b.batteryChargingLocked, "Battery charging locked");
|
||||
assertEquals(OnOffType.OFF, b.batteryDischargingLocked, "Battery discharging locked");
|
||||
assertEquals(OnOffType.OFF, b.epPossible, "EP possible");
|
||||
assertEquals(OnOffType.OFF, b.weatherPredictedCharging, "Weather Predicted charging");
|
||||
assertEquals(OnOffType.OFF, b.regulationStatus, "Regulation Status");
|
||||
assertEquals(OnOffType.OFF, b.chargeLockTime, "Charge Lock Time");
|
||||
assertEquals(OnOffType.OFF, b.dischargeLockTime, "Discharge Lock Time");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,26 +91,26 @@ public class DataBlockTest {
|
||||
Optional<Data> dataOpt = mc.parse(DataType.STRINGS);
|
||||
assertTrue(dataOpt.isPresent());
|
||||
StringBlock b = (StringBlock) dataOpt.get();
|
||||
assertEquals("String 1 V", 381, b.string1Volt.intValue());
|
||||
assertEquals("String 1 V", "V", b.string1Volt.getUnit().toString());
|
||||
assertEquals("String 2 V", 533, b.string2Volt.intValue());
|
||||
assertEquals("String 1 V", "V", b.string2Volt.getUnit().toString());
|
||||
assertEquals("String 3 V", 0, b.string3Volt.intValue());
|
||||
assertEquals("String 1 V", "V", b.string3Volt.getUnit().toString());
|
||||
assertEquals(381, b.string1Volt.intValue(), "String 1 V");
|
||||
assertEquals("V", b.string1Volt.getUnit().toString(), "String 1 V");
|
||||
assertEquals(533, b.string2Volt.intValue(), "String 2 V");
|
||||
assertEquals("V", b.string2Volt.getUnit().toString(), "String 1 V");
|
||||
assertEquals(0, b.string3Volt.intValue(), "String 3 V");
|
||||
assertEquals("V", b.string3Volt.getUnit().toString(), "String 1 V");
|
||||
|
||||
assertEquals("String 1 A", 0.27, b.string1Ampere.doubleValue(), 0.01);
|
||||
assertEquals("String 1 A", "A", b.string1Ampere.getUnit().toString());
|
||||
assertEquals("String 2 A", 0.26, b.string2Ampere.doubleValue(), 0.01);
|
||||
assertEquals("String 2 A", "A", b.string2Ampere.getUnit().toString());
|
||||
assertEquals("String 3 A", 0, b.string3Ampere.doubleValue(), 0.01);
|
||||
assertEquals("String 3 A", "A", b.string3Ampere.getUnit().toString());
|
||||
assertEquals(0.27, b.string1Ampere.doubleValue(), 0.01, "String 1 A");
|
||||
assertEquals("A", b.string1Ampere.getUnit().toString(), "String 1 A");
|
||||
assertEquals(0.26, b.string2Ampere.doubleValue(), 0.01, "String 2 A");
|
||||
assertEquals("A", b.string2Ampere.getUnit().toString(), "String 2 A");
|
||||
assertEquals(0, b.string3Ampere.doubleValue(), 0.01, "String 3 A");
|
||||
assertEquals("A", b.string3Ampere.getUnit().toString(), "String 3 A");
|
||||
|
||||
assertEquals("String 1 W", 103, b.string1Watt.intValue());
|
||||
assertEquals("String 1 W", "W", b.string1Watt.getUnit().toString());
|
||||
assertEquals("String 2 W", 139, b.string2Watt.intValue());
|
||||
assertEquals("String 2 W", "W", b.string2Watt.getUnit().toString());
|
||||
assertEquals("String 3 W", 0, b.string3Watt.intValue());
|
||||
assertEquals("String 3 W", "W", b.string3Watt.getUnit().toString());
|
||||
assertEquals(103, b.string1Watt.intValue(), "String 1 W");
|
||||
assertEquals("W", b.string1Watt.getUnit().toString(), "String 1 W");
|
||||
assertEquals(139, b.string2Watt.intValue(), "String 2 W");
|
||||
assertEquals("W", b.string2Watt.getUnit().toString(), "String 2 W");
|
||||
assertEquals(0, b.string3Watt.intValue(), "String 3 W");
|
||||
assertEquals("W", b.string3Watt.getUnit().toString(), "String 3 W");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.e3dc.dto;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock;
|
||||
import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
|
||||
import org.openhab.binding.modbus.e3dc.internal.modbus.Data.DataType;
|
||||
@@ -31,7 +31,7 @@ import org.openhab.binding.modbus.e3dc.internal.modbus.Parser;
|
||||
public class InfoTest {
|
||||
private Parser mc;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
byte[] infoBlock = new byte[] { -29, -36, 1, 2, 0, -120, 69, 51, 47, 68, 67, 32, 71, 109, 98, 72, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 32, 69, 32, 65, 73, 79, 0, 0, 0, 0, 0, 0,
|
||||
@@ -48,10 +48,10 @@ public class InfoTest {
|
||||
assertTrue(infoOpt.isPresent());
|
||||
InfoBlock b = (InfoBlock) infoOpt.get();
|
||||
assertNotNull(b);
|
||||
assertEquals("MagicByte", "E3DC", b.modbusId.toString());
|
||||
assertEquals("Model", "S10 E AIO", b.modelName.toString());
|
||||
assertEquals("Firmware", "S10_2020_04", b.firmware.toString());
|
||||
assertEquals("Manufacturer", "E3/DC GmbH", b.manufacturer.toString());
|
||||
assertEquals("E3DC", b.modbusId.toString(), "MagicByte");
|
||||
assertEquals("S10 E AIO", b.modelName.toString(), "Model");
|
||||
assertEquals("S10_2020_04", b.firmware.toString(), "Firmware");
|
||||
assertEquals("E3/DC GmbH", b.manufacturer.toString(), "Manufacturer");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.e3dc.modbus;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.modbus.e3dc.internal.modbus.Data.DataType;
|
||||
import org.openhab.binding.modbus.e3dc.internal.modbus.Parser;
|
||||
|
||||
@@ -30,11 +30,11 @@ public class ParserNameTest {
|
||||
@Test
|
||||
public void testDebugNames() {
|
||||
Parser mcInfo = new Parser(DataType.INFO);
|
||||
assertEquals("Debug Name Info", "org.openhab.binding.modbus.e3dc.internal.modbus.Parser:INFO",
|
||||
mcInfo.toString());
|
||||
assertEquals("org.openhab.binding.modbus.e3dc.internal.modbus.Parser:INFO", mcInfo.toString(),
|
||||
"Debug Name Info");
|
||||
|
||||
Parser mcPower = new Parser(DataType.DATA);
|
||||
assertEquals("Debug Name Power", "org.openhab.binding.modbus.e3dc.internal.modbus.Parser:DATA",
|
||||
mcPower.toString());
|
||||
assertEquals("org.openhab.binding.modbus.e3dc.internal.modbus.Parser:DATA", mcPower.toString(),
|
||||
"Debug Name Power");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.e3dc.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.modbus.e3dc.internal.dto.DataConverter;
|
||||
|
||||
/**
|
||||
@@ -34,28 +34,28 @@ public class DataConverterTest {
|
||||
// Reg 69 value 65098 bytes [-2, 74]
|
||||
// Reg 70 value 65535 bytes [-1, -1]
|
||||
byte[] b = new byte[] { -2, -74, -1, -1 };
|
||||
assertEquals("Negative Value", -330, DataConverter.getInt32Swap(ByteBuffer.wrap(b)));
|
||||
assertEquals(-330, DataConverter.getInt32Swap(ByteBuffer.wrap(b)), "Negative Value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitset() {
|
||||
byte[] b = new byte[] { 3, 16 };
|
||||
BitSet s = BitSet.valueOf(b);
|
||||
assertEquals("Bit0", true, s.get(0));
|
||||
assertEquals("Bit1", true, s.get(1));
|
||||
assertEquals("Bit2", false, s.get(2));
|
||||
assertEquals("Bit3", false, s.get(3));
|
||||
assertEquals("Bit4", false, s.get(4));
|
||||
assertEquals("Bit5", false, s.get(5));
|
||||
assertEquals("Bit6", false, s.get(6));
|
||||
assertEquals("Bit7", false, s.get(7));
|
||||
assertEquals("Bit8", false, s.get(8));
|
||||
assertEquals("Bit9", false, s.get(9));
|
||||
assertEquals("Bit10", false, s.get(10));
|
||||
assertEquals("Bit11", false, s.get(11));
|
||||
assertEquals("Bit12", true, s.get(12));
|
||||
assertEquals("Bit13", false, s.get(13));
|
||||
assertEquals("Bit14", false, s.get(14));
|
||||
assertEquals("Bit15", false, s.get(15));
|
||||
assertEquals(true, s.get(0), "Bit0");
|
||||
assertEquals(true, s.get(1), "Bit1");
|
||||
assertEquals(false, s.get(2), "Bit2");
|
||||
assertEquals(false, s.get(3), "Bit3");
|
||||
assertEquals(false, s.get(4), "Bit4");
|
||||
assertEquals(false, s.get(5), "Bit5");
|
||||
assertEquals(false, s.get(6), "Bit6");
|
||||
assertEquals(false, s.get(7), "Bit7");
|
||||
assertEquals(false, s.get(8), "Bit8");
|
||||
assertEquals(false, s.get(9), "Bit9");
|
||||
assertEquals(false, s.get(10), "Bit10");
|
||||
assertEquals(false, s.get(11), "Bit11");
|
||||
assertEquals(true, s.get(12), "Bit12");
|
||||
assertEquals(false, s.get(13), "Bit13");
|
||||
assertEquals(false, s.get(14), "Bit14");
|
||||
assertEquals(false, s.get(15), "Bit15");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user