Skip to content

Commit 345acc7

Browse files
committed
Simplify test setup by simplifying the Multimap assert.
Since there is no different between the three different multimap assert types we can collapse them into one assertion type.
1 parent 327cd23 commit 345acc7

File tree

101 files changed

+1504
-5299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1504
-5299
lines changed

src/main/java/org/assertj/eclipse/collections/api/Assertions.java

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
package org.assertj.eclipse.collections.api;
1414

1515
import org.assertj.core.util.CheckReturnValue;
16-
import org.assertj.eclipse.collections.api.multimap.bag.BagMultimapAssert;
17-
import org.assertj.eclipse.collections.api.multimap.list.ListMultimapAssert;
18-
import org.assertj.eclipse.collections.api.multimap.set.SetMultimapAssert;
19-
import org.eclipse.collections.api.multimap.bag.BagMultimap;
20-
import org.eclipse.collections.api.multimap.list.ListMultimap;
21-
import org.eclipse.collections.api.multimap.set.SetMultimap;
16+
import org.assertj.eclipse.collections.api.multimap.MultimapAssert;
17+
import org.eclipse.collections.api.multimap.Multimap;
2218

2319
/**
2420
* Entry point for assertion methods for the Eclipse Collections library. Each method in this class is a static factory
@@ -34,38 +30,14 @@ protected Assertions() {
3430
}
3531

3632
/**
37-
* Creates a new instance of {@link BagMultimapAssert}.
33+
* Creates a new instance of {@link MultimapAssert}.
3834
*
3935
* @param actual the actual value.
4036
* @return the created assertion object.
4137
* @param <KEY> The type of keys in the BagMultimap
4238
* @param <VALUE> The type of values in the BagMultimap
4339
*/
44-
public static <KEY, VALUE> BagMultimapAssert<KEY, VALUE> assertThat(BagMultimap<KEY, VALUE> actual) {
45-
return BagMultimapAssert.assertThat(actual);
46-
}
47-
48-
/**
49-
* Creates a new instance of {@link ListMultimapAssert}.
50-
*
51-
* @param actual the actual value.
52-
* @return the created assertion object.
53-
* @param <KEY> The type of keys in the ListMultimap
54-
* @param <VALUE> The type of values in the ListMultimap
55-
*/
56-
public static <KEY, VALUE> ListMultimapAssert<KEY, VALUE> assertThat(ListMultimap<KEY, VALUE> actual) {
57-
return ListMultimapAssert.assertThat(actual);
58-
}
59-
60-
/**
61-
* Creates a new instance of {@link SetMultimapAssert}.
62-
*
63-
* @param actual the actual value.
64-
* @return the created assertion object.
65-
* @param <KEY> The type of keys in the SetMultimap
66-
* @param <VALUE> The type of values in the SetMultimap
67-
*/
68-
public static <KEY, VALUE> SetMultimapAssert<KEY, VALUE> assertThat(SetMultimap<KEY, VALUE> actual) {
69-
return SetMultimapAssert.assertThat(actual);
40+
public static <KEY, VALUE> MultimapAssert<KEY, VALUE> assertThat(Multimap<KEY, VALUE> actual) {
41+
return new MultimapAssert<>(actual);
7042
}
7143
}

src/main/java/org/assertj/eclipse/collections/api/BDDAssertions.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
package org.assertj.eclipse.collections.api;
1414

1515
import org.assertj.core.util.CheckReturnValue;
16-
import org.assertj.eclipse.collections.api.multimap.bag.BagMultimapAssert;
17-
import org.assertj.eclipse.collections.api.multimap.list.ListMultimapAssert;
18-
import org.assertj.eclipse.collections.api.multimap.set.SetMultimapAssert;
19-
import org.eclipse.collections.api.multimap.bag.BagMultimap;
20-
import org.eclipse.collections.api.multimap.list.ListMultimap;
21-
import org.eclipse.collections.api.multimap.set.SetMultimap;
16+
import org.assertj.eclipse.collections.api.multimap.MultimapAssert;
17+
import org.eclipse.collections.api.multimap.Multimap;
2218

