From cf74c5d4897889eba4deb656369d76a84b99b3bf Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Wed, 18 May 2022 15:24:23 +0530 Subject: [PATCH] Remove deprecated utility methods --- .../main/java/org/testng/util/Strings.java | 26 +------- .../main/java/org/testng/reporters/Files.java | 63 ------------------- 2 files changed, 2 insertions(+), 87 deletions(-) diff --git a/testng-collections/src/main/java/org/testng/util/Strings.java b/testng-collections/src/main/java/org/testng/util/Strings.java index d4ce9c2b1d..8f8f3f55a5 100644 --- a/testng-collections/src/main/java/org/testng/util/Strings.java +++ b/testng-collections/src/main/java/org/testng/util/Strings.java @@ -10,17 +10,6 @@ private Strings() { // Utility class. Defeat instantiation. } - // TODO: When TestNG moves to JDK11 as the default JDK this method needs to be deprecated and - // removed - // because now this method is present in JDK11 as part of the JDK itself. - // See - // https://hg.openjdk.java.net/jdk/jdk/file/fc16b5f193c7/src/java.base/share/classes/java/lang/String.java#l2984 - /** @deprecated - This method stands deprecated as of TestNG 7.6.0 */ - @Deprecated - public static String repeat(String text, int count) { - return text.repeat(count); - } - public static boolean isNullOrEmpty(String string) { return Optional.ofNullable(string).orElse("").trim().isEmpty(); } @@ -29,17 +18,6 @@ public static boolean isNotNullAndNotEmpty(String string) { return !isNullOrEmpty(string); } - /** - * @param string - The input String. - * @return - Returns an empty string if the input String is null (or) empty, else it - * returns back the input string. - * @deprecated - This method stands deprecated as of TestNG 7.6.0 - */ - @Deprecated - public static String getValueOrEmpty(String string) { - return Optional.ofNullable(string).orElse(""); - } - private static final Map ESCAPE_HTML_MAP = Maps.newLinkedHashMap(); static { @@ -60,8 +38,8 @@ public static String valueOf(Map m) { return m.values().stream().map(Object::toString).collect(Collectors.joining(" ")); } - /** @deprecated - This is deprecated of TestNG 7.6.0 */ - @Deprecated + // Don't remove this method. This is being called as part of the Gradle build. Removing this + // causes build to fail due to NoSuchMethodError public static String join(String delimiter, String[] parts) { return String.join(delimiter, parts); } diff --git a/testng-core/src/main/java/org/testng/reporters/Files.java b/testng-core/src/main/java/org/testng/reporters/Files.java index 8589b76fbb..3cedfb3f03 100644 --- a/testng-core/src/main/java/org/testng/reporters/Files.java +++ b/testng-core/src/main/java/org/testng/reporters/Files.java @@ -1,18 +1,9 @@ package org.testng.reporters; import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringWriter; -import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; @@ -22,63 +13,9 @@ private Files() { // defeat instantiation } - /** @deprecated - This method stands deprecated as of TestNG 7.6.0 */ - @Deprecated - public static String readFile(File f) throws IOException { - try (InputStream is = new FileInputStream(f)) { - return readFile(is); - } - } - public static String readFile(InputStream is) throws IOException { return new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)) .lines() .collect(Collectors.joining("\n")); } - - /** @deprecated - This method stands deprecated as of TestNG 7.6.0 */ - @Deprecated - public static void writeFile(String string, File f) throws IOException { - f.getParentFile().mkdirs(); - try (FileWriter fw = new FileWriter(f); - BufferedWriter bw = new BufferedWriter(fw)) { - bw.write(string); - } - } - - /** @deprecated - This method stands deprecated as of TestNG 7.6.0 */ - @Deprecated - public static void copyFile(InputStream from, File to) throws IOException { - if (!to.getParentFile().exists()) { - to.getParentFile().mkdirs(); - } - - try (OutputStream os = new FileOutputStream(to)) { - byte[] buffer = new byte[65536]; - int count = from.read(buffer); - while (count > 0) { - os.write(buffer, 0, count); - count = from.read(buffer); - } - } - } - - /** @deprecated - This method stands deprecated as of TestNG 7.6.0 */ - @Deprecated - public static String streamToString(InputStream is) throws IOException { - if (is != null) { - Writer writer = new StringWriter(); - - char[] buffer = new char[1024]; - try (Reader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { - int n; - while ((n = reader.read(buffer)) != -1) { - writer.write(buffer, 0, n); - } - } - return writer.toString(); - } else { - return ""; - } - } }