llorllale/cactoos-matchers

New matcher is required to detect that file exists

dgroup opened this issue · 5 comments

new Assertion<>(
  "... scenario name ...",
   /* some business logic which manipulates with file */,
  new Exists("target", "sub-dir1", "sub-dir2")
).affirm();

// where Found supports
public final Exists extends MatcherEnvelope<File> {
   public Exists(final String ... path) {
      this(() -> Paths.get(path).toFile());
  }
  public Exists(final Path path) {
     this(()-> path.toFile());
  )
  public Exists(final File path) {
     this(() -> path);
  }
  public Exists(final Scalar<File> path) {
     super(...);
  }

@dgroup could you update the description to make this a Matcher of Path instead of File. The constructors should only take Path and File imho, no need for Strings and for Scalar.

Also, let's name it Exists (or if you have a better idea, I'm open :)

@victornoel thanks for the idea related to Exists, but disagree with

  • removing constructor for String/Scalar (in fact we gives more options on how to build a matcher)
  • use Path instead of File, because most of the API which I'm facing returns files, not Path.

Could you please clarify more your ideas?

@dgroup sorry for the late reply.

I just realized that there was something fishy with this Matcher: if it's a Matcher<File>, then why does it also take a file in the constructor? Shouldn't it be instead:

public final Exists implements Matcher<File> {
  public Exists() { /* ... */ }
}

new Assertion<>(
  "... scenario name ...",
   /* some business logic which returns a file */,
  new Exists()
).affirm();

Or if not, then, it shouldn't be a Matcher of File but of Proc for example... Which one did you have in mind?

@victornoel agree, such approach is more laconic.

@dgroup cool, could you update the description to mirror the conclusion of this discussion?