Skip to content

Commit

Permalink
Fix recently introduced SAT issues (openhab#3516)
Browse files Browse the repository at this point in the history
* Fix recently introduced SAT issues

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored Apr 1, 2023
1 parent b745d70 commit 4851bfb
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ protected void ensureCachedBundlesAreInstalled(BundleContext bundleContext) {
logger.warn("Failed reinstalling add-on from cache", e);
}
});

} catch (IOException e) {
logger.warn("Failed to re-install bundles: {}", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ public List<String> getLoggerPackages() {
* Create a builder for an {@link Addon}
*
* @param uid the UID of the add-on (e.g. "binding-dmx", "json:transform-format" or "marketplace:123456")
*
* @return
* @return the builder
*/
public static Builder create(String uid) {
return new Builder(uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public abstract class AbstractAudioServletTest extends JavaTest {
private @NonNullByDefault({}) HttpClient httpClient;
private @NonNullByDefault({}) CompletableFuture<Boolean> serverStarted;

private @Mock @NonNullByDefault({}) HttpService httpServiceMock;
private @Mock @NonNullByDefault({}) HttpContext httpContextMock;
public @Mock @NonNullByDefault({}) HttpService httpServiceMock;
public @Mock @NonNullByDefault({}) HttpContext httpContextMock;

@BeforeEach
public void setupServerAndClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.openhab.core.automation.type.Input;
import org.openhab.core.automation.type.ModuleTypeRegistry;
import org.openhab.core.automation.type.Output;
import org.openhab.core.automation.util.ActionBuilder;
import org.openhab.core.automation.util.ModuleBuilder;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.rest.LocaleService;
import org.openhab.core.io.rest.RESTConstants;
Expand All @@ -64,8 +64,6 @@
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsApplicationSelect;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsName;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -91,7 +89,6 @@
public class ThingActionsResource implements RESTResource {
public static final String PATH_THINGS = "actions";

private final Logger logger = LoggerFactory.getLogger(ThingActionsResource.class);
private final LocaleService localeService;
private final ModuleTypeRegistry moduleTypeRegistry;

Expand Down Expand Up @@ -209,7 +206,7 @@ public Response executeThingAction(@PathParam("thingUID") @Parameter(description

Configuration configuration = new Configuration();
configuration.put("config", thingUID);
Action action = ActionBuilder.createAction().withConfiguration(configuration)
Action action = ModuleBuilder.createAction().withConfiguration(configuration)
.withId(UUID.randomUUID().toString()).withTypeUID(actionTypeUid).build();

ModuleHandlerFactory moduleHandlerFactory = moduleHandlerFactories.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*/
package org.openhab.core.automation.internal.module.handler;

import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -74,7 +72,6 @@ public ItemCommandTriggerHandler(Trigger module, String ruleUID, BundleContext b
this.bundleContext = bundleContext;
this.ruleUID = ruleUID;
this.types = Set.of(ItemCommandEvent.TYPE, ItemAddedEvent.TYPE, ItemRemovedEvent.TYPE);
Dictionary<String, Object> properties = new Hashtable<>();
eventSubscriberRegistration = this.bundleContext.registerService(EventSubscriber.class.getName(), this, null);
if (itemRegistry.get(itemName) == null) {
logger.warn("Item '{}' needed for rule '{}' is missing. Trigger '{}' will not work.", itemName, ruleUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ void activate(Map<String, Object> properties) {
void modified(Map<String, Object> properties) {
Object authenticationEnabled = properties.get(AUTHENTICATION_ENABLED);
if (authenticationEnabled != null) {
this.enabled = Boolean.valueOf(authenticationEnabled.toString());
this.enabled = Boolean.parseBoolean(authenticationEnabled.toString());
}

Object loginUri = properties.get(AUTHENTICATION_ENDPOINT);
if (loginUri != null && loginUri instanceof String) {
if (loginUri instanceof String) {
this.loginUri = (String) loginUri;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ private WebSocketClient createWebSocketClientInternal(String consumerName,
}

return webSocketClient;

} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/
package org.openhab.core.model.core.internal.folder;

import static org.openhab.core.service.WatchService.Kind.CREATE;
import static org.openhab.core.service.WatchService.Kind.MODIFY;
import static org.openhab.core.service.WatchService.Kind.*;

import java.io.File;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -162,7 +161,7 @@ private void addModelsToRepo() {
if (!folderFileExtMap.isEmpty()) {
for (String folderName : folderFileExtMap.keySet()) {
final List<String> validExtension = folderFileExtMap.get(folderName);
if (validExtension != null && validExtension.size() > 0) {
if (validExtension != null && !validExtension.isEmpty()) {
File folder = watchService.getWatchPath().resolve(folderName).toFile();

File[] files = folder.listFiles(new FileExtensionsFilter(validExtension));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void perform(Thing thing, ThingBuilder thingBuilder) {
}

private void doChannel(Thing thing, ThingBuilder thingBuilder, ChannelUID affectedChannelUid) {

if (removeOldChannel) {
thingBuilder.withoutChannel(affectedChannelUid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ void listenAndAnswer(@Nullable STTService stt, @Nullable TTSService tts, @Nullab
* Only one registration can be done for an audio source.
*
* @param registration with the desired services ids and options for the dialog
*
* @throws IllegalStateException if there is another registration for the same source
*/
void registerDialog(DialogRegistration registration) throws IllegalStateException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ protected void modified(Map<String, Object> config) {
@Override
public AudioStream get(CachedTTSService tts, String text, Voice voice, AudioFormat requestedFormat)
throws TTSException {

LRUMediaCache<AudioFormatInfo> lruMediaCacheLocal = lruMediaCache;
if (!enableCacheTTS || lruMediaCacheLocal == null) {
return tts.synthesizeForCache(text, voice, requestedFormat);
Expand All @@ -115,14 +114,14 @@ public AudioStream get(CachedTTSService tts, String text, Voice voice, AudioForm
return new LRUMediaCacheEntry<AudioFormatInfo>(key, audioInputStream,
new AudioFormatInfo(audioInputStream.getFormat()));
} catch (TTSException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
});
} catch (RuntimeException re) {
if (re.getCause() != null && re.getCause() instanceof TTSException ttse) {
} catch (IllegalStateException ise) {
if (ise.getCause() != null && ise.getCause() instanceof TTSException ttse) {
throw ttse;
} else {
throw re;
throw ise;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void getCacheMissAndTwoHitAndTTsIsCalledOnlyOnce() throws TTSException, I

@Test
public void loadTTSResultsFromCacheDirectory() throws IOException, TTSException {

// prepare cache directory
Path cacheDirectory = tempDir.resolve("cache").resolve(TTSLRUCacheImpl.VOICE_TTS_CACHE_PID);
Files.createDirectories(cacheDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ protected String getKey() {
* @throws IOException
*/
public InputStream getInputStream() throws IOException {

File localFile = file;
if (localFile == null) { // the cache entry is not tied to the disk. The cache is not ready or not to be used.
InputStream inputStreamLocal = inputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
Throwable actualThrowable = t;
if (actualThrowable == null && r instanceof Future<?> f) {

// The Future is the wrapper task around our scheduled Runnable. This is only "done" if an Exception
// occurred, the Task was completed, or aborted. A periodic Task (scheduleWithFixedDelay etc.) is NEVER
// "done" unless there was an Exception because the outer Task is always rescheduled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public State convertToAcceptedState(@Nullable State state, @Nullable Item item)

if (item instanceof NumberItem numberItem && state instanceof QuantityType quantityState) {
if (numberItem.getDimension() != null) {

// in case the item does define a unit it takes precedence over all other conversions:
Unit<?> itemUnit = parseItemUnit(numberItem);
if (itemUnit != null) {
Expand All @@ -92,8 +91,6 @@ public State convertToAcceptedState(@Nullable State state, @Nullable Item item)
&& UnitUtils.isDifferentMeasurementSystem(conversionUnit, quantityState.getUnit())) {
return convertOrUndef(quantityState, conversionUnit);
}

return state;
} else {
State convertedState = state.as(DecimalType.class);
if (convertedState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ private <T> void schedule(ScheduledCompletableFutureRecurring<T> recurringSchedu

deferred.thenAccept(v -> {
if (temporalAdjuster instanceof SchedulerTemporalAdjuster schedulerTemporalAdjuster) {

if (!schedulerTemporalAdjuster.isDone(newTime)) {
schedule(recurringSchedule, runnable, identifier, temporalAdjuster);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public void streamAndMetadataTest() throws IOException {

@Test
public void getTotalSizeByForcingReadAllTest() throws IOException {

LRUMediaCache<MetadataSample> lruMediaCache = createCache(1000);

// init simulated data stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,28 @@
package org.openhab.core.internal.service;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.core.JavaTest;
import org.openhab.core.OpenHAB;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.service.WatchService;
import org.openhab.core.service.WatchService.Kind;
import org.osgi.framework.BundleContext;
Expand All @@ -57,11 +53,10 @@ public class WatchServiceImplTest extends JavaTest {

private @NonNullByDefault({}) String systemConfDirProperty;

private @NonNullByDefault({}) WatchServiceImpl.WatchServiceConfiguration configurationMock;
public @Mock @NonNullByDefault({}) WatchServiceImpl.WatchServiceConfiguration configurationMock;

private @NonNullByDefault({}) WatchServiceImpl watchService;
private @NonNullByDefault({}) Path rootPath;
private @NonNullByDefault({}) Path subDirPath;
private @NonNullByDefault({}) TestWatchEventListener listener;

@BeforeEach
Expand All @@ -70,8 +65,6 @@ public void setup() throws IOException {
systemConfDirProperty = System.getProperty(OpenHAB.CONFIG_DIR_PROG_ARGUMENT);

rootPath = Files.createDirectories(Path.of("target", "test-watcher"));
subDirPath = Files.createDirectories(rootPath.resolve(SUB_DIR_PATH_NAME));
ExecutorService ex = ThreadPoolManager.getScheduledPool("file-processing");
System.setProperty(OpenHAB.CONFIG_DIR_PROG_ARGUMENT, rootPath.toString());

when(configurationMock.name()).thenReturn("unnamed");
Expand All @@ -88,7 +81,8 @@ public void tearDown() throws IOException {
}

@Test
private void testFileInWatchedDir() throws IOException, InterruptedException {
@Disabled("Broken")
public void testFileInWatchedDir() throws IOException, InterruptedException {
watchService.registerListener(listener, Path.of(""), false);

Path testFile = rootPath.resolve(TEST_FILE_NANE);
Expand All @@ -108,7 +102,8 @@ private void testFileInWatchedDir() throws IOException, InterruptedException {
}

@Test
private void testFileInWatchedSubDir() throws IOException, InterruptedException {
@Disabled("Broken")
public void testFileInWatchedSubDir() throws IOException, InterruptedException {
// listener is listening to root and sub-dir
watchService.registerListener(listener, Path.of(""), false);

Expand All @@ -129,7 +124,8 @@ private void testFileInWatchedSubDir() throws IOException, InterruptedException
}

@Test
private void testFileInWatchedSubDir2() throws IOException, InterruptedException {
@Disabled("Broken")
public void testFileInWatchedSubDir2() throws IOException, InterruptedException {
// listener is only listening to sub-dir of root
watchService.registerListener(listener, Path.of(SUB_DIR_PATH_NAME), false);

Expand All @@ -150,7 +146,8 @@ private void testFileInWatchedSubDir2() throws IOException, InterruptedException
}

@Test
private void testFileInUnwatchedSubDir() throws IOException, InterruptedException {
@Disabled("Broken")
public void testFileInUnwatchedSubDir() throws IOException, InterruptedException {
watchService.registerListener(listener, Path.of(""), false);

Path testFile = rootPath.resolve(SUB_DIR_PATH_NAME).resolve(TEST_FILE_NANE);
Expand All @@ -169,7 +166,8 @@ private void testFileInUnwatchedSubDir() throws IOException, InterruptedExceptio
}

@Test
private void testNewSubDirAlsoWatched() throws IOException, InterruptedException {
@Disabled("Broken")
public void testNewSubDirAlsoWatched() throws IOException, InterruptedException {
watchService.registerListener(listener, Path.of(""), false);

Path subDirSubDir = Files.createDirectories(rootPath.resolve(SUB_DIR_PATH_NAME).resolve(SUB_DIR_PATH_NAME));
Expand Down Expand Up @@ -209,7 +207,7 @@ private void assertEvent(Path path, Kind kind) throws InterruptedException {
listener.events.clear();
}

private class TestWatchEventListener implements WatchService.WatchEventListener {
private static class TestWatchEventListener implements WatchService.WatchEventListener {
List<Event> events = new CopyOnWriteArrayList<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ public QuantityEquals(Quantity<?> quantity) {
@Override
public boolean matches(@Nullable Object actualValue) {
if (actualValue instanceof Quantity other) {

if (!other.getUnit().isCompatible(quantity.getUnit())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package org.openhab.core.storage.json.internal;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.is;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -38,7 +38,6 @@
public class ThingMigrationOSGiTest extends JavaOSGiTest {
private static final Path DB_DIR = Path.of(OpenHAB.getUserDataFolder(), "jsondb");
private static final String DB_NAME = "org.openhab.core.thing.Thing";
private static final String DB_OLD_NAME = "org.openhab.core.thing.Thing-old";

@Test
public void migrationParsable() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -116,9 +114,9 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest {
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
private @NonNullByDefault({}) ThingRegistry thingRegistry;

private @Mock @NonNullByDefault({}) Bundle bundleMock;
private @Mock @NonNullByDefault({}) BundleResolver bundleResolverMock;
private @Mock @NonNullByDefault({}) ThingHandlerFactory thingHandlerFactoryMock;
public @Mock @NonNullByDefault({}) Bundle bundleMock;
public @Mock @NonNullByDefault({}) BundleResolver bundleResolverMock;
public @Mock @NonNullByDefault({}) ThingHandlerFactory thingHandlerFactoryMock;

/**
* A thing handler which updates the {@link ThingStatus} when initialized to the provided {@code thingStatus} value.
Expand Down

0 comments on commit 4851bfb

Please sign in to comment.