Replace for loops with String.repeat where appropriate

This commit is contained in:
Mahmoud Ben Hassine
2023-06-12 16:00:45 +02:00
parent a63755b546
commit 8c5456cff6
2 changed files with 5 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,9 +49,7 @@ class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
void testTruncateExitDescription() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++) {
sb.append("too long exit description");
}
sb.append("too long exit description".repeat(100));
String longDescription = sb.toString();
ExitStatus exitStatus = ExitStatus.FAILED.addExitDescription(longDescription);

View File

@@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test;
* Unit tests for {@link FormatterLineAggregator}
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
class FormatterLineAggregatorTests {
@@ -120,9 +121,7 @@ class FormatterLineAggregatorTests {
strings[i] = item[i];
if (item[i].length() < widths[i]) {
StringBuilder buffer = new StringBuilder(strings[i]);
for (int j = 0; j < (widths[i] - item[i].length() + 1) / 2; j++) {
buffer.append(" ");
}
buffer.append(" ".repeat(Math.max(0, (widths[i] - item[i].length() + 1) / 2)));
strings[i] = buffer.toString();
}
}
@@ -155,9 +154,7 @@ class FormatterLineAggregatorTests {
strings[i] = item[i];
if (item[i].length() < widths[i]) {
StringBuilder buffer = new StringBuilder(strings[i]);
for (int j = 0; j < widths[i] - item[i].length(); j++) {
buffer.append(".");
}
buffer.append(".".repeat(Math.max(0, widths[i] - item[i].length())));
strings[i] = buffer.toString();
}
}