Java 17 features (N-S) (#15565)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.revogi.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -34,8 +33,8 @@ import org.osgi.service.component.annotations.Component;
|
||||
@Component(configurationPid = "binding.revogi", service = ThingHandlerFactory.class)
|
||||
public class RevogiSmartStripControlHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
|
||||
.singleton(RevogiSmartStripControlBindingConstants.SMART_STRIP_THING_TYPE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
|
||||
.of(RevogiSmartStripControlBindingConstants.SMART_STRIP_THING_TYPE);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.revogi.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -43,8 +42,8 @@ import org.osgi.service.component.annotations.Component;
|
||||
@Component(service = DiscoveryService.class, configurationPid = "discovery.revogi")
|
||||
@NonNullByDefault
|
||||
public class RevogiSmartStripDiscoveryService extends AbstractDiscoveryService {
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
|
||||
.singleton(RevogiSmartStripControlBindingConstants.SMART_STRIP_THING_TYPE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set
|
||||
.of(RevogiSmartStripControlBindingConstants.SMART_STRIP_THING_TYPE);
|
||||
|
||||
private final RevogiDiscoveryService revogiDiscoveryService;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RevogiDiscoveryServiceTest {
|
||||
public void discoverSmartStripSuccesfully() {
|
||||
// given
|
||||
DiscoveryResponseDTO discoveryResponse = new DiscoveryResponseDTO("1234", "reg", "sak", "Strip", "mac", "5.11");
|
||||
List<UdpResponseDTO> discoveryString = Collections.singletonList(new UdpResponseDTO(
|
||||
List<UdpResponseDTO> discoveryString = List.of(new UdpResponseDTO(
|
||||
"{\"response\":0,\"data\":{\"sn\":\"1234\",\"regid\":\"reg\",\"sak\":\"sak\",\"name\":\"Strip\",\"mac\":\"mac\",\"ver\":\"5.11\"}}",
|
||||
"127.0.0.1"));
|
||||
when(udpSenderService.broadcastUdpDatagram("00sw=all,,,;"))
|
||||
@@ -61,8 +61,7 @@ public class RevogiDiscoveryServiceTest {
|
||||
@Test
|
||||
public void invalidUdpResponse() throws ExecutionException, InterruptedException {
|
||||
// given
|
||||
List<UdpResponseDTO> discoveryString = Collections
|
||||
.singletonList(new UdpResponseDTO("something invalid", "12345"));
|
||||
List<UdpResponseDTO> discoveryString = List.of(new UdpResponseDTO("something invalid", "12345"));
|
||||
when(udpSenderService.broadcastUdpDatagram("00sw=all,,,;"))
|
||||
.thenReturn(CompletableFuture.completedFuture(discoveryString));
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class StatusServiceTest {
|
||||
// given
|
||||
StatusDTO status = new StatusDTO(true, 200, Arrays.asList(0, 0, 0, 0, 0, 0), Arrays.asList(0, 0, 0, 0, 0, 0),
|
||||
Arrays.asList(0, 0, 0, 0, 0, 0));
|
||||
List<UdpResponseDTO> statusString = Collections.singletonList(new UdpResponseDTO(
|
||||
List<UdpResponseDTO> statusString = List.of(new UdpResponseDTO(
|
||||
"V3{\"response\":90,\"code\":200,\"data\":{\"switch\":[0,0,0,0,0,0],\"watt\":[0,0,0,0,0,0],\"amp\":[0,0,0,0,0,0]}}",
|
||||
"127.0.0.1"));
|
||||
when(udpSenderService.sendMessage("V3{\"sn\":\"serial\", \"cmd\": 90}", "127.0.0.1"))
|
||||
@@ -56,7 +55,7 @@ public class StatusServiceTest {
|
||||
@Test
|
||||
public void invalidUdpResponse() {
|
||||
// given
|
||||
List<UdpResponseDTO> statusString = Collections.singletonList(new UdpResponseDTO("something invalid", "12345"));
|
||||
List<UdpResponseDTO> statusString = List.of(new UdpResponseDTO("something invalid", "12345"));
|
||||
when(udpSenderService.sendMessage("V3{\"sn\":\"serial\", \"cmd\": 90}", "127.0.0.1"))
|
||||
.thenReturn(CompletableFuture.completedFuture(statusString));
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -39,8 +38,7 @@ public class SwitchServiceTest {
|
||||
@Test
|
||||
public void getStatusSuccesfully() {
|
||||
// given
|
||||
List<UdpResponseDTO> response = Collections
|
||||
.singletonList(new UdpResponseDTO("V3{\"response\":20,\"code\":200}", "127.0.0.1"));
|
||||
List<UdpResponseDTO> response = List.of(new UdpResponseDTO("V3{\"response\":20,\"code\":200}", "127.0.0.1"));
|
||||
when(udpSenderService.sendMessage("V3{\"sn\":\"serial\", \"cmd\": 20, \"port\": 1, \"state\": 1}", "127.0.0.1"))
|
||||
.thenReturn(CompletableFuture.completedFuture(response));
|
||||
|
||||
@@ -54,8 +52,7 @@ public class SwitchServiceTest {
|
||||
@Test
|
||||
public void getStatusSuccesfullyWithBroadcast() {
|
||||
// given
|
||||
List<UdpResponseDTO> response = Collections
|
||||
.singletonList(new UdpResponseDTO("V3{\"response\":20,\"code\":200}", "127.0.0.1"));
|
||||
List<UdpResponseDTO> response = List.of(new UdpResponseDTO("V3{\"response\":20,\"code\":200}", "127.0.0.1"));
|
||||
when(udpSenderService.broadcastUdpDatagram("V3{\"sn\":\"serial\", \"cmd\": 20, \"port\": 1, \"state\": 1}"))
|
||||
.thenReturn(CompletableFuture.completedFuture(response));
|
||||
|
||||
@@ -69,7 +66,7 @@ public class SwitchServiceTest {
|
||||
@Test
|
||||
public void invalidUdpResponse() {
|
||||
// given
|
||||
List<UdpResponseDTO> response = Collections.singletonList(new UdpResponseDTO("something invalid", "12345"));
|
||||
List<UdpResponseDTO> response = List.of(new UdpResponseDTO("something invalid", "12345"));
|
||||
when(udpSenderService.sendMessage("V3{\"sn\":\"serial\", \"cmd\": 20, \"port\": 1, \"state\": 1}", "127.0.0.1"))
|
||||
.thenReturn(CompletableFuture.completedFuture(response));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user