Skip to content

Commit 6861563

Browse files
committed
Merge pull request #567 from JLLeitschuh/chore/testsWithMockFrameGrabberFactory
Tests now use MockFrameGrabberFactory so tests wont hang
2 parents f6ec082 + 8f82ab3 commit 6861563

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

core/src/main/java/edu/wpi/grip/core/GRIPCoreModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
109109

110110
bind(ConnectionValidator.class).to(Pipeline.class);
111111
bind(Source.SourceFactory.class).to(Source.SourceFactoryImpl.class);
112-
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
113112
install(new FactoryModuleBuilder()
114113
.implement(CameraSource.class, CameraSource.class)
115114
.build(CameraSource.Factory.class));

core/src/main/java/edu/wpi/grip/core/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import edu.wpi.grip.core.operations.Operations;
1010
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
1111
import edu.wpi.grip.core.serialization.Project;
12+
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
1213
import edu.wpi.grip.generated.CVOperations;
1314

1415
import javax.inject.Inject;
@@ -30,7 +31,7 @@ public class Main {
3031

3132
@SuppressWarnings("PMD.SystemPrintln")
3233
public static void main(String[] args) throws IOException, InterruptedException {
33-
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule());
34+
final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule());
3435
injector.getInstance(Main.class).start(args);
3536
}
3637

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package edu.wpi.grip.core.sources;
2+
3+
import com.google.inject.AbstractModule;
4+
5+
/**
6+
* Adds bindings for hardware that is required by {@link edu.wpi.grip.core.Source Sources}
7+
*/
8+
public class GRIPSourcesHardwareModule extends AbstractModule {
9+
@Override
10+
protected void configure() {
11+
bind(CameraSource.FrameGrabberFactory.class).to(CameraSource.FrameGrabberFactoryImpl.class);
12+
}
13+
}

core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void tearDown() {
7676
}
7777

7878
@Test
79-
public void testFoo() throws Exception {
79+
public void testCompatibilityIsMaintained() throws Exception {
8080
assertEquals("The expected number of steps were not found", 50, pipeline.getSteps().size());
8181
assertEquals("The expected number of sources were not found", 2, pipeline.getSources().size());
8282
pipeline.clear();

core/src/test/java/edu/wpi/grip/core/sources/MockCameraSource.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,19 @@
22

33
import com.google.common.eventbus.EventBus;
44
import edu.wpi.grip.core.util.MockExceptionWitness;
5-
import org.bytedeco.javacv.FrameGrabber;
65

76
import java.io.IOException;
8-
import java.net.MalformedURLException;
97

108
public class MockCameraSource extends CameraSource {
119

1210
private boolean started = false;
1311

14-
static class FrameGrabberFactory implements CameraSource.FrameGrabberFactory {
15-
16-
@Override
17-
public FrameGrabber create(int deviceNumber) {
18-
return null;
19-
}
20-
21-
@Override
22-
public FrameGrabber create(String addressProperty) throws MalformedURLException {
23-
return null;
24-
}
25-
}
26-
2712
public MockCameraSource(EventBus eventBus, String address) throws IOException {
28-
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
13+
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, address);
2914
}
3015

3116
public MockCameraSource(EventBus eventBus, int deviceNumber) throws IOException {
32-
super(eventBus, new FrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
17+
super(eventBus, new MockFrameGrabberFactory(), MockExceptionWitness.MOCK_FACTORY, deviceNumber);
3318
}
3419

3520
@Override
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package edu.wpi.grip.core.sources;
2+
3+
import org.bytedeco.javacv.FrameGrabber;
4+
5+
import java.net.MalformedURLException;
6+
7+
/**
8+
* Frame Grabber Factory that mocks out the frame grabber that it returns
9+
*/
10+
public class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory {
11+
12+
@Override
13+
public FrameGrabber create(int deviceNumber) {
14+
return new SimpleMockFrameGrabber();
15+
}
16+
17+
@Override
18+
public FrameGrabber create(String addressProperty) throws MalformedURLException {
19+
return new SimpleMockFrameGrabber();
20+
}
21+
}

core/src/test/java/edu/wpi/grip/util/GRIPCoreTestModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import com.google.common.eventbus.SubscriberExceptionContext;
55
import edu.wpi.grip.core.GRIPCoreModule;
6+
import edu.wpi.grip.core.sources.CameraSource;
7+
import edu.wpi.grip.core.sources.MockFrameGrabberFactory;
68

79
import java.util.ArrayList;
810
import java.util.List;
@@ -68,6 +70,7 @@ public void tearDown() {
6870
@Override
6971
protected void configure() {
7072
assert setUp : "The GRIPCoreTestModule handler was not set up. Call 'setUp' before passing the injector";
73+
bind(CameraSource.FrameGrabberFactory.class).to(MockFrameGrabberFactory.class);
7174
super.configure();
7275
}
7376

ui/src/main/java/edu/wpi/grip/ui/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.grip.core.operations.Operations;
1414
import edu.wpi.grip.core.operations.network.GRIPNetworkModule;
1515
import edu.wpi.grip.core.serialization.Project;
16+
import edu.wpi.grip.core.sources.GRIPSourcesHardwareModule;
1617
import edu.wpi.grip.core.util.SafeShutdown;
1718
import edu.wpi.grip.generated.CVOperations;
1819
import edu.wpi.grip.ui.util.DPIUtility;
@@ -67,7 +68,7 @@ public void start(Stage stage) throws Exception {
6768
parameters.remove("--headless");
6869
} else {
6970
// Otherwise, run with both the core and UI modules, and show the JavaFX stage
70-
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule()).with(new GRIPUIModule()));
71+
injector = Guice.createInjector(Modules.override(new GRIPCoreModule(), new GRIPNetworkModule(), new GRIPSourcesHardwareModule()).with(new GRIPUIModule()));
7172
injector.injectMembers(this);
7273

7374
root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);

0 commit comments

Comments
 (0)