2319
/**
2420
* Behavior-driven development style entry point for assertion methods for the Eclipse Collections library. Each method
@@ -34,38 +30,14 @@ protected BDDAssertions() {
3430
}
3531

3632
/**
37-
* Creates a new instance of {@link BagMultimapAssert}.
33+
* Creates a new instance of {@link MultimapAssert}.
3834
*
3935
* @param actual the actual value.
4036
* @return the created assertion object.
4137
* @param <KEY> The type of keys in the BagMultimap
4238
* @param <VALUE> The type of values in the BagMultimap
4339
*/
44-
public static <KEY, VALUE> BagMultimapAssert<KEY, VALUE> then(BagMultimap<KEY, VALUE> actual) {
45-
return assertThat(actual);
46-
}
47-
48-
/**
49-
* Creates a new instance of {@link ListMultimapAssert}.
50-
*
51-
* @param actual the actual value.
52-
* @return the created assertion object.
53-
* @param <KEY> The type of keys in the ListMultimap
54-
* @param <VALUE> The type of values in the ListMultimap
55-
*/
56-
public static <KEY, VALUE> ListMultimapAssert<KEY, VALUE> then(ListMultimap<KEY, VALUE> actual) {
57-
return assertThat(actual);
58-
}
59-
60-
/**
61-
* Creates a new instance of {@link SetMultimapAssert}.
62-
*
63-
* @param actual the actual value.
64-
* @return the created assertion object.
65-
* @param <KEY> The type of keys in the SetMultimap
66-
* @param <VALUE> The type of values in the SetMultimap
67-
*/
68-
public static <KEY, VALUE> SetMultimapAssert<KEY, VALUE> then(SetMultimap<KEY, VALUE> actual) {
40+
public static <KEY, VALUE> MultimapAssert<KEY, VALUE> then(Multimap<KEY, VALUE> actual) {
6941
return assertThat(actual);
7042
}
7143
}

src/main/java/org/assertj/eclipse/collections/api/EclipseCollectionsSoftAssertionsProvider.java

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,24 @@
1414

1515
import org.assertj.core.api.SoftAssertionsProvider;
1616
import org.assertj.core.util.CheckReturnValue;
17-
import org.assertj.eclipse.collections.api.multimap.bag.BagMultimapAssert;
18-
import org.assertj.eclipse.collections.api.multimap.list.ListMultimapAssert;
19-
import org.assertj.eclipse.collections.api.multimap.set.SetMultimapAssert;
20-
import org.eclipse.collections.api.multimap.bag.BagMultimap;
21-
import org.eclipse.collections.api.multimap.list.ListMultimap;
22-
import org.eclipse.collections.api.multimap.set.SetMultimap;
17+
import org.assertj.eclipse.collections.api.multimap.MultimapAssert;
18+
import org.eclipse.collections.api.multimap.Multimap;
2319

