82
82
*
83
83
* then(bulls).contains(rose, noah).doesNotContain(james);
84
84
* }</code></pre>
85
+ * Use <code>{@link #and}</code> to avoid clash with other libraries (like BDDMockito) exposing '<code>then(object)</code>'.
86
+ * You might have to ignore a warning like: <i>The static method BDDAssertions.then() should be accessed in a static way</i>.
85
87
*
88
+ *
89
+ * @author Gonzalo Müller
86
90
* @author Alex Ruiz
87
91
* @author Yvonne Wang
88
92
* @author David DIDIER
@@ -103,6 +107,48 @@ public class BDDAssertions extends Assertions {
103
107
*/
104
108
protected BDDAssertions () {}
105
109
110
+ /**
111
+ * A <code>BDDAssertions</code> which allows to blend assertions with other libraries when the name '<code>then</code>' cause clash.
112
+ * <p>
113
+ * Examples:
114
+ * <pre><code class='java'> import static org.assertj.core.api.BDDAssertions.and;
115
+ * import static org.mockito.BDDMockito.then;
116
+ * import static org.mockito.Mockito.mock;
117
+ * import static org.mockito.Mockito.times;
118
+ *
119
+ * // suppress and.then warning: The static method BDDAssertions.then() should be accessed in a static way
120
+ * {@literal @SuppressWarnings}("static-access")
121
+ * {@literal @Test}
122
+ * public void bdd_assertions_with_bdd_mockito() {
123
+ * // GIVEN
124
+ * Person person = mock(Person.class)
125
+ * // WHEN
126
+ * person.ride(bike);
127
+ * person.ride(bike);
128
+ * // THEN
129
+ * // mockito then()
130
+ * then(person).should(times(2)).ride(bike);
131
+ * // use AssertJ and.then(person) as then(person) would clash with mockito then(person)
132
+ * and.then(person.hasBike()).isTrue();
133
+ * }</code></pre>
134
+ * <p>
135
+ * Can also be used to add extra readability:
136
+ * <pre><code class='java'> import static org.assertj.core.api.BDDAssertions.and;
137
+ * import static org.assertj.core.api.BDDAssertions.then;
138
+ *
139
+ * // suppress and.then warning: The static method BDDAssertions.then() should be accessed in a static way
140
+ * {@literal @SuppressWarnings}("static-access")
141
+ * {@literal @Test}
142
+ * public void bdd_assertions_with_and_field() {
143
+ * // ...
144
+ * then(person.hasBike()).isTrue()
145
+ * and.then(bike.isNew()).isFalse();
146
+ * }</code></pre>
147
+ *
148
+ * @since 3.14.0
149
+ */
150
+ public static final BDDAssertions and = new BDDAssertions ();
151
+
106
152
/**
107
153
* Create assertion for {@link Predicate}.
108
154
*
0 commit comments