From 8c5456cff6ac3dfa8ef2cef85c53802e4fdaa112 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Mon, 12 Jun 2023 16:00:45 +0200 Subject: [PATCH] Replace for loops with String.repeat where appropriate --- .../core/repository/dao/JdbcStepExecutionDaoTests.java | 6 ++---- .../file/transform/FormatterLineAggregatorTests.java | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java index d4eb57efb..f4651a247 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java @@ -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); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java index b64af5cff..c0cec91ad 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java @@ -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(); } }