assertj-assertions-generator icon indicating copy to clipboard operation
assertj-assertions-generator copied to clipboard

The generator is a little too greedy with Iterable of Path and make tests fails

Open glhez opened this issue 8 years ago • 0 comments

With 2.1.0 version, the generator is too greedy when encountering a class implementing an java.lang.Iterable. It should ignore it unless the type extends java.util.Collection (where that make sense) or explicitly a java.lang.Iterable (where it is harder to tell it makes sense).

Sample classes: assertj-foo.zip

The test (FooTest) will fail because the usage of hasPath is NOT the same than using an iterable: we want to test an equals rather than a collection predicate. Here the exception: java.lang.AssertionError: Expecting: <foobar\a>to contain: <[foobar\a]>but could not find: <[foobar\a]>

A working alternative is to convert the Path into a List extracting the Iterable content, but that is wrong by all means:

  • first, the default semantic is not good (the default = search for subsequence in any order)
  • second, as an user, I want to test the path using equals (and that is what the generator produce if I have a class not implementing java.lang.Iterable):
final List<Path> paths = new ArrayList<>();
test.forEach(paths::add); // says ["foobar", "A"]
assertThat(foo).hasPath(paths);

glhez avatar Oct 11 '17 22:10 glhez