Skip to content

Commit 70bd24f

Browse files
committed
Fixes tests from rebase
1 parent c434d06 commit 70bd24f

4 files changed

Lines changed: 41 additions & 22 deletions

File tree

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ProjectTest {
3030

3131
private Connection.Factory<Number> connectionFactory;
3232
private ImageFileSource.Factory imageSourceFactory;
33+
private Step.Factory stepFactory;
3334
private EventBus eventBus;
3435
private Pipeline pipeline;
3536
private Project project;
@@ -47,6 +48,7 @@ public void setUp() throws Exception {
4748
eventBus = injector.getInstance(EventBus.class);
4849
pipeline = injector.getInstance(Pipeline.class);
4950
project = injector.getInstance(Project.class);
51+
stepFactory = injector.getInstance(Step.Factory.class);
5052

5153

5254
additionOperation = new AdditionOperation();
@@ -84,9 +86,9 @@ public void testSerializeEmptyPipeline() throws Exception {
8486

8587
@Test
8688
public void testSerializePipelineWithSteps() throws Exception {
87-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, additionOperation)));
88-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, pythonAdditionOperationFromSource)));
89-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, pythonAdditionOperationFromURL)));
89+
eventBus.post(new StepAddedEvent(stepFactory.create(additionOperation)));
90+
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromSource)));
91+
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromURL)));
9092

9193
serializeAndDeserialize();
9294

@@ -99,12 +101,12 @@ public void testSerializePipelineWithSteps() throws Exception {
99101
@Test
100102
@SuppressWarnings("unchecked")
101103
public void testSerializePipelineWithStepsAndConnections() throws Exception {
102-
Step step1 = new MockStep(eventBus, pythonAdditionOperationFromSource);
104+
Step step1 = stepFactory.create(pythonAdditionOperationFromSource);
103105
InputSocket<Number> a1 = (InputSocket<Number>) step1.getInputSockets()[0];
104106
InputSocket<Number> b1 = (InputSocket<Number>) step1.getInputSockets()[1];
105107
OutputSocket<Number> sum1 = (OutputSocket<Number>) step1.getOutputSockets()[0];
106108

107-
Step step2 = new MockStep(eventBus, pythonAdditionOperationFromURL);
109+
Step step2 = stepFactory.create(pythonAdditionOperationFromURL);
108110
InputSocket<Number> a2 = (InputSocket<Number>) step2.getInputSockets()[0];
109111
InputSocket<Number> b2 = (InputSocket<Number>) step2.getInputSockets()[1];
110112
OutputSocket<Number> sum2 = (OutputSocket<Number>) step2.getOutputSockets()[0];
@@ -128,7 +130,7 @@ public void testSerializePipelineWithStepsAndConnections() throws Exception {
128130
@Test
129131
@SuppressWarnings("unchecked")
130132
public void testPerformSerializedStep() throws Exception {
131-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, additionOperation)));
133+
eventBus.post(new StepAddedEvent(stepFactory.create(additionOperation)));
132134
serializeAndDeserialize();
133135

134136
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -143,7 +145,7 @@ public void testPerformSerializedStep() throws Exception {
143145
@Test
144146
@SuppressWarnings("unchecked")
145147
public void testPerformSerializedPythonStepFromURL() throws Exception {
146-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, pythonAdditionOperationFromURL)));
148+
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromURL)));
147149
serializeAndDeserialize();
148150

149151
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -158,7 +160,7 @@ public void testPerformSerializedPythonStepFromURL() throws Exception {
158160
@Test
159161
@SuppressWarnings("unchecked")
160162
public void testPerformSerializedPythonStepFromSource() throws Exception {
161-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, pythonAdditionOperationFromSource)));
163+
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromSource)));
162164
serializeAndDeserialize();
163165

