Skip to content

Commit 0521edf

Browse files
committed
Fix missing configuration for MatcherAssert soft assertions
1 parent 2b2e5c9 commit 0521edf

File tree

4 files changed

+58
-25
lines changed

4 files changed

+58
-25
lines changed

assertj-core/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,6 @@ static <T> InstanceOfAssertFactory<T, ObjectAssert<T>> type(Class<T> type) {
443443
*/
444444
InstanceOfAssertFactory<Object[], ObjectArrayAssert<Object>> ARRAY = array(Object[].class);
445445

446-
/**
447-
* {@link InstanceOfAssertFactory} for an two-dimensional array of {@link Object}.
448-
*
449-
* @see #array(Class)
450-
*/
451-
InstanceOfAssertFactory<Object[][], Object2DArrayAssert<Object>> ARRAY_2D = array2D(Object[][].class);
452-
453446
/**
454447
* {@link InstanceOfAssertFactory} for an array of elements.
455448
*
@@ -464,7 +457,14 @@ static <ELEMENT> InstanceOfAssertFactory<ELEMENT[], ObjectArrayAssert<ELEMENT>>
464457
}
465458

466459
/**
467-
* {@link InstanceOfAssertFactory} for an two-dimensional array of elements.
460+
* {@link InstanceOfAssertFactory} for a two-dimensional array of {@link Object}.
461+
*
462+
* @see #array(Class)
463+
*/
464+
InstanceOfAssertFactory<Object[][], Object2DArrayAssert<Object>> ARRAY_2D = array2D(Object[][].class);
465+
466+
/**
467+
* {@link InstanceOfAssertFactory} for a two-dimensional array of elements.
468468
*
469469
* @param <ELEMENT> the element type.
470470
* @param arrayType the element type instance.

assertj-core/src/main/java/org/assertj/core/api/ProxifyMethodChangingTheObjectUnderTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.function.IntPredicate;
5656
import java.util.function.LongPredicate;
5757
import java.util.function.Predicate;
58+
import java.util.regex.Matcher;
5859

5960
import net.bytebuddy.implementation.bind.annotation.FieldValue;
6061
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
@@ -163,6 +164,7 @@ private static Class actualClass(Object currentAssert) {
163164
if (currentAssert instanceof LongAssert) return Long.class;
164165
if (currentAssert instanceof LongPredicateAssert) return LongPredicate.class;
165166
if (currentAssert instanceof MapAssert) return Map.class;
167+
if (currentAssert instanceof MatcherAssert) return Matcher.class;
166168
if (currentAssert instanceof ObjectAssert) return Object.class;
167169
if (currentAssert instanceof OffsetDateTimeAssert) return OffsetDateTime.class;
168170
if (currentAssert instanceof OffsetTimeAssert) return OffsetTime.class;

assertj-core/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java

+36-13
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import static org.assertj.core.api.InstanceOfAssertFactories.LONG_PREDICATE;
7878
import static org.assertj.core.api.InstanceOfAssertFactories.LONG_STREAM;
7979
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
80+
import static org.assertj.core.api.InstanceOfAssertFactories.MATCHER;
8081
import static org.assertj.core.api.InstanceOfAssertFactories.OFFSET_DATE_TIME;
8182
import static org.assertj.core.api.InstanceOfAssertFactories.OFFSET_TIME;
8283
import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL;
@@ -99,6 +100,7 @@
99100
import static org.assertj.core.api.InstanceOfAssertFactories.URL_TYPE;
100101
import static org.assertj.core.api.InstanceOfAssertFactories.ZONED_DATE_TIME;
101102
import static org.assertj.core.api.InstanceOfAssertFactories.array;
103+
import static org.assertj.core.api.InstanceOfAssertFactories.array2D;
102104
import static org.assertj.core.api.InstanceOfAssertFactories.atomicIntegerFieldUpdater;
103105
import static org.assertj.core.api.InstanceOfAssertFactories.atomicLongFieldUpdater;
104106
import static org.assertj.core.api.InstanceOfAssertFactories.atomicMarkableReference;
@@ -121,7 +123,6 @@
121123
import static org.assertj.core.api.InstanceOfAssertFactories.throwable;
122124
import static org.assertj.core.api.InstanceOfAssertFactories.type;
123125
import static org.assertj.core.test.Maps.mapOf;
124-
import static org.assertj.core.util.Lists.list;
125126
import static org.mockito.Mockito.mock;
126127

127128
import java.io.ByteArrayInputStream;
@@ -168,11 +169,13 @@
168169
import java.util.function.IntPredicate;
169170
import java.util.function.LongPredicate;
170171
import java.util.function.Predicate;
172+
import java.util.regex.Pattern;
171173
import java.util.stream.DoubleStream;
172174
import java.util.stream.IntStream;
173175
import java.util.stream.LongStream;
174176
import java.util.stream.Stream;
175177

178+
import org.assertj.core.util.Lists;
176179
import org.assertj.core.util.Strings;
177180
import org.junit.jupiter.api.Test;
178181

@@ -321,6 +324,16 @@ void optional_long_factory_should_allow_optional_long_assertions() {
321324
result.isPresent();
322325
}
323326

327+
@Test
328+
void matcher_factory_should_allow_matcher_assertions() {
329+
// GIVEN
330+
Object value = Pattern.compile("a*").matcher("aaa");
331+
// WHEN
332+
MatcherAssert result = assertThat(value).asInstanceOf(MATCHER);
333+
// THEN
334+
result.matches();
335+
}
336+
324337
@Test
325338
void big_decimal_factory_should_allow_big_decimal_assertions() {
326339
// GIVEN
@@ -641,6 +654,16 @@ void array_factory_should_allow_array_assertions() {
641654
result.containsExactly(0, "");
642655
}
643656

657+
@Test
658+
void array_typed_factory_should_allow_array_typed_assertions() {
659+
// GIVEN
660+
Object value = new Integer[] { 0, 1 };
661+
// WHEN
662+
ObjectArrayAssert<Integer> result = assertThat(value).asInstanceOf(array(Integer[].class));
663+
// THEN
664+
result.containsExactly(0, 1);
665+
}
666+
644667
@Test
645668
void array_2d_factory_should_allow_2d_array_assertions() {
646669
// GIVEN
@@ -652,13 +675,13 @@ void array_2d_factory_should_allow_2d_array_assertions() {
652675
}
653676

654677
@Test
655-
void array_typed_factory_should_allow_array_typed_assertions() {
678+
void array_2d_typed_factory_should_allow_2d_array_typed_assertions() {
656679
// GIVEN
657-
Object value = new Integer[] { 0, 1 };
680+
Object value = new Integer[][] { { 0, 1 }, { 2, 3 } };
658681
// WHEN
659-
ObjectArrayAssert<Integer> result = assertThat(value).asInstanceOf(array(Integer[].class));
682+
Object2DArrayAssert<Integer> result = assertThat(value).asInstanceOf(array2D(Integer[][].class));
660683
// THEN
661-
result.containsExactly(0, 1);
684+
result.hasDimensions(2, 2);
662685
}
663686

664687
@Test
@@ -1055,7 +1078,7 @@ void string_factory_should_allow_string_assertions() {
10551078
@Test
10561079
void iterable_factory_should_allow_iterable_assertions() {
10571080
// GIVEN
1058-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1081+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
10591082
// WHEN
10601083
IterableAssert<Object> result = assertThat(value).asInstanceOf(ITERABLE);
10611084
// THEN
@@ -1065,7 +1088,7 @@ void iterable_factory_should_allow_iterable_assertions() {
10651088
@Test
10661089
void iterable_typed_factory_should_allow_iterable_typed_assertions() {
10671090
// GIVEN
1068-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1091+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
10691092
// WHEN
10701093
IterableAssert<String> result = assertThat(value).asInstanceOf(iterable(String.class));
10711094
// THEN
@@ -1075,7 +1098,7 @@ void iterable_typed_factory_should_allow_iterable_typed_assertions() {
10751098
@Test
10761099
void iterator_factory_should_allow_iterator_assertions() {
10771100
// GIVEN
1078-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator();
1101+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator();
10791102
// WHEN
10801103
IteratorAssert<Object> result = assertThat(value).asInstanceOf(ITERATOR);
10811104
// THEN
@@ -1085,7 +1108,7 @@ void iterator_factory_should_allow_iterator_assertions() {
10851108
@Test
10861109
void iterator_typed_factory_should_allow_iterator_typed_assertions() {
10871110
// GIVEN
1088-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator();
1111+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator();
10891112
// WHEN
10901113
IteratorAssert<String> result = assertThat(value).asInstanceOf(iterator(String.class));
10911114
// THEN
@@ -1095,7 +1118,7 @@ void iterator_typed_factory_should_allow_iterator_typed_assertions() {
10951118
@Test
10961119
void collection_factory_should_allow_collection_assertions() {
10971120
// GIVEN
1098-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1121+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
10991122
// WHEN
11001123
AbstractCollectionAssert<?, Collection<?>, Object, ObjectAssert<Object>> result = assertThat(value).asInstanceOf(COLLECTION);
11011124
// THEN
@@ -1105,7 +1128,7 @@ void collection_factory_should_allow_collection_assertions() {
11051128
@Test
11061129
void collection_typed_factory_should_allow_collection_typed_assertions() {
11071130
// GIVEN
1108-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1131+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
11091132
// WHEN
11101133
AbstractCollectionAssert<?, Collection<? extends String>, String, ObjectAssert<String>> result = assertThat(value).asInstanceOf(collection(String.class));
11111134
// THEN
@@ -1115,7 +1138,7 @@ void collection_typed_factory_should_allow_collection_typed_assertions() {
11151138
@Test
11161139
void list_factory_should_allow_list_assertions() {
11171140
// GIVEN
1118-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1141+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
11191142
// WHEN
11201143
ListAssert<Object> result = assertThat(value).asInstanceOf(LIST);
11211144
// THEN
@@ -1125,7 +1148,7 @@ void list_factory_should_allow_list_assertions() {
11251148
@Test
11261149
void list_typed_factory_should_allow_typed_list_assertions() {
11271150
// GIVEN
1128-
Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie");
1151+
Object value = Lists.list("Homer", "Marge", "Bart", "Lisa", "Maggie");
11291152
// WHEN
11301153
ListAssert<String> result = assertThat(value).asInstanceOf(list(String.class));
11311154
// THEN

assertj-core/src/test/java/org/assertj/core/api/SoftAssertions_combined_with_asInstanceOf_Test.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_INTEGER;
2121
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_INTEGER_ARRAY;
2222
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_INTEGER_FIELD_UPDATER;
23+
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_LONG;
24+
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_LONG_ARRAY;
2325
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_LONG_FIELD_UPDATER;
2426
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_MARKABLE_REFERENCE;
2527
import static org.assertj.core.api.InstanceOfAssertFactories.ATOMIC_REFERENCE;
@@ -39,6 +41,7 @@
3941
import static org.assertj.core.api.InstanceOfAssertFactories.CHAR_ARRAY;
4042
import static org.assertj.core.api.InstanceOfAssertFactories.CHAR_SEQUENCE;
4143
import static org.assertj.core.api.InstanceOfAssertFactories.CLASS;
44+
import static org.assertj.core.api.InstanceOfAssertFactories.COLLECTION;
4245
import static org.assertj.core.api.InstanceOfAssertFactories.COMPLETABLE_FUTURE;
4346
import static org.assertj.core.api.InstanceOfAssertFactories.COMPLETION_STAGE;
4447
import static org.assertj.core.api.InstanceOfAssertFactories.DATE;
@@ -72,6 +75,7 @@
7275
import static org.assertj.core.api.InstanceOfAssertFactories.LONG_PREDICATE;
7376
import static org.assertj.core.api.InstanceOfAssertFactories.LONG_STREAM;
7477
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
78+
import static org.assertj.core.api.InstanceOfAssertFactories.MATCHER;
7579
import static org.assertj.core.api.InstanceOfAssertFactories.OFFSET_DATE_TIME;
7680
import static org.assertj.core.api.InstanceOfAssertFactories.OFFSET_TIME;
7781
import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL;
@@ -91,6 +95,7 @@
9195
import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE;
9296
import static org.assertj.core.api.InstanceOfAssertFactories.URI_TYPE;
9397
import static org.assertj.core.api.InstanceOfAssertFactories.URL_TYPE;
98+
import static org.assertj.core.api.InstanceOfAssertFactories.ZONED_DATE_TIME;
9499
import static org.assertj.core.util.Lists.list;
95100
import static org.assertj.core.util.Maps.newHashMap;
96101
import static org.assertj.core.util.Sets.newHashSet;
@@ -135,6 +140,7 @@
135140
import java.util.function.IntPredicate;
136141
import java.util.function.LongPredicate;
137142
import java.util.function.Predicate;
143+
import java.util.regex.Pattern;
138144
import java.util.stream.DoubleStream;
139145
import java.util.stream.IntStream;
140146
import java.util.stream.LongStream;
@@ -187,8 +193,8 @@ public static Stream<Arguments> should_work_with_any_InstanceOfFactory_source()
187193
arguments(new AtomicInteger(1), ATOMIC_INTEGER),
188194
arguments(new AtomicIntegerArray(5), ATOMIC_INTEGER_ARRAY),
189195
arguments(AtomicIntegerFieldUpdater.newUpdater(Data.class, "intField"), ATOMIC_INTEGER_FIELD_UPDATER),
190-
arguments(new AtomicLong(5l), InstanceOfAssertFactories.ATOMIC_LONG),
191-
arguments(new AtomicLongArray(5), InstanceOfAssertFactories.ATOMIC_LONG_ARRAY),
196+
arguments(new AtomicLong(5L), ATOMIC_LONG),
197+
arguments(new AtomicLongArray(5), ATOMIC_LONG_ARRAY),
192198
arguments(AtomicLongFieldUpdater.newUpdater(Data.class, "longField"), ATOMIC_LONG_FIELD_UPDATER),
193199
arguments(new AtomicMarkableReference<>("", false), ATOMIC_MARKABLE_REFERENCE),
194200
arguments(new AtomicReference<>("abc"), ATOMIC_REFERENCE),
@@ -210,6 +216,7 @@ public static Stream<Arguments> should_work_with_any_InstanceOfFactory_source()
210216
arguments('a', CHARACTER),
211217
arguments(Character.valueOf('a'), CHARACTER),
212218
arguments(TolkienCharacter.class, CLASS),
219+
arguments(list("foo"), COLLECTION),
213220
arguments(completedFuture("foo"), COMPLETABLE_FUTURE),
214221
arguments(completionStage, COMPLETION_STAGE),
215222
arguments(new Date(), DATE),
@@ -245,14 +252,15 @@ public static Stream<Arguments> should_work_with_any_InstanceOfFactory_source()
245252
arguments((LongPredicate) l -> l == 0, LONG_PREDICATE),
246253
arguments(LongStream.empty(), LONG_STREAM),
247254
arguments(newHashMap("k", "v"), MAP),
255+
arguments(Pattern.compile("a*").matcher("aaa"), MATCHER),
248256
arguments(OffsetDateTime.now(), OFFSET_DATE_TIME),
249257
arguments(OffsetTime.now(), OFFSET_TIME),
250258
arguments(Optional.empty(), OPTIONAL),
251259
arguments(OptionalDouble.empty(), OPTIONAL_DOUBLE),
252260
arguments(OptionalInt.empty(), OPTIONAL_INT),
253261
arguments(OptionalLong.empty(), OPTIONAL_LONG),
254262
arguments(Paths.get("."), PATH),
255-
arguments((Predicate<String>) s -> s.isEmpty(), PREDICATE),
263+
arguments((Predicate<String>) String::isEmpty, PREDICATE),
256264
arguments(Short.MIN_VALUE, SHORT),
257265
arguments(new short[0], SHORT_ARRAY),
258266
arguments(new short[0][0], SHORT_2D_ARRAY),
@@ -263,7 +271,7 @@ public static Stream<Arguments> should_work_with_any_InstanceOfFactory_source()
263271
arguments(new Exception(), THROWABLE),
264272
arguments(URI.create("http://localhost"), URI_TYPE),
265273
arguments(URI.create("http://localhost").toURL(), URL_TYPE),
266-
arguments(ZonedDateTime.now(), InstanceOfAssertFactories.ZONED_DATE_TIME));
274+
arguments(ZonedDateTime.now(), ZONED_DATE_TIME));
267275
}
268276

269277
static class Data {

0 commit comments

Comments
 (0)