Skip to content

Commit c21e7cd

Browse files
committed
chore: refine code
1 parent e8515e6 commit c21e7cd

File tree

3 files changed

+16
-12
lines changed
  • pdfclown-common-build/src
  • pdfclown-common-util/src/test/java/org/pdfclown/common/util/measure

3 files changed

+16
-12
lines changed

pdfclown-common-build/src/main/java/org/pdfclown/common/build/test/assertion/Assertions.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. If you reuse (enti
2929
import static org.pdfclown.common.build.internal.util_.Exceptions.runtime;
3030
import static org.pdfclown.common.build.internal.util_.Exceptions.unexpected;
3131
import static org.pdfclown.common.build.internal.util_.Exceptions.wrongArg;
32+
import static org.pdfclown.common.build.internal.util_.Objects.LITERAL_NULL;
3233
import static org.pdfclown.common.build.internal.util_.Objects.fqn;
3334
import static org.pdfclown.common.build.internal.util_.Objects.fqnd;
3435
import static org.pdfclown.common.build.internal.util_.Objects.objToLiteralString;
@@ -445,6 +446,8 @@ Matcher<T> getMatcher() {
445446
* @see Assertions#assertParameterized(Object, Expected, Supplier)
446447
*/
447448
public static class ExpectedGeneration {
449+
private static final int MAX_ARG_COMMENT_LENGTH__DEFAULT = 50;
450+
448451
/**
449452
* Gets the constructor source code to use in {@link #setExpectedSourceCodeGenerator(Function)}.
450453
*
@@ -470,7 +473,7 @@ public static String expectedSourceCodeForFactory(Class<?> type, String methodNa
470473
Function<@Nullable Object, String> argCommentFormatter = Objects::objToLiteralString;
471474
final List<Entry<String, @Nullable Object>> args;
472475
Function<Object, String> expectedSourceCodeGenerator = Objects::objToLiteralString;
473-
int maxArgCommentLength = 20;
476+
int maxArgCommentLength = MAX_ARG_COMMENT_LENGTH__DEFAULT;
474477
PrintStream out = System.err;
475478
boolean outOverridable = true;
476479

@@ -522,7 +525,7 @@ public Function<Object, String> getExpectedSourceCodeGenerator() {
522525
/**
523526
* Maximum length of argument values in comments accompanying expected results source code.
524527
* <p>
525-
* DEFAULT: {@code 20}
528+
* DEFAULT: {@value #MAX_ARG_COMMENT_LENGTH__DEFAULT}
526529
* </p>
527530
*/
528531
public int getMaxArgCommentLength() {
@@ -758,11 +761,11 @@ protected ExpectedGenerator(int count) {
758761
* The expected result is mapped to source code representation based on its value type:
759762
* </p>
760763
* <ul>
761-
* <li>{@code null} — to literal null ({@code "null"})</li>
762764
* <li>failed result (thrown {@link Throwable}) — to {@link Failure}</li>
763765
* <li>regular result — via
764766
* {@code generation.}{@link ExpectedGeneration#getExpectedSourceCodeGenerator()
765767
* expectedSourceCodeGenerator}</li>
768+
* <li>{@code null} — to literal null ({@code "null"})</li>
766769
* </ul>
767770
*
768771
* @param expected
@@ -831,7 +834,7 @@ protected <T> void generateExpectedSourceCode(@Nullable Object expected,
831834
ExpectedGeneration generation) {
832835
String expectedSourceCode;
833836
if (expected == null) {
834-
expectedSourceCode = "null";
837+
expectedSourceCode = LITERAL_NULL;
835838
} else if (expected instanceof Failure) {
836839
var failure = (Failure) expected;
837840
expectedSourceCode = String.format("new %s(\"%s\", %s)",

pdfclown-common-build/src/test/java/org/pdfclown/common/build/test/assertion/AssertionsTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void assertParameterized__cartesian_generation(Expected<String> expected, String
213213
doAssertParameterized_generation(expected, value, length, ""
214214
+ "// expected\n"
215215
+ "java.util.Arrays.asList(\n"
216-
+ " // value[0]: \"The quick brow. . .\"\n"
216+
+ " // value[0]: \"The quick brown fox jumps over the lazy dog\"\n"
217217
+ " // [1] length[0]: 50\n"
218218
+ " new org.pdfclown.common.build.test.assertion.Assertions.Failure("
219219
+ "\"java.lang.IllegalArgumentException\", "
@@ -223,7 +223,7 @@ void assertParameterized__cartesian_generation(Expected<String> expected, String
223223
+ " // [3] length[2]: 5\n"
224224
+ " \"The q\",\n"
225225
+ " //\n"
226-
+ " // value[1]: \"The lazy yello. . .\"\n"
226+
+ " // value[1]: \"The lazy yellow dog was caught by the slow r. . .\"\n"
227227
+ " // [4] length[0]: 50\n"
228228
+ " \"The lazy yellow dog was caught by the slow red fox\",\n"
229229
+ " // [5] length[1]: 20\n"
@@ -256,11 +256,12 @@ void assertParameterized__simple_generation(Expected<String> expected, String va
256256
doAssertParameterized_generation(expected, value, length, ""
257257
+ "// expected\n"
258258
+ "java.util.Arrays.asList(\n"
259-
+ " // [1] value[0]: \"The quick brow. . .\"; length[0]: 50\n"
259+
+ " // [1] value[0]: \"The quick brown fox jumps over the lazy dog\"; length[0]: 50\n"
260260
+ " new org.pdfclown.common.build.test.assertion.Assertions.Failure("
261261
+ "\"java.lang.IllegalArgumentException\", "
262262
+ "\"`length` (50): INVALID (should be less than 43)\"),\n"
263-
+ " // [2] value[1]: \"The lazy yello. . .\"; length[1]: 20\n"
263+
+ " // [2] value[1]: \"The lazy yellow dog was caught by the slow r. . .\"; "
264+
+ "length[1]: 20\n"
264265
+ " \"The lazy yellow dog \"),\n");
265266
}
266267

pdfclown-common-util/src/test/java/org/pdfclown/common/util/measure/UnitsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class UnitsTest extends BaseTest {
5555
.<Unit, String>comparing(Unit::getSymbol, Comparator.nullsFirst(String::compareToIgnoreCase))
5656
.thenComparing(Unit::getName);
5757

58-
private static final List<? super XtUnit<?>> units = Units.getInstance().getUnits().stream()
58+
private static final List<? super XtUnit<?>> UNITS = Units.getInstance().getUnits().stream()
5959
.peek($ -> assertThat($, isA(XtUnit.class)))
6060
.map(XtUnit.class::cast)
6161
.sorted(COMPARATOR__UNIT)
@@ -156,7 +156,7 @@ static Stream<Arguments> getFactor_Unit() {
156156
1.0),
157157
// unit
158158
list()
159-
.withAll(units)
159+
.withAll(UNITS)
160160
.with(tech.units.indriya.unit.Units.WEEK)
161161
.with(tech.units.indriya.unit.Units.AMPERE));
162162
}
@@ -294,7 +294,7 @@ static Stream<Arguments> getOffset_Unit() {
294294
// [42] unit[41]: '℃ (Celsius)'
295295
273.15),
296296
// unit
297-
units);
297+
UNITS);
298298
}
299299

300300
static Stream<Arguments> getQuantityType() {
@@ -388,7 +388,7 @@ static Stream<Arguments> getQuantityType() {
388388
// [42] unit[41]: '℃ (Celsius)'
389389
"javax.measure.quantity.Temperature"),
390390
// unit
391-
units);
391+
UNITS);
392392
}
393393

394394
static Stream<Arguments> getQuantityType__external() {

0 commit comments

Comments
 (0)