Skip to content

Commit b7e0133

Browse files
committed
Rename dead-chain factories to nullXxxAssert
- Rename `deadChainXxxAssert()` static factories to `nullXxxAssert()` on every navigated target assert class (String, Byte, Short, Integer, Long, Float, Double, ByteArray, Throwable, Object, Iterable, List) - Drop the `.deadChain()` call from those factories: all call sites funnel through `markAsDeadChain`, which already sets `skipAssertions` and propagates assertion state - Rename the `deadChainFactory` parameter of `AbstractAssert.executeAssertionNavigation` to `emptyAssertProvider`
1 parent acb59ac commit b7e0133

23 files changed

Lines changed: 60 additions & 60 deletions

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ protected SELF executeAssertion(Runnable body) {
153153
/**
154154
* Wraps a navigation method that returns a different assert type and also performs assertion checks.
155155
* In soft mode, catches {@link AssertionError} from the assertion guards, collects it, and returns a
156-
* dead-chain assertion built from {@code deadChainFactory} (marked with {@link #skipAssertions} so
156+
* dead-chain assertion built from {@code emptyAssertProvider} (marked with {@link #skipAssertions} so
157157
* that subsequent chained assertions no-op instead of throwing a {@link RuntimeException}).
158158
*
159159
* @param <T> the return type of the navigation method
160160
* @param body the navigation method logic to execute
161-
* @param deadChainFactory supplies a fresh assertion instance to mark as dead-chain when a soft
161+
* @param emptyAssertProvider supplies a fresh assertion instance to mark as dead-chain when a soft
162162
* assertion error is collected; typically wraps {@code null} actual
163163
* @return the navigation result, or a dead-chain assertion if an assertion error was collected in soft mode
164164
*/
165-
protected <T extends AbstractAssert<?, ?>> T executeAssertionNavigation(Supplier<T> body, Supplier<T> deadChainFactory) {
165+
protected <T extends AbstractAssert<?, ?>> T executeAssertionNavigation(Supplier<T> body, Supplier<T> emptyAssertProvider) {
166166
if (assertionErrorHandler == null) {
167167
try {
168168
return body.get();
@@ -172,7 +172,7 @@ protected SELF executeAssertion(Runnable body) {
172172
throw new RuntimeException(e);
173173
}
174174
}
175-
if (skipAssertions) return markAsDeadChain(deadChainFactory.get());
175+
if (skipAssertions) return markAsDeadChain(emptyAssertProvider.get());
176176
int depth = SOFT_CALL_DEPTH.get();
177177
SOFT_CALL_DEPTH.set(depth + 1);
178178
try {
@@ -182,7 +182,7 @@ protected SELF executeAssertion(Runnable body) {
182182
} catch (AssertionError e) {
183183
if (depth > 0) throw e;
184184
assertionErrorHandler.handleError(e);
185-
return markAsDeadChain(deadChainFactory.get());
185+
return markAsDeadChain(emptyAssertProvider.get());
186186
} catch (RuntimeException e) {
187187
throw e;
188188
} catch (Exception e) {
@@ -736,7 +736,7 @@ public AbstractStringAssert<?> asString() {
736736
return executeAssertionNavigation(() -> {
737737
objects.assertNotNull(info, actual);
738738
return Assertions.assertThat(actual.toString()).withAssertionState(myself);
739-
}, StringAssert::deadChainStringAssert);
739+
}, StringAssert::nullStringAssert);
740740
}
741741

742742
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ public AbstractStringAssert<?> asHexString() {
12171217
return executeAssertionNavigation(() -> {
12181218
objects.assertNotNull(info, actual);
12191219
return assertThat(toHexString(actual)).withAssertionState(myself);
1220-
}, StringAssert::deadChainStringAssert);
1220+
}, StringAssert::nullStringAssert);
12211221
}
12221222

12231223
/**
@@ -1250,7 +1250,7 @@ public AbstractStringAssert<?> asString() {
12501250
objects.assertNotNull(info, actual);
12511251
String actualAsString = new String(actual);
12521252
return assertThat(actualAsString).withAssertionState(myself);
1253-
}, StringAssert::deadChainStringAssert);
1253+
}, StringAssert::nullStringAssert);
12541254
}
12551255

12561256
/**
@@ -1278,7 +1278,7 @@ public AbstractStringAssert<?> asString() {
12781278
@CheckReturnValue
12791279
public AbstractStringAssert<?> asString(Charset charset) {
12801280
isNotNull();
1281-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
1281+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
12821282
String actualAsString = new String(actual, charset);
12831283
return assertThat(actualAsString).withAssertionState(myself);
12841284
}
@@ -1298,7 +1298,7 @@ public AbstractStringAssert<?> asString(Charset charset) {
12981298
@CheckReturnValue
12991299
public AbstractStringAssert<?> asBase64Encoded() {
13001300
isNotNull();
1301-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
1301+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
13021302
return new StringAssert(Base64.getEncoder().encodeToString(actual)).withAssertionState(myself);
13031303
}
13041304

@@ -1317,7 +1317,7 @@ public AbstractStringAssert<?> asBase64Encoded() {
13171317
@CheckReturnValue
13181318
public AbstractStringAssert<?> asBase64UrlEncoded() {
13191319
isNotNull();
1320-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
1320+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
13211321
return new StringAssert(Base64.getUrlEncoder().encodeToString(actual)).withAssertionState(myself);
13221322
}
13231323

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ public AbstractByteArrayAssert<?> binaryContent() {
12371237
return executeAssertionNavigation(() -> {
12381238
files.assertCanRead(info, actual);
12391239
return new ByteArrayAssert(readFile()).withAssertionState(myself);
1240-
}, ByteArrayAssert::deadChainByteArrayAssert);
1240+
}, ByteArrayAssert::nullByteArrayAssert);
12411241
}
12421242

12431243
/**
@@ -1340,7 +1340,7 @@ private AbstractStringAssert<?> internalContent(Charset charset) {
13401340
files.assertCanRead(info, actual);
13411341
String fileContent = readFile(charset);
13421342
return new StringAssert(fileContent).withAssertionState(myself);
1343-
}, StringAssert::deadChainStringAssert);
1343+
}, StringAssert::nullStringAssert);
13441344
}
13451345

13461346
private byte[] readFile() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected AbstractInputStreamAssert(ACTUAL actual, Class<?> selfType) {
9292
@CheckReturnValue
9393
public AbstractStringAssert<?> asString(Charset charset) {
9494
isNotNull();
95-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
95+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
9696
return assertThat(asString(actual, charset)).withAssertionState(myself);
9797
}
9898

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public SELF isExhausted() {
9494
*/
9595
public IterableAssert<ELEMENT> toIterable() {
9696
isNotNull();
97-
if (actual == null) return markAsDeadChain(IterableAssert.<ELEMENT> deadChainIterableAssert());
97+
if (actual == null) return markAsDeadChain(IterableAssert.<ELEMENT> nullIterableAssert());
9898
return new IterableAssert<ELEMENT>(IterableAssert.toIterable(actual)).withAssertionState(myself);
9999
}
100100

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ public AbstractObjectAssert<?, V> extractingByKey(K key) {
17251725

17261726
private AbstractObjectAssert<?, V> internalExtractingByKey(K key) {
17271727
isNotNull();
1728-
if (actual == null) return markAsDeadChain(ObjectAssert.<V> deadChainObjectAssert());
1728+
if (actual == null) return markAsDeadChain(ObjectAssert.<V> nullObjectAssert());
17291729
V extractedValue = actual.get(key);
17301730
String extractedPropertyOrFieldDescription = extractedDescriptionOf(key);
17311731
String description = mostRelevantDescription(info.description(), extractedPropertyOrFieldDescription);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public SELF matches() {
8585
*/
8686
public AbstractStringAssert<?> group(int groupIndex) {
8787
matches();
88-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
88+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
8989
return assertThat(extractGroup(() -> actual.group(groupIndex), groupIndex)).withAssertionState(myself);
9090
}
9191

@@ -109,7 +109,7 @@ public AbstractStringAssert<?> group(int groupIndex) {
109109
*/
110110
public AbstractStringAssert<?> group(String groupName) {
111111
matches();
112-
if (actual == null) return markAsDeadChain(StringAssert.deadChainStringAssert());
112+
if (actual == null) return markAsDeadChain(StringAssert.nullStringAssert());
113113
return assertThat(extractGroup(() -> actual.group(groupName), groupName)).withAssertionState(myself);
114114
}
115115

@@ -131,7 +131,7 @@ public AbstractStringAssert<?> group(String groupName) {
131131
*/
132132
public ListAssert<String> groups() {
133133
matches();
134-
if (actual == null) return markAsDeadChain(ListAssert.deadChainListAssert());
134+
if (actual == null) return markAsDeadChain(ListAssert.nullListAssert());
135135
return assertThat(rangeClosed(1, actual.groupCount()).mapToObj(actual::group).toList()).withAssertionState(myself);
136136
}
137137

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ public RecursiveAssertionAssert usingRecursiveAssertion(RecursiveAssertionConfig
720720

721721
private AbstractObjectAssert<?, VALUE> internalGet() {
722722
isPresent();
723-
if (actual == null || actual.isEmpty()) return markAsDeadChain(ObjectAssert.<VALUE> deadChainObjectAssert());
723+
if (actual == null || actual.isEmpty()) return markAsDeadChain(ObjectAssert.<VALUE> nullObjectAssert());
724724
// noinspection OptionalGetWithoutIsPresent
725725
return assertThat(actual.get()).withAssertionState(myself);
726726
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ public AbstractByteArrayAssert<?> binaryContent() {
18111811
return executeAssertionNavigation(() -> {
18121812
paths.assertIsReadable(info, actual);
18131813
return new ByteArrayAssert(readPath()).withAssertionState(myself);
1814-
}, ByteArrayAssert::deadChainByteArrayAssert);
1814+
}, ByteArrayAssert::nullByteArrayAssert);
18151815
}
18161816

18171817
/**
@@ -1863,7 +1863,7 @@ private AbstractStringAssert<?> internalContent(Charset charset) {
18631863
paths.assertIsReadable(info, actual);
18641864
String pathContent = readPath(charset);
18651865
return new StringAssert(pathContent).withAssertionState(myself);
1866-
}, StringAssert::deadChainStringAssert);
1866+
}, StringAssert::nullStringAssert);
18671867
}
18681868

18691869
private byte[] readPath() {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public SELF isBase64() {
272272
@CheckReturnValue
273273
public AbstractByteArrayAssert<?> asBase64Decoded() {
274274
isBase64();
275-
if (actual == null) return markAsDeadChain(ByteArrayAssert.deadChainByteArrayAssert());
275+
if (actual == null) return markAsDeadChain(ByteArrayAssert.nullByteArrayAssert());
276276
return new ByteArrayAssert(Base64.getDecoder().decode(actual)).withAssertionState(myself);
277277
}
278278

@@ -315,7 +315,7 @@ public SELF isBase64Url() {
315315
@CheckReturnValue
316316
public AbstractByteArrayAssert<?> asBase64UrlDecoded() {
317317
isBase64Url();
318-
if (actual == null) return markAsDeadChain(ByteArrayAssert.deadChainByteArrayAssert());
318+
if (actual == null) return markAsDeadChain(ByteArrayAssert.nullByteArrayAssert());
319319
return new ByteArrayAssert(Base64.getUrlDecoder().decode(actual)).withAssertionState(myself);
320320
}
321321

@@ -472,7 +472,7 @@ public AbstractByteAssert<?> asByte() {
472472
} catch (NumberFormatException e) {
473473
throw failures.failure(info, shouldBeNumeric(actual, BYTE));
474474
}
475-
}, ByteAssert::deadChainByteAssert);
475+
}, ByteAssert::nullByteAssert);
476476
}
477477

478478
/**
@@ -493,7 +493,7 @@ public AbstractByteAssert<?> asByte() {
493493
*/
494494
public AbstractByteArrayAssert<?> bytes() {
495495
isNotNull();
496-
if (actual == null) return markAsDeadChain(ByteArrayAssert.deadChainByteArrayAssert());
496+
if (actual == null) return markAsDeadChain(ByteArrayAssert.nullByteArrayAssert());
497497
return InstanceOfAssertFactories.BYTE_ARRAY.createAssert(actual.getBytes()).withAssertionState(myself);
498498
}
499499

@@ -517,7 +517,7 @@ public AbstractByteArrayAssert<?> bytes() {
517517
public AbstractByteArrayAssert<?> bytes(Charset charset) {
518518
requireNonNull(charset, "The charset must not be null");
519519
isNotNull();
520-
if (actual == null) return markAsDeadChain(ByteArrayAssert.deadChainByteArrayAssert());
520+
if (actual == null) return markAsDeadChain(ByteArrayAssert.nullByteArrayAssert());
521521
byte[] bytes = actual.getBytes(charset);
522522
return InstanceOfAssertFactories.BYTE_ARRAY.createAssert(bytes).withAssertionState(myself);
523523
}
@@ -542,7 +542,7 @@ public AbstractByteArrayAssert<?> bytes(Charset charset) {
542542
public AbstractByteArrayAssert<?> bytes(String charsetName) {
543543
requireNonNull(charsetName, "The charsetName must not be null");
544544
isNotNull();
545-
if (actual == null) return markAsDeadChain(ByteArrayAssert.deadChainByteArrayAssert());
545+
if (actual == null) return markAsDeadChain(ByteArrayAssert.nullByteArrayAssert());
546546
try {
547547
byte[] bytes = actual.getBytes(charsetName);
548548
return InstanceOfAssertFactories.BYTE_ARRAY.createAssert(bytes).withAssertionState(myself);
@@ -576,7 +576,7 @@ public AbstractShortAssert<?> asShort() {
576576
} catch (NumberFormatException e) {
577577
throw failures.failure(info, shouldBeNumeric(actual, SHORT));
578578
}
579-
}, ShortAssert::deadChainShortAssert);
579+
}, ShortAssert::nullShortAssert);
580580
}
581581

582582
/**
@@ -604,7 +604,7 @@ public AbstractIntegerAssert<?> asInt() {
604604
} catch (NumberFormatException e) {
605605
throw failures.failure(info, shouldBeNumeric(actual, INTEGER));
606606
}
607-
}, IntegerAssert::deadChainIntegerAssert);
607+
}, IntegerAssert::nullIntegerAssert);
608608
}
609609

610610
/**
@@ -632,7 +632,7 @@ public AbstractLongAssert<?> asLong() {
632632
} catch (NumberFormatException e) {
633633
throw failures.failure(info, shouldBeNumeric(actual, LONG));
634634
}
635-
}, LongAssert::deadChainLongAssert);
635+
}, LongAssert::nullLongAssert);
636636
}
637637

638638
/**
@@ -660,7 +660,7 @@ public AbstractFloatAssert<?> asFloat() {
660660
} catch (NumberFormatException | NullPointerException e) {
661661
throw failures.failure(info, shouldBeNumeric(actual, FLOAT));
662662
}
663-
}, FloatAssert::deadChainFloatAssert);
663+
}, FloatAssert::nullFloatAssert);
664664
}
665665

666666
/**
@@ -688,6 +688,6 @@ public AbstractDoubleAssert<?> asDouble() {
688688
} catch (NumberFormatException | NullPointerException e) {
689689
throw failures.failure(info, shouldBeNumeric(actual, DOUBLE));
690690
}
691-
}, DoubleAssert::deadChainDoubleAssert);
691+
}, DoubleAssert::nullDoubleAssert);
692692
}
693693
}

0 commit comments

Comments
 (0)