2420
/**
2521
* Soft assertions implementations for Eclipse Collections types.
2622
*/
2723
@CheckReturnValue
2824
public interface EclipseCollectionsSoftAssertionsProvider extends SoftAssertionsProvider {
2925
/**
30-
* Creates a new, proxied instance of a {@link BagMultimapAssert}
26+
* Creates a new, proxied instance of a {@link MultimapAssert}
3127
*
3228
* @param actual the path
3329
* @return the created assertion object
3430
* @param <KEY> The type of keys in the actual BagMultimap
3531
* @param <VALUE> The type of values in the actual BagMultimap
3632
*/
3733
@SuppressWarnings("unchecked")
38-
default <KEY, VALUE> BagMultimapAssert<KEY, VALUE> assertThat(BagMultimap<KEY, VALUE> actual) {
39-
return this.proxy(BagMultimapAssert.class, BagMultimap.class, actual);
40-
}
41-
42-
/**
43-
* Creates a new, proxied instance of a {@link ListMultimapAssert}
44-
*
45-
* @param actual the path
46-
* @return the created assertion object
47-
* @param <KEY> The type of keys in the actual ListMultimap
48-
* @param <VALUE> The type of values in the actual ListMultimap
49-
*/
50-
@SuppressWarnings("unchecked")
51-
default <KEY, VALUE> ListMultimapAssert<KEY, VALUE> assertThat(ListMultimap<KEY, VALUE> actual) {
52-
return this.proxy(ListMultimapAssert.class, ListMultimap.class, actual);
53-
}
54-
55-
/**
56-
* Creates a new, proxied instance of a {@link SetMultimapAssert}
57-
*
58-
* @param actual the path
59-
* @return the created assertion object
60-
* @param <KEY> The type of keys in the actual SetMultimap
61-
* @param <VALUE> The type of values in the actual SetMultimap
62-
*/
63-
@SuppressWarnings("unchecked")
64-
default <KEY, VALUE> SetMultimapAssert<KEY, VALUE> assertThat(SetMultimap<KEY, VALUE> actual) {
65-
return this.proxy(SetMultimapAssert.class, SetMultimap.class, actual);
34+
default <KEY, VALUE> MultimapAssert<KEY, VALUE> assertThat(Multimap<KEY, VALUE> actual) {
35+
return this.proxy(MultimapAssert.class, Multimap.class, actual);
6636
}
6737
}

src/main/java/org/assertj/eclipse/collections/api/multimap/AbstractMultimapAssert.java renamed to src/main/java/org/assertj/eclipse/collections/api/multimap/MultimapAssert.java

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
import java.util.Map;
3636

37-
import org.assertj.core.api.AbstractObjectAssert;
37+
import org.assertj.core.api.AbstractAssert;
3838
import org.assertj.core.api.Condition;
3939
import org.assertj.core.error.GroupTypeDescription;
4040
import org.eclipse.collections.api.RichIterable;
@@ -48,21 +48,18 @@
4848
/**
4949
* Base class for all implementations of assertions for {@link Multimap}.
5050
*
51-
* @param <SELF> the "self" type of this assertion class.
52-
* @param <ACTUAL> the type of the "actual" value.
53-
* @param <KEY> the type of keys in the Multimap.
54-
* @param <VALUE> the type of values in the Multimap.
51+
* @param <KEY> the type of keys in the Multimap.
52+
* @param <VALUE> the type of values in the Multimap.
5553
*/
56-
public abstract class AbstractMultimapAssert<SELF extends AbstractMultimapAssert<SELF, ACTUAL, KEY, VALUE>, ACTUAL extends Multimap<KEY, VALUE>, KEY, VALUE>
57-
extends AbstractObjectAssert<SELF, ACTUAL> {
54+
public class MultimapAssert<KEY, VALUE> extends AbstractAssert<MultimapAssert<KEY, VALUE>, Multimap<KEY, VALUE>> {
5855

5956
/**
60-
* Creates a new {@link AbstractMultimapAssert}.
57+
* Creates a new {@link MultimapAssert}.
58+
*
6159
* @param actual The actual Multimap to assert against
62-
* @param selfType The "self" type of child assert class
6360
*/
64-
protected AbstractMultimapAssert(ACTUAL actual, Class<?> selfType) {
65-
super(actual, selfType);
61+
public MultimapAssert(Multimap<KEY, VALUE> actual) {
62+
super(actual, MultimapAssert.class);
6663
}
6764

6865
/**
@@ -85,7 +82,7 @@ protected AbstractMultimapAssert(ACTUAL actual, Class<?> selfType) {
8582
* @throws AssertionError if the actual {@link Multimap} does not contain the given entries
8683
*/
8784
@SafeVarargs
88-
public final SELF contains(Pair<KEY, VALUE>... entries) {
85+
public final MultimapAssert<KEY, VALUE> contains(Pair<KEY, VALUE>... entries) {
8986
return this.containsForProxy(Lists.mutable.of(entries));
9087
}
9188

@@ -98,7 +95,7 @@ public final SELF contains(Pair<KEY, VALUE>... entries) {
9895
* @throws AssertionError if the actual {@code Multimap} does not contain one or more of the specified entries.
9996
*/
10097
@SafeVarargs
101-
public final SELF contains(Map.Entry<KEY, VALUE>... entries) {
98+
public final MultimapAssert<KEY, VALUE> contains(Map.Entry<KEY, VALUE>... entries) {
10299
MutableList<Pair<KEY, VALUE>> pairs = Lists.mutable.of(entries).collect(Tuples::pairFrom);
103100
return this.containsForProxy(pairs);
104101
}
@@ -110,7 +107,7 @@ public final SELF contains(Map.Entry<KEY, VALUE>... entries) {
110107
* @return this assertion object for method chaining.
111108
* @throws AssertionError if the actual {@code Multimap} does not contain one or more of the specified entries.
112109
*/
113-
protected SELF containsForProxy(MutableList<Pair<KEY, VALUE>> entries) {
110+
protected MultimapAssert<KEY, VALUE> containsForProxy(MutableList<Pair<KEY, VALUE>> entries) {
114111
this.isNotNull();
115112
MutableList<Pair<KEY, VALUE>> entriesNotFound = entries
116113
.reject(entry -> this.actual.containsKeyAndValue(entry.getOne(), entry.getTwo()));
@@ -130,7 +127,7 @@ protected SELF containsForProxy(MutableList<Pair<KEY, VALUE>> entries) {
130127
* @see #contains(Pair[])
131128
* @see #contains(Map.Entry[])
132129
*/
133-
public SELF containsEntry(KEY key, VALUE value) {
130+
public MultimapAssert<KEY, VALUE> containsEntry(KEY key, VALUE value) {
134131
return this.contains(Tuples.pair(key, value));
135132
}
136133

@@ -152,7 +149,7 @@ public SELF containsEntry(KEY key, VALUE value) {
152149
* @return this assertion object for method chaining.
153150
* @throws AssertionError if the actual {@link Multimap} does not contain the given keys.
154151
*/
155-
public SELF containsKeys(KEY... keys) {
152+
public MultimapAssert<KEY, VALUE> containsKeys(KEY... keys) {
156153
this.isNotNull();
157154
MutableList<KEY> keysNotFound = Lists.mutable.of(keys).reject(this.actual::containsKey);
158155
if (keysNotFound.isEmpty()) {
@@ -169,7 +166,7 @@ public SELF containsKeys(KEY... keys) {
169166
* @throws AssertionError if the actual {@link Multimap} does not contain only the given entries.
170167
*/
171168
@SafeVarargs
172-
public final SELF containsOnly(Map.Entry<? extends KEY, ? extends VALUE>... entries) {
169+
public final MultimapAssert<KEY, VALUE> containsOnly(Map.Entry<? extends KEY, ? extends VALUE>... entries) {
173170
MutableList<Pair<? extends KEY, ? extends VALUE>> pairs = Lists.mutable.of(entries).collect(Tuples::pairFrom);
174171
return this.containsOnlyForProxy(pairs);
175172
}
@@ -182,7 +179,7 @@ public final SELF containsOnly(Map.Entry<? extends KEY, ? extends VALUE>... entr
182179
* @throws AssertionError if the actual {@link Multimap} does not contain only the given entries.
183180
*/
184181
@SafeVarargs
185-
public final SELF containsOnly(Pair<? extends KEY, ? extends VALUE>... entries) {
182+
public final MultimapAssert<KEY, VALUE> containsOnly(Pair<? extends KEY, ? extends VALUE>... entries) {
186183
return this.containsOnlyForProxy(Lists.mutable.of(entries));
187184
}
188185

@@ -193,7 +190,7 @@ public final SELF containsOnly(Pair<? extends KEY, ? extends VALUE>... entries)
193190
* @return this assertion object for method chaining
194191
* @throws AssertionError if the actual {@link Multimap} does not contain only the given entries.
195192
*/
196-
protected SELF containsOnlyForProxy(MutableList<Pair<? extends KEY, ? extends VALUE>> entries) {
193+
protected MultimapAssert<KEY, VALUE> containsOnlyForProxy(MutableList<Pair<? extends KEY, ? extends VALUE>> entries) {
197194
this.isNotNull();
198195
PartitionMutableList<Pair<? extends KEY, ? extends VALUE>> partition = entries
199196
.partition(entry -> this.actual.containsKeyAndValue(entry.getOne(), entry.getTwo()));
@@ -217,7 +214,7 @@ protected SELF containsOnlyForProxy(MutableList<Pair<? extends KEY, ? extends VA
217214
* @return the current assertion object for method chaining
218215
* @throws AssertionError if the actual map does not contain the given values
219216
*/
220-
public SELF containsValues(VALUE... values) {
217+
public MultimapAssert<KEY, VALUE> containsValues(VALUE... values) {
221218
this.isNotNull();
222219
MutableList<VALUE> valuesNotFound = Lists.mutable.of(values).reject(this.actual::containsValue);
223220
if (valuesNotFound.isEmpty()) {
@@ -233,7 +230,7 @@ public SELF containsValues(VALUE... values) {
233230
* @return this assertion object for method chaining.
234231
* @throws AssertionError if the actual number of distinct keys in the {@code Multimap} does not match the expected size.
235232
*/
236-
public SELF hasDistinctSize(int expected) {
233+
public MultimapAssert<KEY, VALUE> hasDistinctSize(int expected) {
237234
this.isNotNull();
238235
int actualSize = this.actual.sizeDistinct();
239236
if (actualSize == expected) {
@@ -249,7 +246,7 @@ public SELF hasDistinctSize(int expected) {
249246
* @return this assertion object for method chaining.
250247
* @throws AssertionError if the actual distinct size of the {@link Multimap} is not greater than the specified boundary.
251248
*/
252-
public SELF hasDistinctSizeGreaterThan(int boundary) {
249+
public MultimapAssert<KEY, VALUE> hasDistinctSizeGreaterThan(int boundary) {
253250
this.isNotNull();
254251
int actualSize = this.actual.sizeDistinct();
255252
if (actualSize > boundary) {
@@ -265,7 +262,7 @@ public SELF hasDistinctSizeGreaterThan(int boundary) {
265262
* @return this assertion for method chaining
266263
* @throws AssertionError if the distinct size of the collection is less than the specified boundary
267264
*/
268-
public SELF hasDistinctSizeGreaterThanOrEqualTo(int boundary) {
265+
public MultimapAssert<KEY, VALUE> hasDistinctSizeGreaterThanOrEqualTo(int boundary) {
269266
this.isNotNull();
270267
int actualSize = this.actual.sizeDistinct();
271268
if (actualSize >= boundary) {
@@ -282,7 +279,7 @@ public SELF hasDistinctSizeGreaterThanOrEqualTo(int boundary) {
282279
* @throws NullPointerException if the provided condition is null.
283280
* @throws AssertionError if none of the keys in the {@link Multimap} satisfy the given condition.
284281
*/
285-
public SELF hasKeySatisfying(Condition<? super KEY> keyCondition) {
282+
public MultimapAssert<KEY, VALUE> hasKeySatisfying(Condition<? super KEY> keyCondition) {
286283
this.isNotNull();
287284
requireNonNull(keyCondition, "The condition to evaluate should not be null");
288285

@@ -312,7 +309,7 @@ public SELF hasKeySatisfying(Condition<? super KEY> keyCondition) {
312309
* @return {@code this} assertion object.
313310
* @throws AssertionError if the actual size of the {@link Multimap} is not equal to the expected size.
314311
*/
315-
public SELF hasSize(int expected) {
312+
public MultimapAssert<KEY, VALUE> hasSize(int expected) {
316313
this.isNotNull();
317314
int actualSize = this.actual.size();
318315
if (actualSize == expected) {
@@ -342,7 +339,7 @@ public SELF hasSize(int expected) {
342339
* @return {@code this} assertion object.
343340
* @throws AssertionError if the actual size of the {@link Multimap} is not between the given boundaries.
344341
*/
345-
public SELF hasSizeBetween(int lowerBoundary, int higherBoundary) {
342+
public MultimapAssert<KEY, VALUE> hasSizeBetween(int lowerBoundary, int higherBoundary) {
346343
this.isNotNull();
347344
int actualSize = this.actual.size();
348345
if (actualSize >= lowerBoundary && actualSize <= higherBoundary) {
@@ -370,7 +367,7 @@ public SELF hasSizeBetween(int lowerBoundary, int higherBoundary) {
370367
* @return {@code this} assertion object.
371368
* @throws AssertionError if the actual size of the {@link Multimap} is not greater than the specified boundary.
372369
*/
373-
public SELF hasSizeGreaterThan(int boundary) {
370+
public MultimapAssert<KEY, VALUE> hasSizeGreaterThan(int boundary) {
374371
this.isNotNull();
375372
int actualSize = this.actual.size();
376373
if (actualSize > boundary) {
@@ -400,7 +397,7 @@ public SELF hasSizeGreaterThan(int boundary) {
400397
* @return {@code this} assertion object for method chaining.
401398
* @throws AssertionError if the actual size of the {@link Multimap} is less than the expected size.
402399
*/
403-
public SELF hasSizeGreaterThanOrEqualTo(int boundary) {
400+
public MultimapAssert<KEY, VALUE> hasSizeGreaterThanOrEqualTo(int boundary) {
404401
this.isNotNull();
405402
int actualSize = this.actual.size();
406403
if (actualSize >= boundary) {
@@ -428,7 +425,7 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) {
428425
* @return {@code this} assertion object.
429426
* @throws AssertionError if the actual size of the {@link Multimap} is not less than the expected size.
430427
*/
431-
public SELF hasSizeLessThan(int boundary) {
428+
public MultimapAssert<KEY, VALUE> hasSizeLessThan(int boundary) {
432429
this.isNotNull();
433430
int actualSize = this.actual.size();
434431
if (actualSize < boundary) {
@@ -457,7 +454,7 @@ public SELF hasSizeLessThan(int boundary) {
457454
* @return {@code this} assertion object for method chaining.
458455
* @throws AssertionError if the actual size of the {@link Multimap} is greater than the expected size.
459456
*/
460-
public SELF hasSizeLessThanOrEqualTo(int boundary) {
457+
public MultimapAssert<KEY, VALUE> hasSizeLessThanOrEqualTo(int boundary) {
461458
this.isNotNull();
462459
int actualSize = this.actual.size();
463460
if (actualSize <= boundary) {
@@ -474,7 +471,7 @@ public SELF hasSizeLessThanOrEqualTo(int boundary) {
474471
* @throws NullPointerException if the provided condition is null.
475472
* @throws AssertionError if none of the values in the {@link Multimap} satisfy the given condition.
476473
*/
477-
public SELF hasValueSatisfying(Condition<? super VALUE> valueCondition) {
474+
public MultimapAssert<KEY, VALUE> hasValueSatisfying(Condition<? super VALUE> valueCondition) {
478475
this.isNotNull();
479476
requireNonNull(valueCondition, "The condition to evaluate should not be null");
480477

@@ -522,7 +519,7 @@ public void isEmpty() {
522519
* @return this assertion object for method chaining
523520
* @throws AssertionError if the {@link Multimap} of values is empty.
524521
*/
525-
public SELF isNotEmpty() {
522+
public MultimapAssert<KEY, VALUE> isNotEmpty() {
526523
this.isNotNull();
527524
if (!this.actual.isEmpty()) {
528525
return this.myself;

0 commit comments

Comments
 (0)