Skip to content

Commit

Permalink
10386: PMD and Checkstyle fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sönke Küper <[email protected]>
  • Loading branch information
soenkekueper committed Apr 11, 2021
1 parent 5382013 commit 3d38c97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ private List<Date> parseTimes(final Element element) {
while (matcher.find()) {
final String dateValue = matcher.group(1);
try {
result.add(DATE_FORMAT.parse(dateValue));
synchronized (DATE_FORMAT) {
result.add(DATE_FORMAT.parse(dateValue));
}
} catch (final ParseException e) {
this.logger.warn("Could not parse date: {}", dateValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openhab.core.config.core.Configuration;
Expand All @@ -44,7 +45,7 @@
@NonNullByDefault
public class AhaWasteCollectionHandlerTest {

private static final Configuration config = createConfig();
private static final Configuration CONFIG = createConfig();

private static Configuration createConfig() {
final Configuration config = new Configuration();
Expand All @@ -56,6 +57,18 @@ private static Configuration createConfig() {
return config;
}

/**
* Exception indicating that the execution of an script within the stub-Scheduler failed.
*/
private static class SchedulerRuntimeException extends RuntimeException {

private static final long serialVersionUID = -1262671065082256315L;

public SchedulerRuntimeException(@Nullable final Throwable cause) {
super(cause);
}
}

/**
* Creates an {@link CronScheduler} that executes all commands synchronous.
*/
Expand All @@ -69,7 +82,7 @@ public final ScheduledCompletableFuture<Void> schedule(final CronJob cronJob,
try {
cronJob.run(config);
} catch (final Exception e) {
throw new RuntimeException(e);
throw new SchedulerRuntimeException(e);
}
return Mockito.mock(ScheduledCompletableFuture.class);
}
Expand All @@ -80,7 +93,7 @@ public final ScheduledCompletableFuture<Void> schedule(final SchedulerRunnable r
try {
runnable.run();
} catch (final Exception e) {
throw new RuntimeException(e);
throw new SchedulerRuntimeException(e);
}
return Mockito.mock(ScheduledCompletableFuture.class);
}
Expand Down Expand Up @@ -115,7 +128,6 @@ private static AhaWasteCollectionHandler createAndInitHandler(final ThingHandler
final Thing thing) {
final AhaWasteCollectionHandler handler = new AhaWasteCollectionHandler(thing, createStubScheduler(),
ZoneId::systemDefault, new AhaCollectionScheduleStubFactory());

handler.setCallback(callback);
handler.initialize();
return handler;
Expand All @@ -128,8 +140,7 @@ private static State getDateTime(final Date day) {

@Test
public void testUpdateChannels() {

final Thing thing = mockThing(config);
final Thing thing = mockThing(CONFIG);
final ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
final AhaWasteCollectionHandler handler = createAndInitHandler(callback, thing);

Expand Down

0 comments on commit 3d38c97

Please sign in to comment.