Skip to content

Commit

Permalink
Even more break up of main to achieve high test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
renato committed Sep 30, 2018
1 parent c45d7ee commit 82542e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/java/ua/comparison/image/ImageComparison.java
Expand Up @@ -65,18 +65,17 @@ public Optional<File> getDestination() {
return Optional.ofNullable( destination );
}

public static void main(String[] args ) throws IOException, URISyntaxException {
Optional<ArgsParser.Arguments> arguments = new ArgsParser().parseArgs(args);
ImageComparison imgCmp;
if ( arguments.isPresent() ) {
imgCmp = create( arguments.get() );
} else {
imgCmp = createDefault();
}
public static void main( String[] args ) throws IOException, URISyntaxException {
ImageComparison imgCmp = create( args );
BufferedImage result = imgCmp.compareImages();
handleResult( imgCmp, ( file ) -> saveImage( file, result ), () -> createGUI( result ) );
}

static ImageComparison create( String... args ) throws IOException, URISyntaxException {
Optional<ArgsParser.Arguments> arguments = new ArgsParser().parseArgs(args);
return arguments.isPresent() ? create( arguments.get() ) : createDefault();
}

static ImageComparison createDefault() throws IOException, URISyntaxException {
return new ImageComparison(
readImageFromResources("image1.png" ),
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/ua/comparison/image/ImageComparisonUnitTest.java
Expand Up @@ -59,6 +59,17 @@ public void testCreateDefault() throws IOException, URISyntaxException {
assertFalse(comparison.getDestination().isPresent());
}

@Test
public void testCreateWithTwoArgs() throws IOException, URISyntaxException {
File image1 = new File( ImageComparison.class.getClassLoader().getResource ( "image1.png" ).toURI().getPath() );
File image2 = new File( ImageComparison.class.getClassLoader().getResource ( "image2.png" ).toURI().getPath() );
ImageComparison comparison = ImageComparison.create(image1.getAbsolutePath(), image2.getAbsolutePath());

assertImagesEqual(readImageFromResources("image1.png" ), comparison.getImage1());
assertImagesEqual(readImageFromResources("image2.png" ), comparison.getImage2());
assertFalse(comparison.getDestination().isPresent());
}

@Test
public void testCreateWithTwoImagesAsArgs() throws IOException, URISyntaxException {
File image1 = new File( ImageComparison.class.getClassLoader().getResource ( "image1.png" ).toURI().getPath() );
Expand Down

0 comments on commit 82542e9

Please sign in to comment.