SetCondition extends BasicCondition<T, SetCondition<T, E>> implements SetChecks<T, E, SetCondition<T, E>> { @Override public SetCondition<T, E> hasSizeBetween(int startInclusive, int endInclusive) { require(this.subject).isNotNull(); int setSize = this.subject.size(); if (!((setSize >= startInclusive && setSize <= endInclusive) || (setSize <= startInclusive && setSize >= endInclusive))) { DbcAssertionError.throwNew(new IllegalArgumentException("Expected set size to be between <" + startInclusive + "> and < " + endInclusive + "> but was <" + setSize + ">"), this.message); } return result(); } SetCondition(T subject); @Override SetCondition<T, E> isNotEmpty(); @Override SetCondition<T, E> hasSize(int size); @Override SetCondition<T, E> hasSizeBetween(int startInclusive, int endInclusive); @Override SetCondition<T, E> hasSizeGreaterThan(int minSizeExclusive); @Override SetCondition<T, E> hasSizeGreaterThanOrEqual(int minSize); @Override SetCondition<T, E> hasSizeLessThan(int maxSizeExclusive); @Override SetCondition<T, E> hasSizeLessThanOrEqual(int maxSize); @Override SetCondition<T, E> contains(E value);  }
@Test public void hasSizeBetween() throws Exception { SetCondition<Set<String>, String> condition = new SetCondition<>(this.input); condition.hasSizeBetween(2, 4); SetCondition<Set<String>, String> badCondition = new SetCondition<>(this.input); Assertions.assertThatThrownBy(() -> badCondition.hasSizeBetween(1, 2)) .isInstanceOf(DbcAssertionError.class) .hasCauseInstanceOf(IllegalArgumentException.class); }