Skip to content

Commit

Permalink
Issue #3 - Easy configuration of source of approval
Browse files Browse the repository at this point in the history
Simplify SourcesOfApproval by making them mutable and add extension
  • Loading branch information
dmcg committed Jul 19, 2013
1 parent 1245089 commit 6385041
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
13 changes: 0 additions & 13 deletions src/main/java/org/rococoa/okeydoke/Sources.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,8 @@ public static SourceOfApproval<File> in(File directory) {
return new FileSystemSourceOfApproval(directory);
}

public static SourceOfApproval<File> in(String srcRoot, Package thePackage) {
return in(new File(srcRoot), thePackage);
}

public static SourceOfApproval<File> in(File srcRoot, Package thePackage) {
return new FileSystemSourceOfApproval(srcRoot, thePackage);
}

public static SourceOfApproval<File> in(String srcRoot, Package thePackage, String actualDir) {
return in(new File(srcRoot), thePackage, new File(actualDir));
}

public static SourceOfApproval<File> in(File srcRoot, Package thePackage, File actualDir) {
return new FileSystemSourceOfApproval(srcRoot, thePackage, actualDir);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,19 @@

public class FileSystemSourceOfApproval implements SourceOfApproval<File> {

private final File approvedDir;
private final File actualDir;
private File approvedDir;
private File actualDir;
private String typeExtension = "";

public FileSystemSourceOfApproval(File directory) {
this(directory, directory);
this.approvedDir = directory;
this.actualDir = directory;
}

public FileSystemSourceOfApproval(File root, Package aPackage) {
this(dirForPackage(root, aPackage));
}

public FileSystemSourceOfApproval(File srcRoot, Package thePackage, File actualDir) {
this(dirForPackage(srcRoot, thePackage), actualDir);
}

public FileSystemSourceOfApproval(File approvedDir, File actualDir) {
this.approvedDir = approvedDir;
this.actualDir = actualDir;
}

public static File dirForPackage(File root, Package aPackage) {
return new File(root, aPackage.getName().replaceAll("\\.", "/"));
}
Expand All @@ -47,12 +40,12 @@ public OutputStream outputForActual(String testname) throws IOException {

@Override
public InputStream inputOrNullForApproved(String testname) throws FileNotFoundException {
return InputStreamOrNullFor(approvedFor(testname));
return inputStreamOrNullFor(approvedFor(testname));
}

@Override
public InputStream inputOrNullForActual(String testname) throws IOException {
return InputStreamOrNullFor(actualFor(testname));
return inputStreamOrNullFor(actualFor(testname));
}

@Override
Expand All @@ -65,24 +58,38 @@ public File approvedFor(String testname) {
return fileFor(approvedDir, testname, approvedExtension());
}

private String approvedExtension() {
return ".approved";
protected String approvedExtension() {
return ".approved" + typeExtension();
}

@Override
public File actualFor(String testname) {
return fileFor(actualDir, testname, actualExtension());
}

private String actualExtension() {
return ".actual";
public FileSystemSourceOfApproval withActualDirectory(File actualDirectory) {
this.actualDir = actualDirectory;
return this;
}

public FileSystemSourceOfApproval withTypeExtension(String typeExtension) {
this.typeExtension = typeExtension;
return this;
}

protected String actualExtension() {
return ".actual" + typeExtension();
}

protected String typeExtension() {
return typeExtension;
}

private File fileFor(File dir, String testname, String suffix) {
return new File(dir, testname + suffix);
}

private InputStream InputStreamOrNullFor(File file) throws FileNotFoundException {
private InputStream inputStreamOrNullFor(File file) throws FileNotFoundException {
return !(file.exists() && file.isFile()) ?
null : new BufferedInputStream(new FileInputStream(file));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public StreamingFileSystemSourceOfApproval(File directory) {
super(directory);
}

public StreamingFileSystemSourceOfApproval(File srcRoot, Package thePackage, File actualDir) {
super(srcRoot, thePackage, actualDir);
}

public StreamingFileSystemSourceOfApproval(File approvedDir, File actualDir) {
super(approvedDir, actualDir);
}

public StreamingFileSystemSourceOfApproval(File root, Package thePackage) {
super(root, thePackage);
}
Expand Down

0 comments on commit 6385041

Please sign in to comment.