This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 6ed86c996 Test modernization
6ed86c996 is described below
commit 6ed86c996951bf563eadc41f0ec81555144c438f
Author: James Bognar <[email protected]>
AuthorDate: Sun Aug 24 20:49:44 2025 -0400
Test modernization
---
.../org/apache/juneau/common/internal/Utils.java | 925 +++++----------------
.../org/apache/juneau/config/store/FileStore.java | 2 +-
.../src/main/java/org/apache/juneau/Context.java | 2 -
.../main/java/org/apache/juneau/parser/Parser.java | 2 +-
.../org/apache/juneau/serializer/Serializer.java | 3 +-
.../java/org/apache/juneau/rest/RestContext.java | 8 +-
.../java/org/apache/juneau/AssertionHelpers.java | 44 +-
.../java/org/apache/juneau/BeanConfig_Test.java | 8 +-
.../org/apache/juneau/ComboRoundTripTester.java | 8 +-
.../org/apache/juneau/ComboSerializeTester.java | 2 +-
.../java/org/apache/juneau/SimpleTestBase.java | 11 +-
.../apache/juneau/assertions/Assertions_Test.java | 2 +-
.../juneau/httppart/HttpPartSchema_Body_Test.java | 3 +-
.../httppart/HttpPartSchema_FormData_Test.java | 3 +-
.../httppart/HttpPartSchema_Header_Test.java | 3 +-
.../juneau/httppart/HttpPartSchema_Path_Test.java | 3 +-
.../juneau/httppart/HttpPartSchema_Query_Test.java | 3 +-
.../HttpPartSchema_ResponseHeader_Test.java | 3 +-
.../httppart/HttpPartSchema_Response_Test.java | 3 +-
.../test/java/org/apache/juneau/json/JsonTest.java | 2 +-
.../juneau/transforms/EnumerationSwapTest.java | 1 -
.../apache/juneau/transforms/IteratorSwapTest.java | 1 -
.../juneau/transforms/OneWayStringSwapTester.java | 6 +-
.../transforms/RoundTripObjectSwapTester.java | 25 +-
.../apache/juneau/transforms/StringSwapTester.java | 10 +-
.../urlencoding/UrlEncodingSerializerTest.java | 1 -
.../java/org/apache/juneau/xml/XmlParserTest.java | 1 -
27 files changed, 261 insertions(+), 824 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
index c307b1cb9..8caf387bd 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
@@ -19,15 +19,11 @@ import java.io.*;
import java.lang.reflect.*;
import java.nio.charset.*;
-import static java.util.Optional.*;
-
import java.text.*;
-import java.time.*;
import java.time.format.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
-import java.util.regex.*;
import java.util.stream.*;
public class Utils {
@@ -36,51 +32,90 @@ public class Utils {
protected Utils() {}
/**
- * Shortcut for calling {@link Objects#hash(Object...)}.
+ * Creates an array of objects.
*/
- public static final int hash(Object...values) {
- return Objects.hash(values);
+ @SafeVarargs
+ public static <T> T[] a(T...x) {
+ return x;
}
/**
- * Prints all the specified lines to System.out.
+ * Traverses all elements in the specified object and accumulates them
into a list.
+ *
+ * @param <T> The element type.
+ * @param o The object to traverse.
+ * @param c The consumer of the objects.
*/
- public static final void printLines(String[] lines) {
- for (var i = 0; i < lines.length; i++)
- System.out.println(String.format("%4s:" + lines[i],
i+1)); // NOSONAR - NOT DEBUG
+ public static <T> List<T> accumulate(Object o) {
+ var l = list();
+ traverse(o, l::add);
+ return (List<T>) l;
}
/**
- * Shortcut for calling {@link Optional#ofNullable(Object)}.
+ * Null-safe {@link String#contains(CharSequence)} operation.
*/
- public static final <T> Optional<T> opt(T t) {
- return Optional.ofNullable(t);
+ public static boolean contains(String s, String...values) {
+ if (s == null || values == null || values.length == 0)
+ return false;
+ for (String v : values) {
+ if (s.contains(v))
+ return true;
+ }
+ return false;
}
/**
- * Converts the string to lowercase if not null.
+ * Null-safe {@link String#contains(CharSequence)} operation.
*/
- public static String lc(String s) {
- return s == null ? null : s.toLowerCase();
+ public static boolean contains(String s, char...values) {
+ if (s == null || values == null || values.length == 0)
+ return false;
+ for (char v : values) {
+ if (s.indexOf(v) >= 0)
+ return true;
+ }
+ return false;
}
/**
- * Converts the string to uppercase if not null.
+ * Returns the specified string, or blank if that string is null.
*/
- public static String uc(String s) {
- return s == null ? null : s.toUpperCase();
+ public static String emptyIfNull(String value) {
+ return value == null ? "" : value;
}
- /** Equals ignore-case */
- public static boolean eqic(Object a, Object b) {
- if (a == null && b == null) { return true; }
- if (a == null || b == null) { return false; }
- return Objects.equals(a.toString().toLowerCase(),
b.toString().toLowerCase());
+ /**
+ * Looks up a system property or environment variable.
+ *
+ * <p>
+ * First looks in system properties. Then converts the name to
env-safe and looks in the system environment.
+ * Then returns the default if it can't be found.
+ *
+ * @param <T> The type to convert the value to.
+ * @param name The property name.
+ * @param def The default value if not found.
+ * @return The default value.
+ */
+ public static <T> T env(String name, T def) {
+ return env(name).map(x -> toType(x, def)).orElse(def);
}
- /** Not equals */
- public static <T> boolean ne(T s1, T s2) {
- return ! eq(s1, s2);
+ /**
+ * Looks up a system property or environment variable.
+ *
+ * <p>
+ * First looks in system properties. Then converts the name to
env-safe and looks in the system environment.
+ * Then returns the default if it can't be found.
+ *
+ * @param name The property name.
+ * @return The value if found.
+ */
+ public static Optional<String> env(String name) {
+ String s = System.getProperty(name);
+ if (s == null)
+ s = System.getenv(envName(name));
+ return opt(s);
}
/** Equals */
@@ -115,162 +150,40 @@ public class Utils {
}
/**
- * @return True if string is null or empty.
- */
- public static boolean isEmpty(String o) {
- return o == null || o.isEmpty();
- }
-
- /**
- * @return True if string is not null or empty.
- */
- public static boolean isNotEmpty(String o) {
- return ! isEmpty(o);
- }
-
- /**
- * Splits a comma-delimited list.
- */
- public static String[] split(String s) {
- return s == null ? new String[0] : StringUtils.split(s);
- }
-
- /**
- * Splits a comma-delimited list to a stream.
- */
- public static Stream<String> splits(String s) {
- return Stream.of(isEmpty(s) ? new String[0] :
split(s)).map(String::trim);
- }
-
- /**
- * Splits a delimited list to a stream using the specified character as
the delimiter.
- */
- public static Stream<String> splits(String s, char delim) {
- return Stream.of(isEmpty(s) ? new String[0] : split(s,
delim)).map(String::trim);
- }
-
- /**
- * Splits a comma-delimited list.
- */
- public static String[] split(String s, char delim) {
- return s == null ? new String[0] : StringUtils.split(s, delim);
- }
-
- /**
- * Converts a comma-delimited string to a list.
- * @return A new modifiable list. Never null.
- */
- public static List<String> cdlToList(String s) {
- return Stream.of(isEmpty(s) ? new String[0] :
split(s)).map(String::trim).collect(toList()); // NOSONAR
- }
-
- /**
- * Converts a comma-delimited string to a set.
- * @return A new {@link LinkedHashSet}. Never null.
- */
- public static LinkedHashSet<String> cdlToSet(String s) { // NOSONAR
- return Stream.of(isEmpty(s) ? new String[0] :
split(s)).map(String::trim).collect(toCollection(LinkedHashSet::new));
- }
-
- /**
- * @return A new {@link TreeSet} copy of the specified set, or null if
the set was null.
- */
- public static <T> TreeSet<T> treeSet(Set<T> copyFrom) { // NOSONAR
- return copyFrom == null ? null : new TreeSet<>(copyFrom);
- }
-
- /**
- * @return A new {@link TreeSet} of the specified values, never null.
- */
- @SafeVarargs
- public static <T> TreeSet<T> treeSet(T...values) { // NOSONAR
- return new TreeSet<>(Arrays.asList(values));
- }
-
- /**
- * Create Calendar from...
- * - ISO date (2000-01-01T12:34:56Z)
- * - Duration (P1D)
- * - Year (2000).
- * - Short format (20000101).
- */
- public static Calendar calendar(String isoDateOrDuration) throws
IllegalArgumentException {
- try {
- var x = isoDateOrDuration.charAt(0);
- if (x == 'P' || x == '-') {
- var c =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- var duration =
Duration.parse(isoDateOrDuration).toMillis() / 1000;
- c.add(Calendar.SECOND, (int)duration);
- return c;
- }
- if (notContains(isoDateOrDuration, '-')) {
- if (isoDateOrDuration.length() == 4)
isoDateOrDuration += "0101";
- Calendar c = new
GregorianCalendar(TimeZone.getTimeZone("Z"));
-
c.setTime(SIMPLIFIED_DATE.get().parse(isoDateOrDuration));
- return c;
- }
- if (notContains(isoDateOrDuration, 'T')) {
- isoDateOrDuration += "T00:00:00Z";
- }
- var zdt =
ZonedDateTime.ofInstant(Instant.parse(isoDateOrDuration), ZoneId.of("Z"));
- return GregorianCalendar.from(zdt);
- } catch (DateTimeParseException | ParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- private static final ThreadLocal<SimpleDateFormat> SIMPLIFIED_DATE =
ThreadLocal.withInitial(Utils::newSimplifiedDate); // NOSONAR
- private static SimpleDateFormat newSimplifiedDate() {
- var df = new SimpleDateFormat("yyyyMMdd");
- df.setTimeZone(TimeZone.getTimeZone("UTC"));
- return df;
- }
-
- /**
- * Add or Subtracts number of days from Calendar given as input
- * @param c Date time
- * @param days to add or subtract
- * @return A cloned calendar with updated date as per days.
+ * Same as MessageFormat.format().
*/
- public static Calendar addSubtractDays(Calendar c, int days) {
- return ofNullable(c)
- .map(x -> (Calendar)x.clone())
- .map(x -> add(x, Calendar.DATE, days))
- .orElse(null);
+ public static String f(String pattern, Object...args) {
+ if (args.length == 0)
+ return pattern;
+ return MessageFormat.format(pattern, args);
}
/**
- * Same as {@link Integer#parseInt(String)} but removes any underscore
characters.
+ * Shortcut for calling {@link Objects#hash(Object...)}.
*/
- public static int parseInt(String value) {
- return Integer.parseInt(removeUnderscores(value));
+ public static final int hash(Object...values) {
+ return Objects.hash(values);
}
/**
- * Same as {@link Long#parseLong(String)} but removes any underscore
characters.
+ * Creates an {@link IllegalArgumentException}.
*/
- public static long parseLong(String value) {
- return Long.parseLong(removeUnderscores(value));
+ public static IllegalArgumentException illegalArg(String msg,
Object...args) {
+ return new IllegalArgumentException(args.length == 0 ? msg :
f(msg, args));
}
/**
- * Same as {@link Float#parseFloat(String)} but removes any underscore
characters.
+ * @return True if string is null or empty.
*/
- public static float parseFloat(String value) {
- return Float.parseFloat(removeUnderscores(value));
- }
-
- private static String removeUnderscores(String value) {
- if (value == null)
- throw new NullPointerException("Trying to parse null
string.");
- return (notContains(value, '_') ? value : value.replace("_",
""));
+ public static boolean isEmpty(String o) {
+ return o == null || o.isEmpty();
}
/**
- * Same as {@link Optional#ofNullable(Object)} but treats -1 as null.
+ * @return True if string is not null or empty.
*/
- public static <T extends Number> Optional<T> optional(T value) {
- return Optional.ofNullable(value).filter(x -> x.intValue() >=
0);
+ public static boolean isNotEmpty(String o) {
+ return ! isEmpty(o);
}
/**
@@ -281,32 +194,6 @@ public class Utils {
return new ArrayList<>(Arrays.asList(values));
}
- /**
- * Shortcut for creating an unmodifiable list out of an array of values.
- */
- @SafeVarargs
- public static <T> List<T> ulist(T...values) { // NOSONAR
- return Collections.unmodifiableList(Arrays.asList(values));
- }
-
- /**
- * Shortcut for creating a modifiable set out of an array of values.
- */
- @SafeVarargs
- public static <T> LinkedHashSet<T> set(T...values) { // NOSONAR
- return new LinkedHashSet<>(Arrays.asList(values));
- }
-
- /**
- * Shortcut for appending values to a set.
- */
- @SafeVarargs
- public static <T> Set<T> appendSet(Set<T> existing, T...values) {
- var existing2 = ofNullable(existing).orElse(new
LinkedHashSet<>());
- Arrays.stream(values).forEach(existing2::add);
- return existing2;
- }
-
/**
* Shortcut for creating a modifiable set out of an array of values.
*/
@@ -319,586 +206,185 @@ public class Utils {
return m;
}
- /**
- * Shortcut for adding a bunch of elements to a collection.
- */
- @SafeVarargs
- public static <E, C extends Collection<E>> C addAll(C collection,
E...elements) {
- Collections.addAll(collection, elements);
- return collection;
+ /** Not equals */
+ public static <T> boolean ne(T s1, T s2) {
+ return ! eq(s1, s2);
}
/**
- * Shortcut for adding a bunch of elements to a set.
- * If set is null, one will be created.
+ * Null-safe {@link String#contains(CharSequence)} operation.
*/
- @SafeVarargs
- public static <E> Set<E> append(Set<E> set, E...values) {
- return set == null ? set(values) : addAll(set, values);
+ public static boolean notContains(String s, char...values) {
+ return ! contains(s, values);
}
/**
- * Adds to a field of a calendar.
+ * Returns the specified string, or null if that string is null or
empty.
*/
- public static Calendar add(Calendar c, int field, int amount) {
- c.add(field, amount);
- return c;
+ public static String nullIfEmpty(String value) {
+ return isEmpty(value) ? null : value;
}
/**
- * Converts a calendar to an ISO8601 string.
+ * Returns an obfuscated version of the specified string.
*/
- public static Optional<ZonedDateTime> toZonedDateTime(Calendar c) {
- return
ofNullable(c).map(GregorianCalendar.class::cast).map(GregorianCalendar::toZonedDateTime);
+ public static String obfuscate(String s) {
+ if (s == null || s.length() < 2)
+ return "*";
+ return s.substring(0, 1) + s.substring(1).replaceAll(".", "*");
// NOSONAR
}
/**
- * Combines values into a simple comma-delimited list.
+ * Shortcut for calling {@link Optional#ofNullable(Object)}.
*/
- public static String join(String...values) {
- return StringUtils.join(values, ',');
+ public static final <T> Optional<T> opt(T t) {
+ return Optional.ofNullable(t);
}
/**
- * Combines values into a simple comma-delimited list.
+ * Prints all the specified lines to System.out.
*/
- public static String join(Collection<?> values) {
- return StringUtils.joine(new ArrayList<>(values), ',');
+ public static final void printLines(String[] lines) {
+ for (var i = 0; i < lines.length; i++)
+ System.out.println(String.format("%4s:" + lines[i],
i+1)); // NOSONAR - NOT DEBUG
}
/**
- * Calls {@link #toString()} on the specified object if it's not null.
- *
- * @param o The object to convert to a string.
- * @return The object converted to a string, or <jk>null</jk> if the
object was null.
+ * Shortcut for {@link #readable(Object)}
*/
- public static String stringify(Object o) {
- if (o instanceof Collection)
- return (String)
Collection.class.cast(o).stream().map(Utils::stringify).collect(joining(",","[","]"));
- if (o instanceof Map)
- return (String)
Map.class.cast(o).entrySet().stream().map(Utils::stringify).collect(joining(",","{","}"));
- if (o instanceof Map.Entry) {
- var e = Map.Entry.class.cast(o);
- return stringify(e.getKey()) + '=' +
stringify(e.getValue());
- }
- if (o instanceof GregorianCalendar) {
- return
GregorianCalendar.class.cast(o).toZonedDateTime().format(DateTimeFormatter.ISO_INSTANT);
- }
+ public static String r(Object o) {
+ if (o instanceof Optional<?> o2)
+ return r(o2.orElse(null));
+ if (o instanceof Collection<?> o2)
+ return
o2.stream().map(Utils::r).collect(joining(",","[","]"));
+ if (o instanceof Map<?,?> o2)
+ return
o2.entrySet().stream().map(Utils::r).collect(joining(",","{","}"));
+ if (o instanceof Map.Entry<?,?> o2)
+ return r(o2.getKey()) + '=' + r(o2.getValue());
+ if (o instanceof GregorianCalendar o2)
+ return
o2.toZonedDateTime().format(DateTimeFormatter.ISO_INSTANT);
+ if (o instanceof Date o2)
+ return o2.toInstant().toString();
+ if (o instanceof InputStream o2)
+ return toHex(o2);
+ if (o instanceof Reader o2)
+ return safe(()->IOUtils.read(o2));
+ if (o instanceof File o2)
+ return safe(()->IOUtils.read(o2));
+ if (o instanceof byte[] o2)
+ return toHex(o2);
if (o != null && o.getClass().isArray()) {
List<Object> l = list();
for (var i = 0; i < Array.getLength(o); i++) {
l.add(Array.get(o, i));
}
- return stringify(l);
+ return r(l);
}
- return StringUtils.stringify(o);
+ return s(o);
}
/**
- * Abbreviates a string if it's longer than the specified length.
- *
- * @param value The input value. Can be null.
- * @param length The max length.
- * @return An abbreviated string.
+ * Creates a {@link RuntimeException}.
*/
- public static String abbreviate(String value, int length) {
- return StringUtils.abbreviate(value, length);
+ public static RuntimeException runtimeException(String msg,
Object...args) {
+ return new RuntimeException(args.length == 0 ? msg : f(msg,
args));
}
/**
- * Searches through the cause chain of an exception to find the
exception of the nested type.
- * @param <T> The cause type.
- * @param e The exception to search.
- * @param cause The cause type.
- * @return The cause of the specified type if it was found.
+ * Shortcut for converting an object to a string.
*/
- public static <T extends Throwable> Optional<T> findCause(Throwable e,
Class<T> cause) {
- while (e != null) {
- if (cause.isInstance(e)) { return
Optional.of(cause.cast(e)); }
- e = e.getCause();
- }
- return Optional.empty();
+ public static String s(Object val) {
+ return val == null ? null : val.toString();
}
/**
- * Calulates a hash against a throwable stacktrace.
+ * Used to wrap code that returns a value but throws an exception.
+ * Useful in cases where you're trying to execute code in a fluent
method call
+ * or are trying to eliminate untestable catch blocks in code.
*/
- public static int hash(Throwable t, String stopClass) {
- var i = 0;
- while (t != null) {
- for (StackTraceElement e : t.getStackTrace()) {
- if (e.getClassName().equals(stopClass))
- break;
- if (notContains(e.getClassName(), '$'))
- i = 31*i+e.hashCode();
- }
- t = t.getCause();
+ public static <T> T safe(ThrowingSupplier<T> s) {
+ try {
+ return s.get();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- return i;
}
/**
- * Returns true if this string can be parsed by
StringUtils.parseNumber(String, Class).
+ * Shortcut for creating a modifiable set out of an array of values.
*/
- public static boolean isNumeric(String val) {
- return StringUtils.isNumeric(val);
+ @SafeVarargs
+ public static <T> LinkedHashSet<T> set(T...values) { // NOSONAR
+ return new LinkedHashSet<>(Arrays.asList(values));
}
/**
- * Returns the first string in the array that's not null and not empty.
- * Returns null if all values were empty/null.
+ * Splits a comma-delimited list into a list of strings.
*/
- public static String coalesce(String...vals) {
- for (String v : vals) {
- if (isNotEmpty(v)) {
- return v;
- }
- }
- return null;
+ public static List<String> split(String s) {
+ return s == null ? Collections.emptyList() :
StringUtils.split2(s);
}
/**
- * Returns the first object that's not null.
+ * Splits a comma-delimited list into an array of strings.
*/
- @SafeVarargs
- public static <T> T coalesce(T...vals) {
- for (T v : vals) {
- if (v != null) {
- return v;
- }
- }
- return null;
+ public static String[] splita(String s) {
+ return s == null ? new String[0] : StringUtils.split(s);
}
/**
- * Returns the specified string, or blank if that string is null.
+ * Converts an array to a stream of objects.
+ * @param array The array to convert.
+ * @return A new stream.
*/
- public static String emptyIfNull(String value) {
- return value == null ? "" : value;
- }
-
- /**
- * Returns the specified string, or null if that string is null or
empty.
- */
- public static String nullIfEmpty(String value) {
- return isEmpty(value) ? null : value;
- }
-
- /**
- * Splits a quoted comma-delimited list.
- *
- * Example: "foo","bar","baz" => ['foo','bar','baz']
- * Example: "foo","bar,baz","qux" => ['foo','bar,baz','baz']
- *
- * Handles double-quoted or unquoted entries.
- * Handles escaped characters.
- *
- * @param s The input string to split.
- * @param result Where to place the split tokens.
- * @return The same array as result.
- */
- public static ArrayList<String> splitQcd(String s, ArrayList<String>
result) { // NOSONAR
- result.clear();
- if (s == null)
- return result;
-
- if (s.length() > 1 && s.charAt(0) == '\uFEFF') s =
s.substring(1); // Remove BOM if present.
-
- s = s.trim();
-
- int
- s1 = 1, // Looking for start of token.
- s2 = 2, // Found ", looking for end "
- s3 = 3, // Found end ", looking for comma
- s4 = 4; // Found non-whitespace, looking for comma.
-
- var state = s1;
-
- boolean isInEscape = false, needsUnescape = false;
- var mark = 0;
-
- for (var i = 0; i < s.length(); i++) {
- var c = s.charAt(i);
-
- if (state == s1) {
- if (c == '"') {
- state = s2;
- mark = i+1;
- } else if (c == ',') {
- result.add("");
- } else if (c != ' ' && c != '\t') {
- state = s4;
- mark = i;
- }
- } else if (state == s2) {
- if (c == '\\') {
- isInEscape = ! isInEscape;
- needsUnescape = true;
- } else if (! isInEscape) {
- if (c == '"') {
- var x = s.substring(mark, i);
- if (needsUnescape) // NOSONAR
- x =
StringUtils.unEscapeChars(x, QUOTE_ESCAPE_SET);
- result.add(x);
- state = s3;
- isInEscape = needsUnescape =
false;
- }
- } else {
- isInEscape = false;
- }
- } else if (state == s3) {
- if (c == ',') {
- state = s1;
- }
- } else /* (state == S4) */ {
- if (c == '\\') {
- isInEscape = ! isInEscape;
- needsUnescape = true;
- } else if (! isInEscape) {
- if (c == ',') {
- var x = s.substring(mark, i);
- if (needsUnescape) // NOSONAR
- x =
StringUtils.unEscapeChars(x, COMMA_ESCAPE_SET);
- result.add(x.trim());
- state = s1;
- isInEscape = needsUnescape =
false;
- }
- } else {
- isInEscape = false;
- }
- }
- }
-
- if (state == s1) {
- result.add("");
- } else if (state == s2) {
- throw new RuntimeException("Unmatched string quotes: "
+ s);
- } else if (state == s4) {
- var x = s.substring(mark);
- if (needsUnescape)
- x = StringUtils.unEscapeChars(x,
COMMA_ESCAPE_SET);
- result.add(x.trim());
- }
-
- return result;
- }
-
- private static final AsciiSet QUOTE_ESCAPE_SET = AsciiSet.of("\"'\\");
- private static final AsciiSet COMMA_ESCAPE_SET = AsciiSet.of(",");
-
-
- /**
- * Takes a supplier of anything and turns it into a Supplier<String>.
- * Useful when passing arguments to the logger.
- */
- public static Supplier<String> stringSupplier(Supplier<?> s) {
- return () -> Utils.stringify(s.get());
- }
-
- /**
- * Throws an {@link AssertionError} if the specified actual value is
not one of the expected values.
- */
- @SafeVarargs
- public static final <T> T assertOneOf(T actual, T...expected) {
- for (T e : expected) {
- if (eq(actual,e)) return actual;
- }
- throw new AssertionError("Invalid value specified: " + actual);
- }
-
- /**
- * Creates a {@link TreeSet} collector using the specified comparator.
- */
- public static <T> Collector<T,?,TreeSet<T>> toTreeSet(Comparator<T>
comparator) {
- return Collectors.toCollection(() -> new TreeSet<>(comparator));
- }
-
- /**
- * Converts a string/object to a boolean.
- */
- public static boolean b(Object val) {
- return
ofNullable(val).map(Object::toString).map(Boolean::valueOf).orElse(false);
- }
-
- /**
- * Used to wrap code that returns a value but throws an exception.
- * Useful in cases where you're trying to execute code in a fluent
method call
- * or are trying to eliminate untestable catch blocks in code.
- */
- public static <T> T safe(ThrowingSupplier<T> s) {
- try {
- return s.get();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Used to wrap code that returns a value but throws an exception.
- * Useful in cases where you're trying to execute code in a fluent
method call
- * or are trying to eliminate untestable catch blocks in code.
- */
- public static <T> T safe(ThrowingSupplier<T> s, ThrowableLogger logger)
{
- try {
- return s.get();
- } catch (Exception e) {
- logger.log(e);
- }
- return null;
- }
-
- /**
- * Returns true if the specified number is inclusively between the two
values.
- */
- public static boolean isBetween(int n, int lower, int higher) {
- return n >= lower && n <= higher;
- }
-
- /**
- * Same as MessageFormat.format().
- */
- public static String format(String pattern, Object...args) {
- if (notContains(pattern, "{"))
- return pattern;
- return MessageFormat.format(pattern, args);
- }
-
- /**
- * Shortcut for converting an object to a string.
- */
- public static String s(Object val) {
- return val == null ? null : val.toString();
- }
-
- private static final AsciiSet ESCAPE_SET = AsciiSet.of(",=");
-
- /**
- * Shortcut for converting an object to a string.
- */
- public static String readable(Object o) {
- if (o instanceof Optional<?> o2)
- return readable(o2.orElse(null));
- if (o instanceof Collection<?> o2)
- return
o2.stream().map(Utils::readable).collect(joining(",","[","]"));
- if (o instanceof Map<?,?> o2)
- return
o2.entrySet().stream().map(Utils::readable).collect(joining(",","{","}"));
- if (o instanceof Map.Entry<?,?> o2)
- return readable(o2.getKey()) + '=' +
readable(o2.getValue());
- if (o instanceof GregorianCalendar o2)
- return
o2.toZonedDateTime().format(DateTimeFormatter.ISO_INSTANT);
- if (o instanceof Date o2)
- return o2.toInstant().toString();
- if (o instanceof InputStream o2)
- return toHex(o2);
- if (o instanceof Reader o2)
- return safe(()->IOUtils.read(o2));
- if (o instanceof File o2)
- return safe(()->IOUtils.read(o2));
- if (o instanceof byte[] o2)
- return toHex(o2);
- if (o != null && o.getClass().isArray()) {
- List<Object> l = list();
- for (var i = 0; i < Array.getLength(o); i++) {
- l.add(Array.get(o, i));
- }
- return readable(l);
- }
- return StringUtils.stringify(o);
- }
-
- /**
- * Shortcut for {@link #readable(Object)}
- */
- public static String r(Object o) {
- return readable(o);
- }
-
- /**
- * Prepends '\' to the beginning of ',' and '='.
- */
- public static String escapeChars(String val) {
- return StringUtils.escapeChars(val, ESCAPE_SET);
- }
-
- /**
- * Returns true if the specified string ends with any of the specified
characters.
- */
- public static boolean endsWith(String s, char...chars) {
- return StringUtils.endsWith(s, chars);
- }
-
- /**
- * Returns the index of the first character in the list of characters.
- */
- public static int indexOf(String s, char...chars) {
- return StringUtils.indexOf(s, chars);
- }
-
- /**
- * Adds 'a' or 'an' to the beginning of a string.
- */
- public static String articlized(String subject) {
- var p = Pattern.compile("^[AEIOUaeiou].*");
- return (p.matcher(subject).matches() ? "an " : "a ") + subject;
- }
-
- /**
- * Returns true if the specified string is null or not numeric.
- */
- public static boolean isNotNumeric(String s) {
- return ! isNumeric(s);
- }
-
- /**
- * Null-safe {@link String#contains(CharSequence)} operation.
- */
- public static boolean contains(String s, String...values) {
- if (s == null || values == null || values.length == 0)
- return false;
- for (String v : values) {
- if (s.contains(v))
- return true;
- }
- return false;
- }
-
- /**
- * Null-safe {@link String#contains(CharSequence)} operation.
- */
- public static boolean contains(String s, char...values) {
- if (s == null || values == null || values.length == 0)
- return false;
- for (char v : values) {
- if (s.indexOf(v) >= 0)
- return true;
- }
- return false;
- }
- /**
- * Null-safe {@link String#contains(CharSequence)} operation.
- */
- public static boolean notContains(String s, String...values) {
- return ! contains(s, values);
- }
-
- /**
- * Null-safe {@link String#contains(CharSequence)} operation.
- */
- public static boolean notContains(String s, char...values) {
- return ! contains(s, values);
- }
-
- /**
- * Null-safe object comparison operation.
- */
- public static int compare(Object o1, Object o2) {
- if (o1 == null && o2 == null) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- if (o1 instanceof Comparable o1c && o2 instanceof Comparable
o2c) { // NOSONAR
- return o1c.compareTo(o2c);
+ public static Stream<Object> toStream(Object array) {
+ if (array == null || ! array.getClass().isArray()) {
+ throw illegalArg("Not an array: " + array);
}
- return o1.toString().compareTo(o2.toString());
+ var length = Array.getLength(array);
+ return IntStream.range(0, length).mapToObj(i ->
Array.get(array, i));
}
/**
- * Convenience method for getting a stack trace as a string.
+ * Traverses all elements in the specified object and executes a
consumer for it.
*
- * @param t The throwable to get the stack trace from.
- * @return The same content that would normally be rendered via
<c>t.printStackTrace()</c>
- */
- public static String getStackTrace(Throwable t) {
- var sw = new StringWriter();
- try (var pw = new PrintWriter(sw)) {
- t.printStackTrace(pw);
- }
- return sw.toString();
- }
-
- /**
- * Returns an obfuscated version of the specified string.
- */
- public static String obfuscate(String s) {
- if (s == null || s.length() < 2)
- return "*";
- return s.substring(0, 1) + s.substring(1).replaceAll(".", "*");
// NOSONAR
- }
-
- /**
- * Returns a stream of strings from a comma-delimited string.
- */
- public static List<String> cdl(String value) {
- return Arrays.asList(StringUtils.split(value));
- }
-
- /**
- * Creates an {@link IllegalArgumentException}.
- */
- public static IllegalArgumentException illegalArg(String msg,
Object...args) {
- return new IllegalArgumentException(args.length == 0 ? msg :
format(msg, args));
- }
-
- /**
- * Creates a {@link RuntimeException}.
+ * @param <T> The element type.
+ * @param o The object to traverse.
+ * @param c The consumer of the objects.
*/
- public static RuntimeException runtimeException(String msg,
Object...args) {
- return new RuntimeException(args.length == 0 ? msg :
format(msg, args));
+ public static <T> void traverse(Object o, Consumer<T> c) {
+ if (o == null)
+ return;
+ if (o instanceof Iterable<?> o2)
+ o2.forEach(x -> traverse(x, c));
+ else if (o instanceof Stream<?> o2)
+ o2.forEach(x -> traverse(x, c));
+ else if (o.getClass().isArray())
+ toStream(o).forEach(x -> traverse(x, c));
+ else
+ c.accept((T)o);
}
/**
- * Creates an array of objects.
+ * Shortcut for creating an unmodifiable list out of an array of values.
*/
@SafeVarargs
- public static <T> T[] a(T...x) {
- return x;
+ public static <T> List<T> ulist(T...values) { // NOSONAR
+ return Collections.unmodifiableList(Arrays.asList(values));
}
- /**
- * Looks up a system property or environment variable.
- *
- * <p>
- * First looks in system properties. Then converts the name to
env-safe and looks in the system environment.
- * Then returns the default if it can't be found.
- *
- * @param <T> The type to convert the value to.
- * @param name The property name.
- * @param def The default value if not found.
- * @return The default value.
- */
- public static <T> T env(String name, T def) {
- return env(name).map(x -> toType(x, def)).orElse(def);
+ private static final Map<Class<?>,Function<String,?>> ENV_FUNCTIONS =
new IdentityHashMap<>();
+ static {
+ ENV_FUNCTIONS.put(Boolean.class, Boolean::valueOf);
+ ENV_FUNCTIONS.put(Charset.class, Charset::forName);
}
- /**
- * Converts an array to a stream of objects.
- * @param array The array to convert.
- * @return A new stream.
- */
- public static Stream<Object> toStream(Object array) {
- if (array == null || ! array.getClass().isArray()) {
- throw new IllegalArgumentException("Not an array: " +
array);
- }
- var length = Array.getLength(array);
- return IntStream.range(0, length).mapToObj(i ->
Array.get(array, i));
- }
+ private static final ConcurrentHashMap<String,String> PROPERTY_TO_ENV =
new ConcurrentHashMap<>();
- /**
- * Looks up a system property or environment variable.
- *
- * <p>
- * First looks in system properties. Then converts the name to
env-safe and looks in the system environment.
- * Then returns the default if it can't be found.
- *
- * @param name The property name.
- * @return The value if found.
- */
- public static Optional<String> env(String name) {
- String s = System.getProperty(name);
- if (s == null)
- s = System.getenv(envName(name));
- return opt(s);
+ private static String envName(String name) {
+ return PROPERTY_TO_ENV.computeIfAbsent(name,
x->x.toUpperCase().replace(".", "_"));
}
@SuppressWarnings("rawtypes")
@@ -916,47 +402,10 @@ public class Utils {
return f.apply(s);
}
- private static final Map<Class<?>,Function<String,?>> ENV_FUNCTIONS =
new IdentityHashMap<>();
- static {
- ENV_FUNCTIONS.put(Boolean.class, Boolean::valueOf);
- ENV_FUNCTIONS.put(Charset.class, Charset::forName);
- }
-
- private static final ConcurrentHashMap<String,String> PROPERTY_TO_ENV =
new ConcurrentHashMap<>();
- private static String envName(String name) {
- return PROPERTY_TO_ENV.computeIfAbsent(name,
x->x.toUpperCase().replace(".", "_"));
- }
-
/**
- * Traverses all elements in the specified object and executes a
consumer for it.
- *
- * @param <T> The element type.
- * @param o The object to traverse.
- * @param c The consumer of the objects.
+ * Simplified formatted string supplier with message arguments.
*/
- public static <T> void traverse(Object o, Consumer<T> c) {
- if (o == null)
- return;
- if (o instanceof Iterable<?> o2)
- o2.forEach(x -> traverse(x, c));
- else if (o instanceof Stream<?> o2)
- o2.forEach(x -> traverse(x, c));
- else if (o.getClass().isArray())
- toStream(o).forEach(x -> traverse(x, c));
- else
- c.accept((T)o);
- }
-
- /**
- * Traverses all elements in the specified object and accumulates them
into a list.
- *
- * @param <T> The element type.
- * @param o The object to traverse.
- * @param c The consumer of the objects.
- */
- public static <T> List<T> accumulate(Object o) {
- var l = list();
- traverse(o, l::add);
- return (List<T>) l;
+ public static Supplier<String> fs(String pattern, Object...args) {
+ return ()->StringUtils.format(pattern, args);
}
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/store/FileStore.java
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/store/FileStore.java
index 64c2cb825..995ac656d 100644
---
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/store/FileStore.java
+++
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/store/FileStore.java
@@ -387,7 +387,7 @@ public class FileStore extends ConfigStore {
try {
dir = new File(directory).getCanonicalFile();
dir.mkdirs();
- exts = Utils.split(extensions);
+ exts = Utils.split(extensions).toArray(String[]::new);
watcher = enableWatcher ? new WatcherThread(dir,
watcherSensitivity) : null;
if (watcher != null)
watcher.start();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index 6ef68eacf..e31ea7c38 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -24,8 +24,6 @@ import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
-import java.util.stream.*;
-
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.common.internal.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
index 338eda46c..cf92c0804 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
@@ -1036,7 +1036,7 @@ public class Parser extends BeanContextable {
unbuffered = builder.unbuffered;
listener = builder.listener;
- String[] _consumes = Utils.split(consumes != null ? consumes :
"");
+ String[] _consumes = splita(consumes != null ? consumes : "");
this.consumesArray = new MediaType[_consumes.length];
for (int i = 0; i < _consumes.length; i++) {
this.consumesArray[i] = MediaType.of(_consumes[i]);
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
index 82c164197..b6de68fbe 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/serializer/Serializer.java
@@ -23,7 +23,6 @@ import java.util.function.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
-import org.apache.juneau.common.internal.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.soap.*;
import org.apache.juneau.utils.*;
@@ -1343,7 +1342,7 @@ public class Serializer extends BeanTraverseContext {
this.producesMediaType = MediaType.of(produces);
this.acceptRanges = accept != null ? MediaRanges.of(accept) :
MediaRanges.of(produces);
- this.acceptMediaTypes = builder.accept != null ?
MediaType.ofAll(Utils.split(builder.accept)) : new MediaType[]
{this.producesMediaType};
+ this.acceptMediaTypes = builder.accept != null ?
MediaType.ofAll(splita(builder.accept)) : new MediaType[]
{this.producesMediaType};
}
@Override /* Context */
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index e8682c587..83a5002cf 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -6592,7 +6592,7 @@ public class RestContext extends Context {
try {
x.invoke(session.getBeanStore(),
session.getResource());
} catch (Exception e) {
- getLogger().log(Level.WARNING, unwrap(e),
()->Utils.format("Error occurred invoking finish-call method ''{0}''.",
x.getFullName()));
+ getLogger().log(Level.WARNING, unwrap(e),
()->Utils.f("Error occurred invoking finish-call method ''{0}''.",
x.getFullName()));
}
}
}
@@ -6658,7 +6658,7 @@ public class RestContext extends Context {
try {
x.invoke(beanStore, getResource());
} catch (Exception e) {
- getLogger().log(Level.WARNING, unwrap(e),
()->Utils.format("Error occurred invoking servlet-destroy method ''{0}''.",
x.getFullName()));
+ getLogger().log(Level.WARNING, unwrap(e),
()->Utils.f("Error occurred invoking servlet-destroy method ''{0}''.",
x.getFullName()));
}
}
@@ -6724,11 +6724,11 @@ public class RestContext extends Context {
}
static ServletException servletException(String msg, Object...args) {
- return new ServletException(Utils.format(msg, args));
+ return new ServletException(Utils.f(msg, args));
}
static ServletException servletException(Throwable t, String msg,
Object...args) {
- return new ServletException(Utils.format(msg, args), t);
+ return new ServletException(Utils.f(msg, args), t);
}
//-----------------------------------------------------------------------------------------------------------------
diff --git a/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
b/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
index b6aab3c53..442b41186 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/AssertionHelpers.java
@@ -17,7 +17,6 @@ import static java.util.stream.Collectors.*;
import static org.apache.juneau.common.internal.StringUtils.*;
import static org.apache.juneau.common.internal.StringUtils.ne;
import static org.apache.juneau.common.internal.Utils.*;
-import static org.apache.juneau.common.internal.Utils.cdl;
import static org.apache.juneau.common.internal.Utils.eq;
import static org.apache.juneau.common.internal.Utils.ne;
import static org.junit.jupiter.api.Assertions.*;
@@ -82,7 +81,7 @@ public class AssertionHelpers {
*/
public static void assertTypes(Class<?> c, Object...value) {
for (int i = 0; i < value.length; i++)
- assertTrue(c.isInstance(value[i]), ss("Incorrect type
at index [{0}].", i));
+ assertTrue(c.isInstance(value[i]), fs("Incorrect type
at index [{0}].", i));
}
/**
@@ -111,13 +110,13 @@ public class AssertionHelpers {
*/
public static void assertContains(String expected, Object actual) {
var a2 = r(actual);
- assertTrue(a2.contains(expected), ss("String did not contain
expected substring. expected={0}, actual={1}", expected, a2));
+ assertTrue(a2.contains(expected), fs("String did not contain
expected substring. expected={0}, actual={1}", expected, a2));
}
public static void assertContainsAll(String expected, Object actual) {
var a2 = r(actual);
for (var e : StringUtils.split(expected))
- assertTrue(a2.contains(e), ss("String did not contain
expected substring. expected={0}, actual={1}", e, a2));
+ assertTrue(a2.contains(e), fs("String did not contain
expected substring. expected={0}, actual={1}", e, a2));
}
public static void assertEmpty(Optional<?> o) {
@@ -135,18 +134,18 @@ public class AssertionHelpers {
if (expected.length == 1 && expected[0] instanceof String &&
s(expected[0]).contains(","))
expected = s(expected[0]).charAt(0) == '>' ? new
String[]{s(expected[0]).substring(1)} : StringUtils.split(s(expected[0]));
if (Array.getLength(array) != expected.length)
- fail(ss("Wrong array length. expected={0},
actual={1}", expected.length, Array.getLength(array)));
+ fail(fs("Wrong array length. expected={0},
actual={1}", expected.length, Array.getLength(array)));
for (var i = 0; i < expected.length; i++) {
var x = Array.get(array, i);
if (expected[i] instanceof String e) {
if (ne(r(x), e))
- fail(ss("Element at index {0} did not
match. expected={1}, actual={2}", i, e, r(x)));
+ fail(fs("Element at index {0} did not
match. expected={1}, actual={2}", i, e, r(x)));
} else if (expected[i] instanceof Predicate e) {
if (! e.test(x))
- fail(ss("Element at index {0} did pass
predicate. actual={1}", i, r(x)));
+ fail(fs("Element at index {0} did pass
predicate. actual={1}", i, r(x)));
} else {
if (ne(expected[i], x))
- fail(ss("Element at index {0} did not
match. expected={1}, actual={2}", i, r(expected[i]), r(x)));
+ fail(fs("Element at index {0} did not
match. expected={1}, actual={2}", i, r(expected[i]), r(x)));
}
}
}
@@ -158,18 +157,18 @@ public class AssertionHelpers {
if (expected.length == 1 && expected[0] instanceof String &&
s(expected[0]).contains(","))
expected = s(expected[0]).charAt(0) == '>' ? new
String[]{s(expected[0]).substring(1)} : StringUtils.split(s(expected[0]));
if (list.size() != expected.length)
- fail(ss("Wrong list length. expected={0}, actual={1}",
expected.length, list.size()));
+ fail(fs("Wrong list length. expected={0}, actual={1}",
expected.length, list.size()));
for (var i = 0; i < expected.length; i++) {
var x = list.get(i);
if (expected[i] instanceof String e) {
if (ne(r(x), e))
- fail(ss("Element at index {0} did not
match. expected={1}, actual={2}", i, e, r(x)));
+ fail(fs("Element at index {0} did not
match. expected={1}, actual={2}", i, e, r(x)));
} else if (expected[i] instanceof Predicate e) {
if (! e.test(x))
- fail(ss("Element at index {0} did pass
predicate. actual={1}", i, r(x)));
+ fail(fs("Element at index {0} did pass
predicate. actual={1}", i, r(x)));
} else {
if (ne(expected[i], x))
- fail(ss("Element at index {0} did not
match. expected={1}, actual={2}", i, r(expected[i]), r(x)));
+ fail(fs("Element at index {0} did not
match. expected={1}, actual={2}", i, r(expected[i]), r(x)));
}
}
}
@@ -180,22 +179,22 @@ public class AssertionHelpers {
public static void assertStream(Stream<?> stream, Object...expected) {
var list = stream.toList();
if (list.size() != expected.length)
- fail(ss("Wrong list length. expected={0}, actual={1}",
expected.length, list.size()));
+ fail(fs("Wrong list length. expected={0}, actual={1}",
expected.length, list.size()));
for (var i = 0; i < expected.length; i++)
if (ne(list.get(i), expected[i]))
- fail(ss("Element at index {0} did not match.
expected={1}, actual={2}", i, expected[i], r(list.get(i))));
+ fail(fs("Element at index {0} did not match.
expected={1}, actual={2}", i, expected[i], r(list.get(i))));
}
public static <T extends Throwable> T assertThrowsWithMessage(Class<T>
expectedType, String expectedSubstring,
org.junit.jupiter.api.function.Executable executable) {
T exception = Assertions.assertThrows(expectedType, executable);
var messages = getMessages(exception);
- assertTrue(messages.contains(expectedSubstring), ss("Expected
message to contain: {0}.\nActual:\n{1}", expectedSubstring, messages));
+ assertTrue(messages.contains(expectedSubstring), fs("Expected
message to contain: {0}.\nActual:\n{1}", expectedSubstring, messages));
return exception;
}
public static <T extends Throwable> T assertThrowable(Class<? extends
Throwable> expectedType, String expectedSubstring, T t) {
var messages = AssertionHelpers.getMessages(t);
- assertTrue(messages.contains(expectedSubstring), ss("Expected
message to contain: {0}.\nActual:\n{1}", expectedSubstring, messages));
+ assertTrue(messages.contains(expectedSubstring), fs("Expected
message to contain: {0}.\nActual:\n{1}", expectedSubstring, messages));
return t;
}
@@ -277,7 +276,7 @@ public class AssertionHelpers {
*/
public static void assertMap(Map<?,?> o, String fields, String value) {
if (o == null) throw new NullPointerException("Map was null");
- assertEquals(value, cdl(fields).stream().map(x ->
getReadableEntry(o, x)).collect(joining(",")));
+ assertEquals(value, Utils.split(fields).stream().map(x ->
getReadableEntry(o, x)).collect(joining(",")));
}
/**
@@ -302,14 +301,14 @@ public class AssertionHelpers {
public static void assertNotEqualsAny(Object o, Object...values) {
for (var i = 0; i < values.length; i++) {
if (eq(o, values[i]))
- fail(ss("Element at index {0} unexpectedly
matched. expected={1}, actual={2}", i, values[i], s(o)));
+ fail(fs("Element at index {0} unexpectedly
matched. expected={1}, actual={2}", i, values[i], s(o)));
}
}
public static void assertEqualsAll(Object...values) {
for (var i = 1; i < values.length; i++) {
if (ne(values[0], values[i]))
- fail(ss("Elements at index {0} and {1} did not
match.", 0, i));
+ fail(fs("Elements at index {0} and {1} did not
match.", 0, i));
}
}
@@ -362,13 +361,6 @@ public class AssertionHelpers {
return ((("get"+n).equals(mn) || ("is"+n).equals(mn)) &&
m.getParameterCount() == 0);
}
- /**
- * Simplified string supplier with message arguments.
- */
- public static Supplier<String> ss(String pattern, Object...args) {
- return ()->StringUtils.format(pattern, args);
- }
-
public static String json(Object o) {
return Json5.DEFAULT.write(o);
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/BeanConfig_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/BeanConfig_Test.java
index f77c49966..94de64bd9 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/BeanConfig_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/BeanConfig_Test.java
@@ -126,7 +126,7 @@ class BeanConfig_Test extends SimpleTestBase {
@Override /* Object */
public String toString() {
- return format("Person(name: {0}, age: {1})", name, age);
+ return f("Person(name: {0}, age: {1})", name, age);
}
}
@@ -163,7 +163,7 @@ class BeanConfig_Test extends SimpleTestBase {
@Override /* Object */
public String toString() {
- return format("Address(street: {0}, city: {1}, state:
{2}, zip: {3})", street, city, state, zip);
+ return f("Address(street: {0}, city: {1}, state: {2},
zip: {3})", street, city, state, zip);
}
}
@@ -325,7 +325,7 @@ class BeanConfig_Test extends SimpleTestBase {
@Override /* Object */
public String toString() {
- return format("toString():name={0},age={1}", name, age);
+ return f("toString():name={0},age={1}", name, age);
}
}
@@ -356,7 +356,7 @@ class BeanConfig_Test extends SimpleTestBase {
@Override /* Object */
public String toString() {
- return format("toString():name={0},age={1}", name, age);
+ return f("toString():name={0},age={1}", name, age);
}
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTester.java
b/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTester.java
index 4416be190..a271825f6 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTester.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/ComboRoundTripTester.java
@@ -78,7 +78,7 @@ public class ComboRoundTripTester<T> {
public Builder<T> verify(Function<T,String> v) { verify.add(v);
return this; }
- public Builder<T> verify(Predicate<T> p, String msg,
Object...args) { verify.add(x -> p.test(x) ? null : format(msg, args)); return
this; }
+ public Builder<T> verify(Predicate<T> p, String msg,
Object...args) { verify.add(x -> p.test(x) ? null : f(msg, args)); return this;
}
public Builder<T> swaps(Class<?>...c) { swaps.addAll(list(c));
return this; }
@@ -224,7 +224,7 @@ public class ComboRoundTripTester<T> {
System.out.println(r);
}
- assertEquals(exp, r, ss("{0}/{1} serialize-normal
failed.", label, testName));
+ assertEquals(exp, r, fs("{0}/{1} serialize-normal
failed.", label, testName));
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
@@ -248,7 +248,7 @@ public class ComboRoundTripTester<T> {
o = postConvert.apply((T)o);
r = s.serializeToString(o);
- assertEquals(exp, r, ss("{0}/{1} parse-normal failed",
label, testName));
+ assertEquals(exp, r, fs("{0}/{1} parse-normal failed",
label, testName));
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
@@ -290,7 +290,7 @@ public class ComboRoundTripTester<T> {
var r = s.serializeToString(in.get());
var o = p.parse(r, type);
r = js.serialize(o);
- assertEquals(exp, r, ss("{0}/{1} parse-normal failed on
JSON equivalency", label, testName));
+ assertEquals(exp, r, fs("{0}/{1} parse-normal failed on
JSON equivalency", label, testName));
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTester.java
b/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTester.java
index e8c1c848f..5ec259c08 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTester.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/ComboSerializeTester.java
@@ -165,7 +165,7 @@ public class ComboSerializeTester<T> {
}
}
- assertEquals(exp, r, ss("{0}/{1} serialize-normal
failed.", label, testName));
+ assertEquals(exp, r, fs("{0}/{1} serialize-normal
failed.", label, testName));
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
diff --git a/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
b/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
index ff254a94f..efc41c69f 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/SimpleTestBase.java
@@ -13,6 +13,7 @@
package org.apache.juneau;
import static org.junit.jupiter.api.Assertions.*;
+import static org.apache.juneau.common.internal.Utils.*;
import java.util.*;
import java.util.function.*;
@@ -41,7 +42,7 @@ public abstract class SimpleTestBase {
}
protected static void assertLines(String expected, Object value) {
- assertEquals(expected,
Utils.readable(value).replaceAll("\\r?\\n", "|"));
+ assertEquals(expected, r(value).replaceAll("\\r?\\n", "|"));
}
protected static <T> void assertTests(T value,
AssertionPredicate<T>...tests) {
@@ -210,7 +211,7 @@ public abstract class SimpleTestBase {
*/
protected static void assertStringEmpty(Object s) {
assertNotNull(s);
- assertTrue(Utils.readable(s).isEmpty());
+ assertTrue(r(s).isEmpty());
}
/**
@@ -285,7 +286,7 @@ public abstract class SimpleTestBase {
}
protected static void assertMatches(Object o, String pattern) throws
AssertionError {
- var text = Utils.readable(o);
+ var text = r(o);
assertTrue(StringUtils.getMatchPattern(pattern).matcher(text).matches(),
ss("Text did not match pattern.\ntext={0}", text));
}
@@ -313,7 +314,7 @@ public abstract class SimpleTestBase {
* Simplified string supplier with message arguments.
*/
public static Supplier<String> ss(String pattern, Object...args) {
- return AssertionHelpers.ss(pattern, args);
+ return Utils.fs(pattern, args);
}
public static String json(Object o) {
@@ -321,7 +322,7 @@ public abstract class SimpleTestBase {
}
public static String s(Object o) {
- return StringUtils.stringify(o);
+ return Utils.s(o);
}
@Deprecated
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/assertions/Assertions_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/assertions/Assertions_Test.java
index fede885ca..52e7d07ca 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/assertions/Assertions_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/assertions/Assertions_Test.java
@@ -175,7 +175,7 @@ public class Assertions_Test {
@Test
public void a24_assertOptional() {
- assertOptional(optional(1)).isNotNull();
+ assertOptional(Optional.of(1)).isNotNull();
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Body_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Body_Test.java
index 07d7fd4f0..103cfecd7 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Body_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Body_Test.java
@@ -777,7 +777,8 @@ class HttpPartSchema_Body_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(Content.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_FormData_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_FormData_Test.java
index 09b4a6b32..468c47b71 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_FormData_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_FormData_Test.java
@@ -873,7 +873,8 @@ class HttpPartSchema_FormData_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(FormData.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Header_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Header_Test.java
index 9f9ad8067..3c2aa5d30 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Header_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Header_Test.java
@@ -836,7 +836,8 @@ class HttpPartSchema_Header_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(Header.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Path_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Path_Test.java
index e281d7cdf..514ec8bd5 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Path_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Path_Test.java
@@ -805,7 +805,8 @@ class HttpPartSchema_Path_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(Path.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Query_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Query_Test.java
index 10cac544c..ce77d95dc 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Query_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Query_Test.java
@@ -868,7 +868,8 @@ class HttpPartSchema_Query_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(Query.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_ResponseHeader_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_ResponseHeader_Test.java
index ccf9dc18a..dff1ec4ce 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_ResponseHeader_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_ResponseHeader_Test.java
@@ -816,7 +816,8 @@ class HttpPartSchema_ResponseHeader_Test extends
SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().applyAll(Header.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Response_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Response_Test.java
index f499b2e2e..66cf72a08 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Response_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/HttpPartSchema_Response_Test.java
@@ -701,7 +701,8 @@ class HttpPartSchema_Response_Test extends SimpleTestBase {
@Test void d01a_uniqueItems_arrays() throws Exception {
var s = HttpPartSchema.create().apply(Response.class,
D01.class).build();
- String[] good = split("a,b"), bad = split("a,a");
+ var good = split("a,b");
+ var bad = split("a,a");
s.getItems().validateOutput(good, BeanContext.DEFAULT);
s.getItems().getItems().validateOutput(good,
BeanContext.DEFAULT);
diff --git a/juneau-utest/src/test/java/org/apache/juneau/json/JsonTest.java
b/juneau-utest/src/test/java/org/apache/juneau/json/JsonTest.java
index c72c84acd..92652df15 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/json/JsonTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/json/JsonTest.java
@@ -28,7 +28,7 @@ class JsonTest extends SimpleTestBase{
//====================================================================================================
@Test void testBasic() throws Exception {
var m = new LinkedHashMap<String,Object>();
- var l = new LinkedList<Object>();
+ var l = new LinkedList<>();
var s1 =
JsonSerializer.create().json5().keepNullProperties().build();
var s2 =
JsonSerializer.create().simpleAttrs().keepNullProperties().build();
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/transforms/EnumerationSwapTest.java
b/juneau-utest/src/test/java/org/apache/juneau/transforms/EnumerationSwapTest.java
index 1887b3b6c..3ed27c70b 100755
---
a/juneau-utest/src/test/java/org/apache/juneau/transforms/EnumerationSwapTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/transforms/EnumerationSwapTest.java
@@ -17,7 +17,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.json.*;
-import org.apache.juneau.serializer.*;
import org.apache.juneau.swaps.*;
import org.junit.jupiter.api.*;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/transforms/IteratorSwapTest.java
b/juneau-utest/src/test/java/org/apache/juneau/transforms/IteratorSwapTest.java
index c3b4cb816..1a80acc8c 100755
---
a/juneau-utest/src/test/java/org/apache/juneau/transforms/IteratorSwapTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/transforms/IteratorSwapTest.java
@@ -17,7 +17,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.json.*;
-import org.apache.juneau.serializer.*;
import org.apache.juneau.swaps.*;
import org.junit.jupiter.api.*;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/transforms/OneWayStringSwapTester.java
b/juneau-utest/src/test/java/org/apache/juneau/transforms/OneWayStringSwapTester.java
index 21535abb7..418f68546 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/transforms/OneWayStringSwapTester.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/transforms/OneWayStringSwapTester.java
@@ -15,8 +15,6 @@ package org.apache.juneau.transforms;
import static org.apache.juneau.common.internal.StringUtils.*;
import static org.apache.juneau.common.internal.Utils.*;
import static org.junit.jupiter.api.Assertions.*;
-import static org.apache.juneau.AssertionHelpers.*;
-
import java.util.function.*;
import org.apache.juneau.*;
@@ -90,11 +88,11 @@ public class OneWayStringSwapTester<T> {
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
} catch (Exception e) {
if (exceptionMsg == null)
throw new AssertionError("Test [" + label + "
swap] failed with exception: " + e.getLocalizedMessage(), e);
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
}
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/transforms/RoundTripObjectSwapTester.java
b/juneau-utest/src/test/java/org/apache/juneau/transforms/RoundTripObjectSwapTester.java
index 1aa86e0be..78ad53af1 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/transforms/RoundTripObjectSwapTester.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/transforms/RoundTripObjectSwapTester.java
@@ -13,9 +13,8 @@
package org.apache.juneau.transforms;
import static org.junit.jupiter.api.Assertions.*;
-import static org.apache.juneau.AssertionHelpers.*;
+import static org.apache.juneau.common.internal.Utils.*;
-import java.util.*;
import java.util.function.*;
import org.apache.juneau.*;
@@ -77,38 +76,38 @@ public class RoundTripObjectSwapTester<T,S> {
try {
var o = objectSupplier.get();
var s = swap.swap(beanSession, o);
- if (!Objects.equals(expected, s)) {
+ if (ne(expected, s)) {
fail("Test [" + label + " swap] failed.
Expected=[" + expected + "], Actual=[" + s + "]");
}
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
} catch (Exception e) {
if (exceptionMsg == null)
throw new AssertionError("Test [" + label + "
swap] failed with exception: " + e.getLocalizedMessage(), e);
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
}
}
public void testUnswap() throws Exception {
try {
- T o = objectSupplier.get();
- S s = swap.swap(beanSession, o);
- T o2 = swap.unswap(beanSession, s,
beanSession.getClassMetaForObject(o));
- S s2 = swap.swap(beanSession, o2);
- if (!Objects.equals(s, s2)) {
+ var o = objectSupplier.get();
+ var s = swap.swap(beanSession, o);
+ var o2 = swap.unswap(beanSession, s,
beanSession.getClassMetaForObject(o));
+ var s2 = swap.swap(beanSession, o2);
+ if (ne(s, s2)) {
System.err.println("s=["+s+"], o=["+o+"],
o.type=["+o.getClass().getName()+"], o2=["+o2+"],
o2.type=["+o2.getClass().getName()+"]"); // NOT DEBUG
fail("Test [" + label + " unswap] failed.
Expected=[" + s + "], Actual=[" + s2 + "]");
}
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
} catch (Exception e) {
if (exceptionMsg == null)
throw new AssertionError("Test [" + label + "
unswap] failed with exception: " + e.getLocalizedMessage(), e);
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
}
}
@@ -116,4 +115,4 @@ public class RoundTripObjectSwapTester<T,S> {
public String toString() {
return "RoundTripObjectSwapTester: " + label;
}
-}
+}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/transforms/StringSwapTester.java
b/juneau-utest/src/test/java/org/apache/juneau/transforms/StringSwapTester.java
index 3c304b0ea..9befb2d0a 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/transforms/StringSwapTester.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/transforms/StringSwapTester.java
@@ -15,8 +15,6 @@ package org.apache.juneau.transforms;
import static org.apache.juneau.common.internal.StringUtils.*;
import static org.apache.juneau.common.internal.Utils.*;
import static org.junit.jupiter.api.Assertions.*;
-import static org.apache.juneau.AssertionHelpers.*;
-
import java.util.function.*;
import org.apache.juneau.*;
@@ -89,11 +87,11 @@ public class StringSwapTester<T> {
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
} catch (Exception e) {
if (exceptionMsg == null)
throw new AssertionError("Test [" + label + "
swap] failed with exception: " + e.getLocalizedMessage(), e);
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
}
}
@@ -111,11 +109,11 @@ public class StringSwapTester<T> {
} catch (AssertionError e) {
if (exceptionMsg == null)
throw e;
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
} catch (Exception e) {
if (exceptionMsg == null)
throw new AssertionError("Test [" + label + "
unswap] failed with exception: " + e.getLocalizedMessage(), e);
- assertTrue(e.getMessage().contains(exceptionMsg),
ss("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
+ assertTrue(e.getMessage().contains(exceptionMsg),
fs("Expected exception message to contain: {0}, but was {1}.", exceptionMsg,
e.getMessage()));
}
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/UrlEncodingSerializerTest.java
b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/UrlEncodingSerializerTest.java
index 4d373baae..cab23dab6 100755
---
a/juneau-utest/src/test/java/org/apache/juneau/urlencoding/UrlEncodingSerializerTest.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/urlencoding/UrlEncodingSerializerTest.java
@@ -19,7 +19,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
-import org.apache.juneau.serializer.*;
import org.junit.jupiter.api.*;
class UrlEncodingSerializerTest extends SimpleTestBase {
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/xml/XmlParserTest.java
b/juneau-utest/src/test/java/org/apache/juneau/xml/XmlParserTest.java
index ed16baf55..ee1ebf828 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/xml/XmlParserTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/xml/XmlParserTest.java
@@ -15,7 +15,6 @@ package org.apache.juneau.xml;
import static org.junit.Assert.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
-import org.apache.juneau.parser.*;
import org.junit.jupiter.api.*;
class XmlParserTest extends SimpleTestBase {