From 8f82ab3e8e01cb6f73f6668a458783baf011d1e6 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 12 Apr 2016 16:15:35 -0400 Subject: [PATCH] Tests now use MockFrameGrabberFactory so tests wont hang --- .../edu/wpi/grip/core/GRIPCoreModule.java | 1 - .../src/main/java/edu/wpi/grip/core/Main.java | 3 ++- .../sources/GRIPSourcesHardwareModule.java | 13 ++++++++++++ .../core/serialization/CompatibilityTest.java | 2 +- .../grip/core/sources/MockCameraSource.java | 19 ++--------------- .../core/sources/MockFrameGrabberFactory.java | 21 +++++++++++++++++++ .../edu/wpi/grip/util/GRIPCoreTestModule.java | 3 +++ ui/src/main/java/edu/wpi/grip/ui/Main.java | 3 ++- 8 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 core/src/main/java/edu/wpi/grip/core/sources/GRIPSourcesHardwareModule.java create mode 100644 core/src/test/java/edu/wpi/grip/core/sources/MockFrameGrabberFactory.java diff --git a/core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java b/core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java index c4869ad969..fda27d7fef 100644 --- a/core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java +++ b/core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java @@ -109,7 +109,6 @@ public void hear(TypeLiteral type, TypeEncounter encounter) { bind(ConnectionValidator.class).to(Pipeline.class); bind(Source.SourceFactory.class).to(Source.SourceFactoryImpl.class); - bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class); install(new FactoryModuleBuilder() .implement(CameraSource.class, CameraSource.class) .build(CameraSource.Factory.class)); diff --git a/core/src/main/java/edu/wpi/grip/core/Main.java b/core/src/main/java/edu/wpi/grip/core/Main.java index cbd35fdf8e..ebbaef8a26 100644 --- a/core/src/main/java/edu/wpi/grip/core/Main.java +++ b/core/src/main/java/edu/wpi/grip/core/Main.java @@ -9,6 +9,7 @@ import edu.wpi.grip.core.operations.Operations; import edu.wpi.grip.core.operations.network.GRIPNetworkModule; import edu.wpi.grip.core.serialization.Project; +import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule; import edu.wpi.grip.generated.CVOperations; import javax.inject.Inject; @@ -30,7 +31,7 @@ public class Main { @SuppressWarnings("PMD.SystemPrintln") public static void main(String[] args) throws IOException, InterruptedException { - final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule()); + final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule()); injector.getInstance(Main.class).start(args); } diff --git a/core/src/main/java/edu/wpi/grip/core/sources/GRIPSourcesHardwareModule.java b/core/src/main/java/edu/wpi/grip/core/sources/GRIPSourcesHardwareModule.java new file mode 100644 index 0000000000..c7a0b388dc --- /dev/null +++ b/core/src/main/java/edu/wpi/grip/core/sources/GRIPSourcesHardwareModule.java @@ -0,0 +1,13 @@ +package edu.wpi.grip.core.sources; + +import com.google.inject.AbstractModule; + +/** + * Adds bindings for hardware that is required by {@link edu.wpi.grip.core.Source Sources} + */ +public class GRIPSourcesHardwareModule extends AbstractModule { + @Override + protected void configure() { + bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class); + } +} diff --git a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java index ac89388317..06286cd29b 100644 --- a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java +++ b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java @@ -76,7 +76,7 @@ public void tearDown() { } @Test - public void testFoo() throws Exception { + public void testCompatibilityIsMaintained() throws Exception { assertEquals("The expected number of steps were not found", 50, pipeline.getSteps().size()); assertEquals("The expected number of sources were not found", 2, pipeline.getSources().size()); pipeline.clear(); diff --git a/core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java b/core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java index 469ff5c137..af0c2f3f59 100644 --- a/core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java +++ b/core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java @@ -2,34 +2,19 @@ import com.google.common.eventbus.EventBus; import edu.wpi.grip.core.util.MockExceptionWitness; -import org.bytedeco.javacv.FrameGrabber; import java.io.IOException; -import java.net.MalformedURLException; public class MockCameraSource extends CameraSource { private boolean started = false; - static class FrameGrabberFactory implements CameraSource.FrameGrabberFactory { - - @Override - public FrameGrabber create(int deviceNumber) { - return null; - } - - @Override - public FrameGrabber create(String addressProperty) throws MalformedURLException { - return null; - } - } - public MockCameraSource(EventBus eventBus, String address) throws IOException { - super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address); + super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address); } public MockCameraSource(EventBus eventBus, int deviceNumber) throws IOException { - super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber); + super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber); } @Override diff --git a/core/src/test/java/edu/wpi/grip/core/sources/MockFrameGrabberFactory.java b/core/src/test/java/edu/wpi/grip/core/sources/MockFrameGrabberFactory.java new file mode 100644 index 0000000000..2a5efdae21 --- /dev/null +++ b/core/src/test/java/edu/wpi/grip/core/sources/MockFrameGrabberFactory.java @@ -0,0 +1,21 @@ +package edu.wpi.grip.core.sources; + +import org.bytedeco.javacv.FrameGrabber; + +import java.net.MalformedURLException; + +/** + * Frame Grabber Factory that mocks out the frame grabber that it returns + */ +public class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory { + + @Override + public FrameGrabber create(int deviceNumber) { + return new SimpleMockFrameGrabber(); + } + + @Override + public FrameGrabber create(String addressProperty) throws MalformedURLException { + return new SimpleMockFrameGrabber(); + } +} diff --git a/core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java b/core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java index 3517108391..d4f88985e3 100644 --- a/core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java +++ b/core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java @@ -3,6 +3,8 @@ import com.google.common.eventbus.SubscriberExceptionContext; import edu.wpi.grip.core.GRIPCoreModule; +import edu.wpi.grip.core.sources.CameraSource; +import edu.wpi.grip.core.sources.MockFrameGrabberFactory; import java.util.ArrayList; import java.util.List; @@ -68,6 +70,7 @@ public void tearDown() { @Override protected void configure() { assert setUp : "The GRIPCoreTestModule handler was not set up. Call 'setUp' before passing the injector"; + bind(CameraSource.FrameGrabberFactory.class).to(MockFrameGrabberFactory.class); super.configure(); } diff --git a/ui/src/main/java/edu/wpi/grip/ui/Main.java b/ui/src/main/java/edu/wpi/grip/ui/Main.java index 5903ab3332..d5d45748a3 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/Main.java +++ b/ui/src/main/java/edu/wpi/grip/ui/Main.java @@ -13,6 +13,7 @@ import edu.wpi.grip.core.operations.Operations; import edu.wpi.grip.core.operations.network.GRIPNetworkModule; import edu.wpi.grip.core.serialization.Project; +import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule; import edu.wpi.grip.core.util.SafeShutdown; import edu.wpi.grip.generated.CVOperations; import edu.wpi.grip.ui.util.DPIUtility; @@ -67,7 +68,7 @@ public void start(Stage stage) throws Exception { parameters.remove("--headless"); } else { // Otherwise, run with both the core and UI modules, and show the JavaFX stage - injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule()).with(new GRIPUIModule())); + injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule()).with(new GRIPUIModule())); injector.injectMembers(this); root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);