164166
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -173,8 +175,8 @@ public void testPerformSerializedPythonStepFromSource() throws Exception {
173175
@Test
174176
@SuppressWarnings("unchecked")
175177
public void testPerformSerializedPipeline() throws Exception {
176-
Step step1 = new MockStep(eventBus, pythonAdditionOperationFromURL);
177-
Step step2 = new MockStep(eventBus, pythonAdditionOperationFromSource);
178+
Step step1 = stepFactory.create(pythonAdditionOperationFromURL);
179+
Step step2 = stepFactory.create(pythonAdditionOperationFromSource);
178180
eventBus.post(new StepAddedEvent(step1));
179181
eventBus.post(new StepAddedEvent(step2));
180182
eventBus.post(new ConnectionAddedEvent(
@@ -198,7 +200,7 @@ public void testPerformSerializedPipeline() throws Exception {
198200
@Test
199201
@SuppressWarnings("unchecked")
200202
public void testPerformSerializedPipelineWithMats() throws Exception {
201-
eventBus.post(new StepAddedEvent(new MockStep(eventBus, opencvAddOperation)));
203+
eventBus.post(new StepAddedEvent(stepFactory.create(opencvAddOperation)));
202204
serializeAndDeserialize();
203205

204206
Step step1 = pipeline.getSteps().get(0);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public void setUp() throws IOException {
2828
sourceWithIndexSet = new MultiImageFileSource(
2929
new EventBus(),
3030
Arrays.asList(imageFile.file, gompeiJpegFile.file), 1);
31+
source.load();
32+
sourceWithIndexSet.load();
3133
}
3234

3335
@Test(expected = IOException.class)
3436
public void createMultiImageFileSourceWithTextFile() throws IOException {
35-
new MultiImageFileSource(new EventBus(), Arrays.asList(imageFile.file, gompeiJpegFile.file, textFile));
37+
new MultiImageFileSource(new EventBus(), Arrays.asList(imageFile.file, gompeiJpegFile.file, textFile)).load();
3638
}
3739

3840
@Test
@@ -59,6 +61,7 @@ public void testConstructedWithIndex() {
5961
public void testLoadFromProperties() throws Exception {
6062
final Properties properties = sourceWithIndexSet.getProperties();
6163
final MultiImageFileSource newSource = new MultiImageFileSource(new EventBus(), properties);
64+
newSource.load();
6265
OutputSocket<Mat> outputSocket = newSource.getOutputSockets()[0];
6366
gompeiJpegFile.assertSameImage(outputSocket.getValue().get());
6467
}

ui/src/main/java/edu/wpi/grip/ui/preview/PreviewsController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class PreviewsController {
3737
private PipelineController pipelineController;
3838
@Inject
3939
private Pipeline pipeline;
40+
@Inject
41+
private SocketPreviewViewFactory previewViewFactory;
4042

4143
private final List<OutputSocket<?>> previewedSockets = new ArrayList<>();
4244

@@ -126,7 +128,7 @@ public synchronized void onPreviewOrderChanged(StepMovedEvent event) {
126128
newLocation = this.previewedSockets.size();//Make it so it will be added to the end of the list of previews
127129
}
128130
this.previewedSockets.add(newLocation, current);//...add it to the correct location in the list of previews open
129-
this.previewBox.getChildren().add(newLocation, SocketPreviewViewFactory.createPreviewView(current));//...and display it in the correct location in the list of previews open
131+
this.previewBox.getChildren().add(newLocation, previewViewFactory.create(current));//...and display it in the correct location in the list of previews open
130132
}
131133
});
132134
}
@@ -150,15 +152,15 @@ public synchronized void onSocketPreviewChanged(SocketPreviewChangedEvent event)
150152
int indexInPreviews = getIndexInPreviewsOfAStepSocket(socket);
151153

152154
this.previewedSockets.add(indexInPreviews, socket);//...use this index to add it to the correct location in the list of previews open
153-
this.previewBox.getChildren().add(indexInPreviews, SocketPreviewViewFactory.createPreviewView(socket));//...and display it in the correct location in the list of previews open in the gui
155+
this.previewBox.getChildren().add(indexInPreviews, previewViewFactory.create(socket));//...and display it in the correct location in the list of previews open in the gui
154156

155157
} else {//This is a socket associated with a source and not a pipeline step...
156158

157159
//Find the appropriate index to add this preview with.
158160
int indexInSourcePreviews = getIndexInPreviewsOfASourceSocket(socket);
159161

160162
this.previewedSockets.add(indexInSourcePreviews, socket);//Add the preview to the appropriate place in the list of previewed sockets
161-
this.previewBox.getChildren().add(indexInSourcePreviews, SocketPreviewViewFactory.createPreviewView(socket));//Display the preview in the appropriate place
163+
this.previewBox.getChildren().add(indexInSourcePreviews, previewViewFactory.create(socket));//Display the preview in the appropriate place
162164
}
163165
}
164166
} else {//The socket was already previewed, so the user must be requesting to not show this preview (remove both it and the corresponding control)
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package edu.wpi.grip.ui.preview;
22

3+
import com.google.common.eventbus.EventBus;
4+
import com.google.inject.Inject;
5+
import com.google.inject.Singleton;
36
import edu.wpi.grip.core.OutputSocket;
47
import edu.wpi.grip.core.operations.composite.BlobsReport;
58
import edu.wpi.grip.core.operations.composite.ContoursReport;
@@ -12,27 +15,36 @@
1215
/**
1316
* Factory for constructing {@link SocketPreviewView}s
1417
*/
18+
@Singleton
1519
public class SocketPreviewViewFactory {
1620

21+
@Inject
22+
private EventBus eventBus;
23+
24+
SocketPreviewViewFactory() {/* no-op */}
25+
1726
/**
1827
* Create an instance of {@link SocketPreviewView} appropriate for the given socket. Sockets of different types
1928
* (like numbers, arrays, images, etc...) are rendered in different ways, and the role of this class is to figure
2029
* out what control to use to render a given socket.
2130
*/
2231
@SuppressWarnings("unchecked")
23-
public static <T> SocketPreviewView<T> createPreviewView(OutputSocket<T> socket) {
32+
public <T> SocketPreviewView<T> create(OutputSocket<T> socket) {
33+
final SocketPreviewView<T> previewView;
2434
if (socket.getSocketHint().getType() == Mat.class) {
25-
return (SocketPreviewView) new ImageSocketPreviewView((OutputSocket<Mat>) socket);
35+
previewView = (SocketPreviewView) new ImageSocketPreviewView((OutputSocket<Mat>) socket);
2636
} else if (socket.getSocketHint().getType() == Point.class || socket.getSocketHint().getType() == Size.class) {
27-
return (SocketPreviewView) new PointSizeSocketPreviewView((OutputSocket<IntPointer>) socket);
37+
previewView = (SocketPreviewView) new PointSizeSocketPreviewView((OutputSocket<IntPointer>) socket);
2838
} else if (socket.getSocketHint().getType() == ContoursReport.class) {
29-
return (SocketPreviewView) new ContoursSocketPreviewView((OutputSocket<ContoursReport>) socket);
39+
previewView = (SocketPreviewView) new ContoursSocketPreviewView((OutputSocket<ContoursReport>) socket);
3040
} else if (socket.getSocketHint().getType() == LinesReport.class) {
31-
return (SocketPreviewView) new LinesSocketPreviewView((OutputSocket<LinesReport>) socket);
41+
previewView = (SocketPreviewView) new LinesSocketPreviewView((OutputSocket<LinesReport>) socket);
3242
} else if (socket.getSocketHint().getType() == BlobsReport.class) {
33-
return (SocketPreviewView) new BlobsSocketPreviewView((OutputSocket<BlobsReport>) socket);
43+
previewView = (SocketPreviewView) new BlobsSocketPreviewView((OutputSocket<BlobsReport>) socket);
3444
} else {
35-
return new TextAreaSocketPreviewView<>(socket);
45+
previewView = new TextAreaSocketPreviewView<>(socket);
3646
}
47+
eventBus.register(previewView);
48+
return previewView;
3749
}
3850
}

0 commit comments

Comments
 (0)