cactoos-matchers icon indicating copy to clipboard operation
cactoos-matchers copied to clipboard

New matcher is required to detect that file exists

Open dgroup opened this issue 3 years ago • 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 avatar Dec 31 '20 13:12 dgroup

@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 avatar Jan 16 '21 10:01 victornoel

@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 avatar Jan 28 '21 20:01 dgroup

@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 avatar Mar 14 '21 18:03 victornoel

@victornoel agree, such approach is more laconic.

dgroup avatar Mar 15 '21 16:03 dgroup

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

victornoel avatar May 13 '21 19:05 victornoel