From 32b03e9334a480fb2ef571bcbdf31168a339ac51 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Mon, 18 Apr 2022 16:49:13 +0200 Subject: [PATCH] Remove unused variable Specify charset, when none is given and use isEmpty. --- .../PreciseThroughputTimerTest.java | 3 --- .../apache/jmeter/resources/PackageTest.java | 26 ++++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java b/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java index ed5e9734132..d6358fc40b8 100644 --- a/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java +++ b/src/components/src/test/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimerTest.java @@ -25,11 +25,8 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class PreciseThroughputTimerTest { - private static final Logger LOG = LoggerFactory.getLogger(PreciseThroughputTimerTest.class); @Test public void testTimer1() throws Exception { diff --git a/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java b/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java index 116a27acd69..744cb69c8fe 100644 --- a/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java +++ b/src/core/src/test/java/org/apache/jmeter/resources/PackageTest.java @@ -23,8 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -67,20 +66,12 @@ public class PackageTest extends TestCase implements Describable { // We assume the test starts in "src/core" directory (which is true for Gradle and IDEs) - private static final File srcFiledir = new File("src/main/java"); private static final File resourceFiledir = new File("src/main/resources"); private static final String MESSAGES = "messages"; private static PropertyResourceBundle defaultPRB; // current default language properties file - private static final CharsetEncoder ASCII_ENCODER = - Charset.forName("US-ASCII").newEncoder(); // Ensure properties files don't use special characters - - private static boolean isPureAscii(String v) { - return ASCII_ENCODER.canEncode(v); - } - // Read resource into ResourceBundle and store in List private PropertyResourceBundle getRAS(String res) throws Exception { InputStream ras = this.getClass().getResourceAsStream(res); @@ -97,16 +88,16 @@ private PropertyResourceBundle getRAS(String res) throws Exception { private void readRF(String res, List l) throws Exception { InputStream ras = this.getClass().getResourceAsStream(res); if (ras == null){ - if (MESSAGES.equals(resourcePrefix)|| lang.length() == 0 ) { + if (MESSAGES.equals(resourcePrefix)|| lang.isEmpty()) { throw new IOException("Cannot open resource file "+res); } else { return; } } - try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(ras));) { + try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(ras, StandardCharsets.UTF_8))) { String s; while ((s = fileReader.readLine()) != null) { - if (s.length() > 0 && !s.startsWith("#") && !s.startsWith("!")) { + if (!s.isEmpty() && !s.startsWith("#") && !s.startsWith("!")) { int equ = s.indexOf('='); String key = s.substring(0, equ); if (resourcePrefix.equals(MESSAGES)){// Only relevant for messages @@ -147,7 +138,7 @@ private void readRF(String res, List l) throws Exception { // Helper method to construct resource name private String getResName(String lang) { - if (lang.length() == 0) { + if (lang.isEmpty()) { return resourcePrefix+".properties"; } else { return resourcePrefix+"_" + lang + ".properties"; @@ -177,7 +168,7 @@ private void check(String resname, boolean checkUnexpected) throws Exception { last = curr; } - if (resname.length() == 0) // Must be the default resource file + if (resname.isEmpty()) // Must be the default resource file { defaultPRB = getRAS(res); if (defaultPRB == null){ @@ -325,15 +316,14 @@ public void checkI18n() throws Exception { for (String prefix : prefixList) { Properties messages = new Properties(); messages.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(prefix.substring(1)+".properties")); - checkMessagesForLanguage( missingLabelsPerBundle , missingLabelsPerBundle, messages,prefix.substring(1), lang); + checkMessagesForLanguage( missingLabelsPerBundle , messages,prefix.substring(1), lang); } assertEquals(missingLabelsPerBundle.size()+" missing labels, labels missing:"+printLabels(missingLabelsPerBundle), 0, missingLabelsPerBundle.size()); } private void checkMessagesForLanguage(Map> missingLabelsPerBundle, - Map> missingLabelsPerBundle2, - Properties messages, String bundlePath, String language) + Properties messages, String bundlePath, String language) throws IOException { Properties messagesFr = new Properties(); String languageBundle = bundlePath+"_"+language+ ".properties";