Skip to content

Commit

Permalink
just use SafeCallerImpl directly, instead of trying to mock it out
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Nov 30, 2022
1 parent 4301892 commit 3ea276c
Showing 1 changed file with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
import org.mockito.quality.Strictness;
import org.openhab.core.automation.module.script.ScriptDependencyTracker;
import org.openhab.core.automation.module.script.ScriptEngineFactory;
import org.openhab.core.common.SafeCaller;
import org.openhab.core.common.SafeCallerBuilder;
import org.openhab.core.internal.common.SafeCallerImpl;

/**
* The {@link ScriptEngineManagerImplTest} is a test class for the {@link ScriptEngineManagerImpl}
Expand All @@ -65,44 +64,6 @@ public class ScriptEngineManagerImplTest {

private @NonNullByDefault({}) ScriptEngineManagerImpl scriptEngineManager;

private static class SafeCallerMock implements SafeCaller {
public <T> SafeCallerBuilder<T> create(T target, Class<T> interfaceType) {
return new SafeCallerBuilderMock(target);
}

private static class SafeCallerBuilderMock<T> implements SafeCallerBuilder<T> {
final T target;

SafeCallerBuilderMock(T target) {
this.target = target;
}

public T build() {
return target;
}

public SafeCallerBuilder<T> withTimeout(long timeout) {
return this;
}

public SafeCallerBuilder<T> withIdentifier(Object identifier) {
return this;
}

public SafeCallerBuilder<T> onException(Consumer<Throwable> exceptionHandler) {
return this;
}

public SafeCallerBuilder<T> onTimeout(Runnable timeoutHandler) {
return this;
}

public SafeCallerBuilder<T> withAsync() {
return this;
}
}
}

@BeforeEach
public void setup() {
when(scriptEngineMock.getFactory()).thenReturn(internalScriptEngineFactoryMock);
Expand All @@ -113,7 +74,7 @@ public void setup() {
when(scriptEngineFactoryMock.getDependencyTracker()).thenReturn(scriptDependencyTrackerMock);
when(scriptDependencyTrackerMock.getTracker(any())).thenReturn(dependencyListenerMock);

scriptEngineManager = new ScriptEngineManagerImpl(scriptExtensionManagerMock, new SafeCallerMock());
scriptEngineManager = new ScriptEngineManagerImpl(scriptExtensionManagerMock, new SafeCallerImpl(null));
scriptEngineManager.addScriptEngineFactory(scriptEngineFactoryMock);
}

Expand Down

0 comments on commit 3ea276c

Please sign in to comment.