Fix recently introduced SAT issues (#3516)

* Fix recently introduced SAT issues

Signed-off-by: Wouter Born <github@maindrain.net>
pull/3518/head
Wouter Born 2023-04-01 17:18:22 +02:00 committed by GitHub
parent b745d70d6d
commit 4851bfbcae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 35 additions and 62 deletions

View File

@ -160,7 +160,6 @@ public abstract class MarketplaceBundleInstaller {
logger.warn("Failed reinstalling add-on from cache", e);
}
});
} catch (IOException e) {
logger.warn("Failed to re-install bundles: {}", e.getMessage());
}

View File

@ -298,8 +298,7 @@ public class Addon {
* 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);

View File

@ -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() {

View File

@ -44,7 +44,7 @@ import org.openhab.core.automation.type.ActionType;
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;
@ -64,8 +64,6 @@ import org.osgi.service.jaxrs.whiteboard.propertytypes.JSONRequired;
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;
@ -91,7 +89,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
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;
@ -209,7 +206,7 @@ public class ThingActionsResource implements RESTResource {
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()

View File

@ -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;
@ -74,7 +72,6 @@ public class ItemCommandTriggerHandler extends BaseTriggerModuleHandler implemen
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,

View File

@ -149,11 +149,11 @@ public class AuthenticationHandler implements Handler {
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;
}
}

View File

@ -322,7 +322,6 @@ public class WebClientFactoryImpl implements HttpClientFactory, WebSocketFactory
}
return webSocketClient;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {

View File

@ -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;
@ -162,7 +161,7 @@ public class FolderObserver implements WatchService.WatchEventListener {
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));

View File

@ -88,7 +88,6 @@ public class UpdateChannelInstructionImpl implements ThingUpdateInstruction {
}
private void doChannel(Thing thing, ThingBuilder thingBuilder, ChannelUID affectedChannelUid) {
if (removeOldChannel) {
thingBuilder.withoutChannel(affectedChannelUid);
}

View File

@ -290,7 +290,6 @@ public interface VoiceManager {
* 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;

View File

@ -99,7 +99,6 @@ public class TTSLRUCacheImpl implements TTSCache {
@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);
@ -115,14 +114,14 @@ public class TTSLRUCacheImpl implements TTSCache {
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;
}
}

View File

@ -116,7 +116,6 @@ public class TTSLRUCacheImplTest {
@Test
public void loadTTSResultsFromCacheDirectory() throws IOException, TTSException {
// prepare cache directory
Path cacheDirectory = tempDir.resolve("cache").resolve(TTSLRUCacheImpl.VOICE_TTS_CACHE_PID);
Files.createDirectories(cacheDirectory);

View File

@ -166,7 +166,6 @@ public class LRUMediaCacheEntry<V> {
* @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;

View File

@ -44,7 +44,6 @@ public class WrappedScheduledExecutorService extends ScheduledThreadPoolExecutor
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.

View File

@ -72,7 +72,6 @@ public class ItemStateConverterImpl implements ItemStateConverter {
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) {
@ -92,8 +91,6 @@ public class ItemStateConverterImpl implements ItemStateConverter {
&& UnitUtils.isDifferentMeasurementSystem(conversionUnit, quantityState.getUnit())) {
return convertOrUndef(quantityState, conversionUnit);
}
return state;
} else {
State convertedState = state.as(DecimalType.class);
if (convertedState != null) {

View File

@ -177,7 +177,6 @@ public class SchedulerImpl implements Scheduler {
deferred.thenAccept(v -> {
if (temporalAdjuster instanceof SchedulerTemporalAdjuster schedulerTemporalAdjuster) {
if (!schedulerTemporalAdjuster.isDone(newTime)) {
schedule(recurringSchedule, runnable, identifier, temporalAdjuster);
return;

View File

@ -250,7 +250,6 @@ public class LRUMediaCacheEntryTest {
@Test
public void getTotalSizeByForcingReadAllTest() throws IOException {
LRUMediaCache<MetadataSample> lruMediaCache = createCache(1000);
// init simulated data stream

View File

@ -13,12 +13,8 @@
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;
@ -26,19 +22,19 @@ 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;
@ -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
@ -70,8 +65,6 @@ public class WatchServiceImplTest extends JavaTest {
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");
@ -88,7 +81,8 @@ public class WatchServiceImplTest extends JavaTest {
}
@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);
@ -108,7 +102,8 @@ public class WatchServiceImplTest extends JavaTest {
}
@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);
@ -129,7 +124,8 @@ public class WatchServiceImplTest extends JavaTest {
}
@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);
@ -150,7 +146,8 @@ public class WatchServiceImplTest extends JavaTest {
}
@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);
@ -169,7 +166,8 @@ public class WatchServiceImplTest extends JavaTest {
}
@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));
@ -209,7 +207,7 @@ public class WatchServiceImplTest extends JavaTest {
listener.events.clear();
}
private class TestWatchEventListener implements WatchService.WatchEventListener {
private static class TestWatchEventListener implements WatchService.WatchEventListener {
List<Event> events = new CopyOnWriteArrayList<>();
@Override

View File

@ -398,7 +398,6 @@ public class UnitsTest {
@Override
public boolean matches(@Nullable Object actualValue) {
if (actualValue instanceof Quantity other) {
if (!other.getUnit().isCompatible(quantity.getUnit())) {
return false;
}

View File

@ -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;
@ -38,7 +38,6 @@ import org.openhab.core.thing.Thing;
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 {

View File

@ -15,11 +15,9 @@ package org.openhab.core.thing.internal;
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;
@ -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.