ImageFileSource extends Source { @Override public void initialize() throws IOException { this.loadImage(path); } @AssistedInject  ImageFileSource(
      final OutputSocket.Factory outputSocketFactory,
      final ExceptionWitness.Factory exceptionWitnessFactory,
      @Assisted final File file); @AssistedInject  ImageFileSource(
      final OutputSocket.Factory outputSocketFactory,
      final ExceptionWitness.Factory exceptionWitnessFactory,
      @Assisted final Properties properties); private  ImageFileSource(
      final OutputSocket.Factory outputSocketFactory,
      final ExceptionWitness.Factory exceptionWitnessFactory,
      final String path); @Override void initialize(); @Override String getName(); @Override List<OutputSocket> createOutputSockets(); @Override Properties getProperties();  }
@Test public void testLoadImageToMat() throws IOException { final ImageFileSource fileSource = new ImageFileSource(osf, origin -> null, this .imageFile.file); fileSource.initialize(); OutputSocket<MatWrapper> outputSocket = fileSource.getOutputSockets().get(0); assertTrue("The output socket's value was empty.", outputSocket.getValue().isPresent()); imageFile.assertSameImage(outputSocket.getValue().get()); }
@Test(expected = IOException.class) public void testReadInTextFile() throws IOException { final ImageFileSource fileSource = new ImageFileSource(osf, origin -> null, this .textFile); fileSource.initialize(); OutputSocket<MatWrapper> outputSocket = fileSource.getOutputSockets().get(0); assertTrue("No matrix should have been returned.", outputSocket.getValue().get().empty()); }
@Test(expected = IOException.class) public void testReadInFileWithoutExtension() throws MalformedURLException, IOException { final File testFile = new File("temp" + File.separator + "fdkajdl3eaf"); final ImageFileSource fileSource = new ImageFileSource(osf, origin -> null, testFile); fileSource.initialize(); fail("initialize() should have thrown an IOException"); }
@Test public void testCallingInitializeAfterGetOutputSocketUpdatesOutputSocket() throws IOException { final ImageFileSource source = new ImageFileSource(osf, origin -> null, this .imageFile.file); final OutputSocket<MatWrapper> imageSource = source.getOutputSockets().get(0); assertTrue("The value should not be present if the source hasn't been initialized", imageSource.getValue().get().empty()); source.initialize(); assertFalse("The value should now be present since the source has been initialized", imageSource.getValue().get().empty()); }