Skip to content

Commit

Permalink
[dsmr] Removed sat warnings
Browse files Browse the repository at this point in the history
Removed usage of apache library and added NonNullByDefault to test classes..

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
  • Loading branch information
Hilbrand committed Jan 7, 2021
1 parent de3f721 commit d0b98f8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.dsmr.internal.device;

import org.apache.commons.lang.StringUtils;

/**
* Class describing the DSMR bridge user configuration
*
Expand Down Expand Up @@ -60,7 +58,8 @@ public class DSMRDeviceConfiguration {
* @return true if serial port settings are all set.
*/
public boolean isSerialFixedSettings() {
return baudrate > 0 && databits > 0 && !StringUtils.isBlank(parity) && !StringUtils.isBlank(stopbits);
return baudrate > 0 && databits > 0 && !(parity != null && parity.isBlank())
&& !(stopbits != null && stopbits.isBlank());
}

@Override
Expand Down
Expand Up @@ -18,7 +18,7 @@
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramParser;
Expand All @@ -28,6 +28,7 @@
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@NonNullByDefault
public final class TelegramReaderUtil {
private static final String TELEGRAM_EXT = ".telegram";

Expand All @@ -46,7 +47,7 @@ public static byte[] readRawTelegram(String telegramName) {
if (is == null) {
fail("Could not find telegram file with name:" + telegramName + TELEGRAM_EXT);
}
return IOUtils.toByteArray(is);
return is.readAllBytes();
} catch (IOException e) {
throw new AssertionError("IOException reading telegram data: ", e);
}
Expand Down
Expand Up @@ -24,6 +24,8 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -47,18 +49,19 @@
* @author Hilbrand Bouwkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
public class DSMRSerialAutoDeviceTest {

private static final String DUMMY_PORTNAME = "/dev/dummy-serial";
private static final String TELEGRAM_NAME = "dsmr_50";

private @Mock SerialPortIdentifier mockIdentifier;
private @Mock ScheduledExecutorService scheduler;
private @Mock SerialPort mockSerialPort;
private @NonNullByDefault({}) @Mock SerialPortIdentifier mockIdentifier;
private @NonNullByDefault({}) @Mock ScheduledExecutorService scheduler;
private @NonNullByDefault({}) @Mock SerialPort mockSerialPort;

private SerialPortManager serialPortManager = new SerialPortManager() {
private final SerialPortManager serialPortManager = new SerialPortManager() {
@Override
public SerialPortIdentifier getIdentifier(String name) {
public @Nullable SerialPortIdentifier getIdentifier(String name) {
assertEquals(DUMMY_PORTNAME, name, "Expect the passed serial port name");
return mockIdentifier;
}
Expand All @@ -68,7 +71,7 @@ public Stream<SerialPortIdentifier> getIdentifiers() {
return Stream.empty();
}
};
private SerialPortEventListener serialPortEventListener;
private @NonNullByDefault({}) SerialPortEventListener serialPortEventListener;

@BeforeEach
public void setUp() throws PortInUseException, TooManyListenersException {
Expand All @@ -81,7 +84,7 @@ public void setUp() throws PortInUseException, TooManyListenersException {
@Test
public void testHandlingDataAndRestart() throws IOException, PortInUseException {
mockValidSerialPort();
AtomicReference<P1Telegram> telegramRef = new AtomicReference<>(null);
AtomicReference<@Nullable P1Telegram> telegramRef = new AtomicReference<>(null);
DSMREventListener listener = new DSMREventListener() {
@Override
public void handleTelegramReceived(P1Telegram telegram) {
Expand Down Expand Up @@ -114,7 +117,7 @@ public void handleErrorEvent(DSMRConnectorErrorEvent connectorErrorEvent) {

@Test
public void testHandleError() throws IOException, PortInUseException {
AtomicReference<DSMRConnectorErrorEvent> eventRef = new AtomicReference<>(null);
AtomicReference<@Nullable DSMRConnectorErrorEvent> eventRef = new AtomicReference<>(null);
DSMREventListener listener = new DSMREventListener() {
@Override
public void handleTelegramReceived(P1Telegram telegram) {
Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
Expand All @@ -27,6 +28,7 @@
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@NonNullByDefault
public class P1TelegramParserTest {

// @formatter:off
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
Expand All @@ -39,6 +40,7 @@
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@NonNullByDefault
public class DSMRMeterDetectorTest {

// @formatter:off
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
Expand All @@ -45,14 +46,15 @@
* @author Hilbrand Bouwkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
public class DSMRMeterDiscoveryServiceTest {

private static final String EXPECTED_CONFIGURED_TELEGRAM = "dsmr_50";
private static final String UNREGISTERED_METER_TELEGRAM = "unregistered_meter";

private @Mock(answer = Answers.RETURNS_DEEP_STUBS) DSMRBridgeHandler bridge;
private @Mock Thing thing;
private @Mock DSMRMeterHandler meterHandler;
private @NonNullByDefault({}) @Mock(answer = Answers.RETURNS_DEEP_STUBS) DSMRBridgeHandler bridge;
private @NonNullByDefault({}) @Mock Thing thing;
private @NonNullByDefault({}) @Mock DSMRMeterHandler meterHandler;

/**
* Test if discovery reports when the user has incorrectly configured the binding with the wrong meter types.
Expand Down

0 comments on commit d0b98f8

Please sign in to comment.