@Override public String satisfies(final Object obj) { final ReasonBuffer buf = new ReasonBuffer(); for (final Specification specification : specifications) { final String reasonNotSatisfiedIfAny = specification.satisfies(obj); buf.append(reasonNotSatisfiedIfAny); } return buf.getReason(); // may be null if all were satisfied. }
@Override public String satisfies(final Object obj) { final ReasonBuffer buf = new ReasonBuffer(); for (final Specification specification : specifications) { final String reasonNotSatisfiedIfAny = specification.satisfies(obj); buf.append(reasonNotSatisfiedIfAny); } return buf.getReason(); // may be null if all were satisfied. }
@Test public void notSatisfiedIfOneAndNotOkay() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(neverSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(not(nullValue()))); assertThat(mySpecOr.satisfies(null), is("not satisfied")); }
@Test public void notSatisfiedIfTwoAndBothAreNotOkayWithConcatenatedReason() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(neverSatisfied, neverSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(not(nullValue()))); assertThat(mySpecOr.satisfies(null), is("not satisfied; not satisfied")); }
@Test public void notSatisfiedIfUnderlyingIs() { class MySpecNot extends SpecificationNot { public MySpecNot() { super(alwaysSatisfied); } } ; final Specification mySpecOr = new MySpecNot(); assertThat(mySpecOr.satisfies(null), is(not(nullValue()))); assertThat(mySpecOr.satisfies(null), is("not satisfied")); }
@Test public void notSatisfiedIfOneAndNotOkay() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(neverSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(not(nullValue()))); assertThat(mySpecAnd.satisfies(null), is("not satisfied")); }
@Test public void notSatisfiedIfTwoAndBothAreNotOkayWithConcatenatedReason() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(neverSatisfied, neverSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(not(nullValue()))); assertThat(mySpecAnd.satisfies(null), is("not satisfied; not satisfied")); }
@Test public void notSatisfiedIfTwoAndBothAreNotOkayWithConcatenatedReason() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(neverSatisfied, neverSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(not(nullValue()))); assertThat(mySpecOr.satisfies(null), is("not satisfied; not satisfied")); }
@Test public void notSatisfiedIfUnderlyingIs() { class MySpecNot extends SpecificationNot { public MySpecNot() { super(alwaysSatisfied); } } ; final Specification mySpecOr = new MySpecNot(); assertThat(mySpecOr.satisfies(null), is(not(nullValue()))); assertThat(mySpecOr.satisfies(null), is("not satisfied")); }
@Test public void notSatisfiedIfOneAndNotOkay() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(neverSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(not(nullValue()))); assertThat(mySpecAnd.satisfies(null), is("not satisfied")); }
@Test public void notSatisfiedIfTwoAndOneIsNotOkay() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(alwaysSatisfied, neverSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(not(nullValue()))); assertThat(mySpecAnd.satisfies(null), is("not satisfied")); }
@Test public void satisfiedIfNone() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfOneAndOkay() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(alwaysSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfTwoAndBothAreOkay() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(alwaysSatisfied, alwaysSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfNone() { class MySpecOr extends SpecificationOr { public MySpecOr() { } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfTwoAndOneIsNotOkay() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(alwaysSatisfied, neverSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfOneAndOkay() { class MySpecOr extends SpecificationOr { public MySpecOr() { super(alwaysSatisfied); } } ; final Specification mySpecOr = new MySpecOr(); assertThat(mySpecOr.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfNone() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfTwoAndBothAreOkay() { class MySpecAnd extends SpecificationAnd { public MySpecAnd() { super(alwaysSatisfied, alwaysSatisfied); } } ; final Specification mySpecAnd = new MySpecAnd(); assertThat(mySpecAnd.satisfies(null), is(nullValue())); }
@Test public void satisfiedIfUnderlyingIsNot() { class MySpecNot extends SpecificationNot { public MySpecNot() { super(neverSatisfied); } } ; final Specification mySpecOr = new MySpecNot(); assertThat(mySpecOr.satisfies(null), is(nullValue())); }