Assertj-core: doesNotContainSequence

Created on 2 Apr 2017  路  3Comments  路  Source: assertj/assertj-core

Summary

There is AbstractIterableAssert.containsSequence, but not the opposite to verify it doesn't contain sequence starting from any index.

Currently I'm using:

assertThat(myList).isNot(Condition(Predicate { it.containsSubList(mySubList) }, "containing sequence"))

where containsSubList is a Kotlin extension method I also had to define:

fun <T> List<T>.containsSubList(other: List<T>)
        = (0..size - other.size).any { subList(it, it + other.size) == other }

I also suggest to create versions of both containsSequence and doesNotContainSequence that accepts List in addition to current vararg ELEMENT.

Example

assertThat(myListOrIterable).doesNotContainSequence(mySubListOrIterable)
assertThat(myListOrIterable).doesNotContainSequence(element1, element2, element3)
assertThat(myListOrIterable).containsSequence(mySubListOrIterable)

Java 8 specific ?

NO

  • YES : create Pull Request from the master branch
  • NO : create Pull Request from the 2.x branch
new feature

Most helpful comment

I've done a pull request for the "support Lists in the existing methods" half of your request.

I'll add the doesNotContainSequence methods separately.

All 3 comments

I've done a pull request for the "support Lists in the existing methods" half of your request.

I'll add the doesNotContainSequence methods separately.

I've added doesNotContainSequence but it still needs doesNotContainSubSequence.

Should all be there now.

Was this page helpful?
0 / 5 - 0 ratings