From 485876f9c2d90b211b5776567086ec0700767f3c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 14 Feb 2020 09:36:04 -0500 Subject: [PATCH] Use final. --- .../org/apache/commons/lang3/ArrayUtils.java | 22 ++--- .../org/apache/commons/lang3/ClassUtils.java | 2 +- .../org/apache/commons/lang3/Functions.java | 80 +++++++++--------- .../org/apache/commons/lang3/ObjectUtils.java | 2 +- .../org/apache/commons/lang3/Streams.java | 22 ++--- .../org/apache/commons/lang3/StringUtils.java | 8 +- .../commons/lang3/builder/EqualsBuilder.java | 2 +- .../org/apache/commons/lang3/tuple/Pair.java | 2 +- .../apache/commons/lang3/ArchUtilsTest.java | 2 +- .../apache/commons/lang3/ArrayUtilsTest.java | 82 +++++++++---------- .../apache/commons/lang3/CharRangeTest.java | 2 +- .../apache/commons/lang3/FunctionsTest.java | 36 ++++---- .../apache/commons/lang3/LocaleUtilsTest.java | 2 +- .../apache/commons/lang3/ObjectUtilsTest.java | 8 +- .../commons/lang3/RandomStringUtilsTest.java | 2 +- .../commons/lang3/SerializationUtilsTest.java | 4 +- .../org/apache/commons/lang3/StreamsTest.java | 18 ++-- .../apache/commons/lang3/StringUtilsTest.java | 14 ++-- .../apache/commons/lang3/ValidateTest.java | 4 +- .../lang3/builder/EqualsBuilderTest.java | 2 +- .../ReflectionToStringBuilderSummaryTest.java | 4 +- .../concurrent/BackgroundInitializerTest.java | 4 +- .../lang3/concurrent/ConcurrentUtilsTest.java | 22 ++--- .../EventCountCircuitBreakerTest.java | 4 +- .../MultiBackgroundInitializerTest.java | 2 +- .../commons/lang3/event/EventUtilsTest.java | 4 +- .../lang3/exception/ExceptionUtilsTest.java | 10 +-- .../commons/lang3/reflect/FieldUtilsTest.java | 12 +-- .../commons/lang3/text/StrBuilderTest.java | 16 ++-- .../lang3/text/StrSubstitutorTest.java | 4 +- .../commons/lang3/time/DateUtilsTest.java | 4 +- .../lang3/time/FastDateParserSDFTest.java | 4 +- .../time/FastDatePrinterTimeZonesTest.java | 2 +- .../commons/lang3/time/WeekYearTest.java | 4 +- .../lang3/tuple/ImmutablePairTest.java | 22 ++--- .../lang3/tuple/ImmutableTripleTest.java | 22 ++--- .../commons/lang3/tuple/MutablePairTest.java | 2 +- .../apache/commons/lang3/tuple/PairTest.java | 2 +- 38 files changed, 230 insertions(+), 230 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 3cfe46ea9..1485e0c55 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -1727,7 +1727,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final boolean[] array, final boolean valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -1778,7 +1778,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final byte[] array, final byte valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -1829,7 +1829,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final char[] array, final char valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -1901,7 +1901,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -1943,7 +1943,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -1994,7 +1994,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final float[] array, final float valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -2045,7 +2045,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final int[] array, final int valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -2096,7 +2096,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final long[] array, final long valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -2147,7 +2147,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final Object[] array, final Object objectToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -2198,7 +2198,7 @@ public class ArrayUtils { * @since 3.10 */ public static BitSet indexesOf(final short[] array, final short valueToFind, int startIndex) { - BitSet bitSet = new BitSet(); + final BitSet bitSet = new BitSet(); if (array == null) { return bitSet; @@ -3084,7 +3084,7 @@ public static int indexOf(final int[] array, final int valueToFind) { * @return Whether the given index is safely-accessible in the given array * @since 3.8 */ - public static boolean isArrayIndexValid(T[] array, int index) { + public static boolean isArrayIndexValid(final T[] array, final int index) { if (getLength(array) == 0 || array.length <= index) { return false; } diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 2b8927c53..040eb21c9 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -282,7 +282,7 @@ public class ClassUtils { * @since 3.0 * @see Class#getSimpleName() */ - public static String getSimpleName(final Class cls, String valueIfNull) { + public static String getSimpleName(final Class cls, final String valueIfNull) { return cls == null ? valueIfNull : cls.getSimpleName(); } diff --git a/src/main/java/org/apache/commons/lang3/Functions.java b/src/main/java/org/apache/commons/lang3/Functions.java index ef9c45d90..0424e1919 100644 --- a/src/main/java/org/apache/commons/lang3/Functions.java +++ b/src/main/java/org/apache/commons/lang3/Functions.java @@ -162,7 +162,7 @@ public class Functions { * @param pRunnable a {@code FailableRunnable} * @return a standard {@code Runnable} */ - public static Runnable asRunnable(FailableRunnable pRunnable) { + public static Runnable asRunnable(final FailableRunnable pRunnable) { return () -> run(pRunnable); } @@ -173,7 +173,7 @@ public class Functions { * @param pConsumer a {@code FailableConsumer} * @return a standard {@code Consumer} */ - public static Consumer asConsumer(FailableConsumer pConsumer) { + public static Consumer asConsumer(final FailableConsumer pConsumer) { return (pInput) -> accept(pConsumer, pInput); } @@ -184,7 +184,7 @@ public class Functions { * @param pCallable a {@code FailableCallable} * @return a standard {@code Callable} */ - public static Callable asCallable(FailableCallable pCallable) { + public static Callable asCallable(final FailableCallable pCallable) { return () -> call(pCallable); } @@ -196,7 +196,7 @@ public class Functions { * @param pConsumer a failable {@code BiConsumer} * @return a standard {@code BiConsumer} */ - public static BiConsumer asBiConsumer(FailableBiConsumer pConsumer) { + public static BiConsumer asBiConsumer(final FailableBiConsumer pConsumer) { return (pInput1, pInput2) -> accept(pConsumer, pInput1, pInput2); } @@ -208,7 +208,7 @@ public class Functions { * @param pFunction a {code FailableFunction} * @return a standard {@code Function} */ - public static Function asFunction(FailableFunction pFunction) { + public static Function asFunction(final FailableFunction pFunction) { return (pInput) -> apply(pFunction, pInput); } @@ -221,7 +221,7 @@ public class Functions { * @param pFunction a {@code FailableBiFunction} * @return a standard {@code BiFunction} */ - public static BiFunction asBiFunction(FailableBiFunction pFunction) { + public static BiFunction asBiFunction(final FailableBiFunction pFunction) { return (pInput1, pInput2) -> apply(pFunction, pInput1, pInput2); } @@ -232,7 +232,7 @@ public class Functions { * @param pPredicate a {@code FailablePredicate} * @return a standard {@code Predicate} */ - public static Predicate asPredicate(FailablePredicate pPredicate) { + public static Predicate asPredicate(final FailablePredicate pPredicate) { return (pInput) -> test(pPredicate, pInput); } @@ -244,7 +244,7 @@ public class Functions { * @param pPredicate a {@code FailableBiPredicate} * @return a standard {@code BiPredicate} */ - public static BiPredicate asBiPredicate(FailableBiPredicate pPredicate) { + public static BiPredicate asBiPredicate(final FailableBiPredicate pPredicate) { return (pInput1, pInput2) -> test(pPredicate, pInput1, pInput2); } @@ -255,7 +255,7 @@ public class Functions { * @param pSupplier a {@code FailableSupplier} * @return a standard {@code Supplier} */ - public static Supplier asSupplier(FailableSupplier pSupplier) { + public static Supplier asSupplier(final FailableSupplier pSupplier) { return () -> get(pSupplier); } @@ -264,10 +264,10 @@ public class Functions { * @param pRunnable The runnable to run * @param the type of checked exception the runnable may throw */ - public static void run(FailableRunnable pRunnable) { + public static void run(final FailableRunnable pRunnable) { try { pRunnable.run(); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -279,10 +279,10 @@ public class Functions { * @param the type of checked exception the callable may throw * @return the value returned from the callable */ - public static O call(FailableCallable pCallable) { + public static O call(final FailableCallable pCallable) { try { return pCallable.call(); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -294,10 +294,10 @@ public class Functions { * @param the type the consumer accepts * @param the type of checked exception the consumer may throw */ - public static void accept(FailableConsumer pConsumer, O pObject) { + public static void accept(final FailableConsumer pConsumer, final O pObject) { try { pConsumer.accept(pObject); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -311,10 +311,10 @@ public class Functions { * @param the type of the second argument the consumer accepts * @param the type of checked exception the consumer may throw */ - public static void accept(FailableBiConsumer pConsumer, O1 pObject1, O2 pObject2) { + public static void accept(final FailableBiConsumer pConsumer, final O1 pObject1, final O2 pObject2) { try { pConsumer.accept(pObject1, pObject2); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -328,10 +328,10 @@ public class Functions { * @param the type of checked exception the function may throw * @return the value returned from the function */ - public static O apply(FailableFunction pFunction, I pInput) { + public static O apply(final FailableFunction pFunction, final I pInput) { try { return pFunction.apply(pInput); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -347,10 +347,10 @@ public class Functions { * @param the type of checked exception the function may throw * @return the value returned from the function */ - public static O apply(FailableBiFunction pFunction, I1 pInput1, I2 pInput2) { + public static O apply(final FailableBiFunction pFunction, final I1 pInput1, final I2 pInput2) { try { return pFunction.apply(pInput1, pInput2); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -363,10 +363,10 @@ public class Functions { * @param the type of checked exception the predicate may throw * @return the boolean value returned by the predicate */ - public static boolean test(FailablePredicate pPredicate, O pObject) { + public static boolean test(final FailablePredicate pPredicate, final O pObject) { try { return pPredicate.test(pObject); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -381,10 +381,10 @@ public class Functions { * @param the type of checked exception the predicate may throw * @return the boolean value returned by the predicate */ - public static boolean test(FailableBiPredicate pPredicate, O1 pObject1, O2 pObject2) { + public static boolean test(final FailableBiPredicate pPredicate, final O1 pObject1, final O2 pObject2) { try { return pPredicate.test(pObject1, pObject2); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -396,10 +396,10 @@ public class Functions { * @param The type of checked exception, which the supplier can throw. * @return The object, which has been created by the supplier */ - public static O get(FailableSupplier pSupplier) { + public static O get(final FailableSupplier pSupplier) { try { return pSupplier.get(); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -416,7 +416,7 @@ public class Functions { * @param The streams element type. * @return The created {@link FailableStream}. */ - public static FailableStream stream(Stream pStream) { + public static FailableStream stream(final Stream pStream) { return new FailableStream(pStream); } @@ -433,7 +433,7 @@ public class Functions { * streams element type.) * @return The created {@link FailableStream}. */ - public static FailableStream stream(Collection pCollection) { + public static FailableStream stream(final Collection pCollection) { return new FailableStream(pCollection.stream()); } @@ -461,9 +461,9 @@ public class Functions { * @see #tryWithResources(FailableRunnable, FailableRunnable...) */ @SafeVarargs - public static void tryWithResources(FailableRunnable pAction, - FailableConsumer pErrorHandler, - FailableRunnable... pResources) { + public static void tryWithResources(final FailableRunnable pAction, + final FailableConsumer pErrorHandler, + final FailableRunnable... pResources) { final FailableConsumer errorHandler; if (pErrorHandler == null) { errorHandler = (t) -> rethrow(t); @@ -471,21 +471,21 @@ public class Functions { errorHandler = pErrorHandler; } if (pResources != null) { - for (FailableRunnable failableRunnable : pResources) { + for (final FailableRunnable failableRunnable : pResources) { Objects.requireNonNull(failableRunnable, "runnable"); } } Throwable th = null; try { pAction.run(); - } catch (Throwable t) { + } catch (final Throwable t) { th = t; } if (pResources != null) { - for (FailableRunnable runnable : pResources) { + for (final FailableRunnable runnable : pResources) { try { runnable.run(); - } catch (Throwable t) { + } catch (final Throwable t) { if (th == null) { th = t; } @@ -495,7 +495,7 @@ public class Functions { if (th != null) { try { errorHandler.accept(th); - } catch (Throwable t) { + } catch (final Throwable t) { throw rethrow(t); } } @@ -521,8 +521,8 @@ public class Functions { * @see #tryWithResources(FailableRunnable, FailableConsumer, FailableRunnable...) */ @SafeVarargs - public static void tryWithResources(FailableRunnable pAction, - FailableRunnable... pResources) { + public static void tryWithResources(final FailableRunnable pAction, + final FailableRunnable... pResources) { tryWithResources(pAction, null, pResources); } @@ -549,7 +549,7 @@ public class Functions { * @param pThrowable The throwable to rethrow possibly wrapped into an unchecked exception * @return Never returns anything, this method never terminates normally. */ - public static RuntimeException rethrow(Throwable pThrowable) { + public static RuntimeException rethrow(final Throwable pThrowable) { Objects.requireNonNull(pThrowable, "pThrowable"); if (pThrowable instanceof RuntimeException) { throw (RuntimeException) pThrowable; diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index b647c1a4a..b94c2ae74 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -238,7 +238,7 @@ public class ObjectUtils { if (suppliers != null) { for (final Supplier supplier : suppliers) { if (supplier != null) { - T value = supplier.get(); + final T value = supplier.get(); if (value != null) { return value; } diff --git a/src/main/java/org/apache/commons/lang3/Streams.java b/src/main/java/org/apache/commons/lang3/Streams.java index c097d76f3..f9d590a36 100644 --- a/src/main/java/org/apache/commons/lang3/Streams.java +++ b/src/main/java/org/apache/commons/lang3/Streams.java @@ -65,7 +65,7 @@ public class Streams { private Stream stream; private boolean terminated; - public FailableStream(Stream pStream) { + public FailableStream(final Stream pStream) { stream = pStream; } @@ -90,7 +90,7 @@ public class Streams { * element to determine if it should be included. * @return the new stream */ - public FailableStream filter(FailablePredicate pPredicate){ + public FailableStream filter(final FailablePredicate pPredicate){ assertNotTerminated(); stream = stream.filter(Functions.asPredicate(pPredicate)); return this; @@ -111,7 +111,7 @@ public class Streams { * * @param pAction a non-interfering action to perform on the elements */ - public void forEach(FailableConsumer pAction) { + public void forEach(final FailableConsumer pAction) { makeTerminated(); stream().forEach(Functions.asConsumer(pAction)); } @@ -164,7 +164,7 @@ public class Streams { * @see #collect(Supplier, BiConsumer, BiConsumer) * @see Collectors */ - public R collect(Collector pCollector) { + public R collect(final Collector pCollector) { makeTerminated(); return stream().collect(pCollector); } @@ -214,7 +214,7 @@ public class Streams { * accumulator function * @return The result of the reduction */ - public R collect(Supplier pSupplier, BiConsumer pAccumulator, BiConsumer pCombiner) { + public R collect(final Supplier pSupplier, final BiConsumer pAccumulator, final BiConsumer pCombiner) { makeTerminated(); return stream().collect(pSupplier, pAccumulator, pCombiner); } @@ -262,7 +262,7 @@ public class Streams { * function for combining two values * @return the result of the reduction */ - public O reduce(O pIdentity, BinaryOperator pAccumulator) { + public O reduce(final O pIdentity, final BinaryOperator pAccumulator) { makeTerminated(); return stream().reduce(pIdentity, pAccumulator); } @@ -277,7 +277,7 @@ public class Streams { * @param pMapper A non-interfering, stateless function to apply to each element * @return the new stream */ - public FailableStream map(FailableFunction pMapper) { + public FailableStream map(final FailableFunction pMapper) { assertNotTerminated(); return new FailableStream(stream.map(Functions.asFunction(pMapper))); } @@ -309,7 +309,7 @@ public class Streams { * @return {@code true} If either all elements of the stream match the * provided predicate or the stream is empty, otherwise {@code false}. */ - public boolean allMatch(FailablePredicate pPredicate) { + public boolean allMatch(final FailablePredicate pPredicate) { assertNotTerminated(); return stream().allMatch(Functions.asPredicate(pPredicate)); } @@ -331,7 +331,7 @@ public class Streams { * @return {@code true} if any elements of the stream match the provided * predicate, otherwise {@code false} */ - public boolean anyMatch(FailablePredicate pPredicate) { + public boolean anyMatch(final FailablePredicate pPredicate) { assertNotTerminated(); return stream().anyMatch(Functions.asPredicate(pPredicate)); } @@ -375,7 +375,7 @@ public class Streams { * @return The {@link FailableStream}, which has been created by * converting the stream. */ - public static FailableStream stream(Stream pStream) { + public static FailableStream stream(final Stream pStream) { return new FailableStream(pStream); } @@ -417,7 +417,7 @@ public class Streams { * @return The {@link FailableStream}, which has been created by * converting the stream. */ - public static FailableStream stream(Collection pStream) { + public static FailableStream stream(final Collection pStream) { return stream(pStream.stream()); } } diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 44fba32dc..2668731eb 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -535,7 +535,7 @@ public class StringUtils { * @since 2.0 */ public static String capitalize(final String str) { - int strLen = length(str); + final int strLen = length(str); if (strLen == 0) { return str; } @@ -3546,7 +3546,7 @@ public class StringUtils { * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */ public static boolean isBlank(final CharSequence cs) { - int strLen = length(cs); + final int strLen = length(cs); if (strLen == 0) { return true; } @@ -8355,7 +8355,7 @@ public class StringUtils { * @return the stripped String, {@code null} if null String input */ public static String stripStart(final String str, final String stripChars) { - int strLen = length(str); + final int strLen = length(str); if (strLen == 0) { return str; } @@ -9203,7 +9203,7 @@ public class StringUtils { * @since 2.0 */ public static String uncapitalize(final String str) { - int strLen = length(str); + final int strLen = length(str); if (strLen == 0) { return str; } diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java index 30c8a1a19..6bd105842 100644 --- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java @@ -267,7 +267,7 @@ public class EqualsBuilder implements Builder { * @return EqualsBuilder - used to chain calls. * @since 3.8 */ - public EqualsBuilder setBypassReflectionClasses(List> bypassReflectionClasses) { + public EqualsBuilder setBypassReflectionClasses(final List> bypassReflectionClasses) { this.bypassReflectionClasses = bypassReflectionClasses; return this; } diff --git a/src/main/java/org/apache/commons/lang3/tuple/Pair.java b/src/main/java/org/apache/commons/lang3/tuple/Pair.java index fda2618e8..62889bd8d 100644 --- a/src/main/java/org/apache/commons/lang3/tuple/Pair.java +++ b/src/main/java/org/apache/commons/lang3/tuple/Pair.java @@ -55,7 +55,7 @@ public abstract class Pair implements Map.Entry, Comparable range.contains(null)); + final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> range.contains(null)); assertEquals("The Range must not be null", e.getMessage()); } diff --git a/src/test/java/org/apache/commons/lang3/FunctionsTest.java b/src/test/java/org/apache/commons/lang3/FunctionsTest.java index ae6bc69d5..bec8a44b3 100644 --- a/src/test/java/org/apache/commons/lang3/FunctionsTest.java +++ b/src/test/java/org/apache/commons/lang3/FunctionsTest.java @@ -49,11 +49,11 @@ class FunctionsTest { private Throwable t; - SomeException(String pMsg) { + SomeException(final String pMsg) { super(pMsg); } - public void setThrowable(Throwable pThrowable) { + public void setThrowable(final Throwable pThrowable) { t = pThrowable; } @@ -66,11 +66,11 @@ class FunctionsTest { public static class Testable { private Throwable t; - Testable(Throwable pTh) { + Testable(final Throwable pTh) { t = pTh; } - public void setThrowable(Throwable pThrowable) { + public void setThrowable(final Throwable pThrowable) { t = pThrowable; } @@ -78,7 +78,7 @@ class FunctionsTest { test(t); } - public void test(Throwable pThrowable) throws Throwable { + public void test(final Throwable pThrowable) throws Throwable { if (pThrowable != null) { throw pThrowable; } @@ -88,7 +88,7 @@ class FunctionsTest { return testInt(t); } - public Integer testInt(Throwable pThrowable) throws Throwable { + public Integer testInt(final Throwable pThrowable) throws Throwable { if (pThrowable != null) { throw pThrowable; } @@ -117,7 +117,7 @@ class FunctionsTest { public static class CloseableObject { private boolean closed; - public void run(Throwable pTh) throws Throwable { + public void run(final Throwable pTh) throws Throwable { if (pTh != null) { throw pTh; } @@ -139,7 +139,7 @@ class FunctionsTest { @Test void testRunnable() { FailureOnOddInvocations.invocation = 0; - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -152,8 +152,8 @@ class FunctionsTest { @Test void testAsRunnable() { FailureOnOddInvocations.invocation = 0; - Runnable runnable = Functions.asRunnable(() -> new FailureOnOddInvocations()); - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run()); + final Runnable runnable = Functions.asRunnable(() -> new FailureOnOddInvocations()); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run()); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -166,7 +166,7 @@ class FunctionsTest { @Test void testCallable() { FailureOnOddInvocations.invocation = 0; - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -182,7 +182,7 @@ class FunctionsTest { return new FailureOnOddInvocations(); }; final Callable callable = Functions.asCallable(failableCallable); - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call()); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call()); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -190,7 +190,7 @@ class FunctionsTest { final FailureOnOddInvocations instance; try { instance = callable.call(); - } catch (Exception ex) { + } catch (final Exception ex) { throw Functions.rethrow(ex); } assertNotNull(instance); @@ -394,7 +394,7 @@ class FunctionsTest { @Test public void testGetFromSupplier() { FailureOnOddInvocations.invocation = 0; - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new)); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -409,7 +409,7 @@ class FunctionsTest { FailureOnOddInvocations.invocation = 0; final Functions.FailablePredicate failablePredicate = (t) -> FailureOnOddInvocations.failingBool(); final Predicate predicate = Functions.asPredicate(failablePredicate); - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null)); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null)); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -424,7 +424,7 @@ class FunctionsTest { FailureOnOddInvocations.invocation = 0; final Functions.FailableBiPredicate failableBiPredicate = (t1, t2) -> FailureOnOddInvocations.failingBool(); final BiPredicate predicate = Functions.asBiPredicate(failableBiPredicate); - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null, null)); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null, null)); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -438,7 +438,7 @@ class FunctionsTest { FailureOnOddInvocations.invocation = 0; final FailableSupplier failableSupplier = () -> new FailureOnOddInvocations(); final Supplier supplier = Functions.asSupplier(failableSupplier); - UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get()); + final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get()); final Throwable cause = e.getCause(); assertNotNull(cause); assertTrue(cause instanceof SomeException); @@ -464,7 +464,7 @@ class FunctionsTest { assertTrue(co.isClosed()); co.reset(); final IOException ioe = new IOException("Unknown I/O error"); - UncheckedIOException uioe = assertThrows(UncheckedIOException.class, () -> Functions.tryWithResources(() -> consumer.accept(ioe), co::close)); + final UncheckedIOException uioe = assertThrows(UncheckedIOException.class, () -> Functions.tryWithResources(() -> consumer.accept(ioe), co::close)); final IOException cause = uioe.getCause(); assertSame(ioe, cause); diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java index e5c140773..558b5f9cf 100644 --- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java @@ -524,7 +524,7 @@ public class LocaleUtilsTest { @ParameterizedTest @MethodSource("java.util.Locale#getAvailableLocales") - public void testParseAllLocales(Locale l) { + public void testParseAllLocales(final Locale l) { // Check if it's possible to recreate the Locale using just the standard constructor final Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant()); if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index 7fcdc4b71..373f40ca7 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -121,8 +121,8 @@ public class ObjectUtilsTest { assertSame(o, ObjectUtils.getIfNull(o, () -> dflt), "dflt was returned when o was not null"); assertSame(o, ObjectUtils.getIfNull(FOO, () -> dflt), "dflt was returned when o was not null"); assertSame(o, ObjectUtils.getIfNull("foo", () -> dflt), "dflt was returned when o was not null"); - MutableInt callsCounter = new MutableInt(0); - Supplier countingDefaultSupplier = () -> { + final MutableInt callsCounter = new MutableInt(0); + final Supplier countingDefaultSupplier = () -> { callsCounter.increment(); return dflt; }; @@ -539,7 +539,7 @@ public class ObjectUtilsTest { @Test public void testCloneOfUncloneable() { final UncloneableString string = new UncloneableString("apache"); - CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string)); + final CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.clone(string)); assertEquals(NoSuchMethodException.class, e.getCause().getClass()); } @@ -585,7 +585,7 @@ public class ObjectUtilsTest { @Test public void testPossibleCloneOfUncloneable() { final UncloneableString string = new UncloneableString("apache"); - CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string)); + final CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string)); assertEquals(NoSuchMethodException.class, e.getCause().getClass()); } diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index d18e3c887..aee483449 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -158,7 +158,7 @@ public class RandomStringUtilsTest { @Test public void testLANG807() { - IllegalArgumentException ex = + final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(3, 5, 5, false, false)); final String msg = ex.getMessage(); assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'"); diff --git a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java index d0dcaa33a..698962f26 100644 --- a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java @@ -159,7 +159,7 @@ public class SerializationUtilsTest { throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE); } }; - SerializationException e = + final SerializationException e = assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest)); assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage()); } @@ -232,7 +232,7 @@ public class SerializationUtilsTest { oos.close(); final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray()); - SerializationException se = + final SerializationException se = assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(inTest)); assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage()); } diff --git a/src/test/java/org/apache/commons/lang3/StreamsTest.java b/src/test/java/org/apache/commons/lang3/StreamsTest.java index 3ce713d93..6769c9b3c 100644 --- a/src/test/java/org/apache/commons/lang3/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/StreamsTest.java @@ -48,7 +48,7 @@ class StreamsTest { try { Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList()); fail("Expected Exception"); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { assertEquals("For input string: \"4 \"", nfe.getMessage()); } } @@ -64,7 +64,7 @@ class StreamsTest { } } - protected FailableConsumer asIntConsumer(T pThrowable) { + protected FailableConsumer asIntConsumer(final T pThrowable) { return (s) -> { final Integer i = Integer.valueOf(s); if (i.intValue() == 4) { @@ -81,7 +81,7 @@ class StreamsTest { try { Functions.stream(input).forEach(asIntConsumer(ise)); fail("Expected Exception"); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertSame(ise, e); } output.clear(); @@ -89,7 +89,7 @@ class StreamsTest { try { Functions.stream(input).forEach(asIntConsumer(oome)); fail("Expected Exception"); - } catch (Throwable t) { + } catch (final Throwable t) { assertSame(oome, t); } output.clear(); @@ -97,7 +97,7 @@ class StreamsTest { try { Functions.stream(input).forEach(asIntConsumer(se)); fail("Expected Exception"); - } catch (UndeclaredThrowableException ute) { + } catch (final UndeclaredThrowableException ute) { assertSame(se, ute.getCause()); } } @@ -121,7 +121,7 @@ class StreamsTest { } } - protected FailablePredicate asIntPredicate(T pThrowable) { + protected FailablePredicate asIntPredicate(final T pThrowable) { return (i) -> { if (i.intValue() == 5) { if (pThrowable != null) { @@ -149,7 +149,7 @@ class StreamsTest { .filter(asIntPredicate(iae)) .collect(Collectors.toList()); fail("Expected Exception"); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertSame(iae, e); } @@ -161,7 +161,7 @@ class StreamsTest { .filter(asIntPredicate(oome)) .collect(Collectors.toList()); fail("Expected Exception"); - } catch (Throwable t) { + } catch (final Throwable t) { assertSame(oome, t); } @@ -173,7 +173,7 @@ class StreamsTest { .filter(asIntPredicate(se)) .collect(Collectors.toList()); fail("Expected Exception"); - } catch (UndeclaredThrowableException t) { + } catch (final UndeclaredThrowableException t) { assertSame(se, t.getCause()); } } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 7f034c27c..e7eb5f075 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -239,7 +239,7 @@ public class StringUtilsTest { //Fixed LANG-1463 @Test public void testAbbreviateMarkerWithEmptyString() { - String greaterThanMaxTest = "much too long text"; + final String greaterThanMaxTest = "much too long text"; assertEquals("much too long", StringUtils.abbreviate(greaterThanMaxTest, "", 13)); } @@ -684,8 +684,8 @@ public class StringUtilsTest { final String s = StringUtils.getIfBlank("abc", () -> "NULL"); assertEquals("abc", s); //Checking that default value supplied only on demand - MutableInt numberOfCalls = new MutableInt(0); - Supplier countingDefaultSupplier = () -> { + final MutableInt numberOfCalls = new MutableInt(0); + final Supplier countingDefaultSupplier = () -> { numberOfCalls.increment(); return "NULL"; }; @@ -752,8 +752,8 @@ public class StringUtilsTest { final String s = StringUtils.getIfEmpty("abc", () -> "NULL"); assertEquals("abc", s); //Checking that default value supplied only on demand - MutableInt numberOfCalls = new MutableInt(0); - Supplier countingDefaultSupplier = () -> { + final MutableInt numberOfCalls = new MutableInt(0); + final Supplier countingDefaultSupplier = () -> { numberOfCalls.increment(); return "NULL"; }; @@ -3273,7 +3273,7 @@ public class StringUtilsTest { assertEquals("title", "TITLE".toLowerCase(Locale.ROOT)); assertEquals("title", StringUtils.toRootLowerCase("TITLE")); // Make sure we are not using the default Locale: - Locale defaultLocales = Locale.getDefault(); + final Locale defaultLocales = Locale.getDefault(); try { Locale.setDefault(TURKISH); assertEquals("title", StringUtils.toRootLowerCase("TITLE")); @@ -3293,7 +3293,7 @@ public class StringUtilsTest { assertEquals("TITLE", "title".toUpperCase(Locale.ROOT)); assertEquals("TITLE", StringUtils.toRootUpperCase("title")); // Make sure we are not using the default Locale: - Locale defaultLocales = Locale.getDefault(); + final Locale defaultLocales = Locale.getDefault(); try { Locale.setDefault(TURKISH); assertEquals("TITLE", StringUtils.toRootUpperCase("title")); diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java index cf1a907f3..0aa6edfdb 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -712,7 +712,7 @@ class ValidateTest { @Test void shouldReturnSameInstance() { - Set col = Collections.singleton("a"); + final Set col = Collections.singleton("a"); final Set result = Validate.noNullElements(col); assertSame(col, result); @@ -747,7 +747,7 @@ class ValidateTest { @Test void shouldReturnSameInstance() { - Set col = Collections.singleton("a"); + final Set col = Collections.singleton("a"); final Set result = Validate.noNullElements(col, "MSG"); assertSame(col, result); diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java index 061d2da0f..d487bac04 100644 --- a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java @@ -447,7 +447,7 @@ public class EqualsBuilderTest { @Test public void testObjectRecursiveGenericString() { // Note: Do not use literals, because string literals are always mapped by same object (internal() of String))! - String s1_a = String.valueOf(1); + final String s1_a = String.valueOf(1); final TestRecursiveGenericObject o1_a = new TestRecursiveGenericObject<>(s1_a); final TestRecursiveGenericObject o1_b = new TestRecursiveGenericObject<>(String.valueOf(1)); final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject<>(String.valueOf(2)); diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java index 46e2283c9..dfd549c24 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java @@ -23,10 +23,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class ReflectionToStringBuilderSummaryTest { @SuppressWarnings("unused") - private String stringField = "string"; + private final String stringField = "string"; @ToStringSummary - private String summaryString = "summary"; + private final String summaryString = "summary"; @Test public void testSummary() { diff --git a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java index cbb726de0..ecb4a160f 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/BackgroundInitializerTest.java @@ -179,7 +179,7 @@ public class BackgroundInitializerTest { final RuntimeException rex = new RuntimeException(); init.ex = rex; init.start(); - Exception ex = assertThrows(Exception.class, init::get); + final Exception ex = assertThrows(Exception.class, init::get); assertEquals(rex, ex, "Runtime exception not thrown"); } @@ -193,7 +193,7 @@ public class BackgroundInitializerTest { final Exception ex = new Exception(); init.ex = ex; init.start(); - ConcurrentException cex = assertThrows(ConcurrentException.class, init::get); + final ConcurrentException cex = assertThrows(ConcurrentException.class, init::get); assertEquals(ex, cex.getCause(), "Exception not thrown"); } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java index 8f3159bed..075c6f807 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java @@ -107,7 +107,7 @@ public class ConcurrentUtilsTest { @Test public void testExtractCauseError() { final Error err = new AssertionError("Test"); - AssertionError e = + final AssertionError e = assertThrows(AssertionError.class, () -> ConcurrentUtils.extractCause(new ExecutionException(err))); assertEquals(err, e, "Wrong error"); } @@ -154,7 +154,7 @@ public class ConcurrentUtilsTest { @Test public void testExtractCauseUncheckedError() { final Error err = new AssertionError("Test"); - Error e = assertThrows(Error.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err))); + final Error e = assertThrows(Error.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err))); assertEquals(err, e, "Wrong error"); } @@ -164,7 +164,7 @@ public class ConcurrentUtilsTest { @Test public void testExtractCauseUncheckedUncheckedException() { final RuntimeException rex = new RuntimeException("Test"); - RuntimeException r = + final RuntimeException r = assertThrows(RuntimeException.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(rex))); assertEquals(rex, r, "Wrong exception"); } @@ -186,7 +186,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseError() { final Error err = new AssertionError("Test"); - Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCause(new ExecutionException(err))); + final Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCause(new ExecutionException(err))); assertEquals(err, e, "Wrong error"); } @@ -196,7 +196,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseUncheckedException() { final RuntimeException rex = new RuntimeException("Test"); - RuntimeException r = + final RuntimeException r = assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(rex))); assertEquals(rex, r, "Wrong exception"); } @@ -207,7 +207,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseChecked() { final Exception ex = new Exception("Test"); - ConcurrentException cex = + final ConcurrentException cex = assertThrows(ConcurrentException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(ex))); assertEquals(ex, cex.getCause(), "Wrong cause"); } @@ -231,7 +231,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseUncheckedError() { final Error err = new AssertionError("Test"); - Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err))); + final Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err))); assertEquals(err, e, "Wrong error"); } @@ -241,7 +241,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseUncheckedUncheckedException() { final RuntimeException rex = new RuntimeException("Test"); - RuntimeException r = + final RuntimeException r = assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(rex))); assertEquals(rex, r, "Wrong exception"); } @@ -252,7 +252,7 @@ public class ConcurrentUtilsTest { @Test public void testHandleCauseUncheckedChecked() { final Exception ex = new Exception("Test"); - ConcurrentRuntimeException crex = + final ConcurrentRuntimeException crex = assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(ex))); assertEquals(ex, crex.getCause(), "Wrong cause"); } @@ -346,7 +346,7 @@ public class ConcurrentUtilsTest { final Exception cause = new Exception(); EasyMock.expect(init.get()).andThrow(new ConcurrentException(cause)); EasyMock.replay(init); - ConcurrentRuntimeException crex = + final ConcurrentRuntimeException crex = assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.initializeUnchecked(init)); assertSame(cause, crex.getCause(), "Wrong cause"); EasyMock.verify(init); @@ -524,7 +524,7 @@ public class ConcurrentUtilsTest { final Exception ex = new Exception(); EasyMock.expect(init.get()).andThrow(new ConcurrentException(ex)); EasyMock.replay(init); - ConcurrentRuntimeException crex = + final ConcurrentRuntimeException crex = assertThrows( ConcurrentRuntimeException.class, () -> ConcurrentUtils.createIfAbsentUnchecked(new ConcurrentHashMap<>(), "test", init)); diff --git a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java index 2819006b2..9e486952c 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java @@ -161,8 +161,8 @@ public class EventCountCircuitBreakerTest { final long timeIncrement = NANO_FACTOR / OPENING_THRESHOLD - 1; final EventCountCircuitBreakerTestImpl breaker = new EventCountCircuitBreakerTestImpl(OPENING_THRESHOLD, 1, TimeUnit.SECONDS, CLOSING_THRESHOLD, 1, TimeUnit.SECONDS); - long startTime = timeIncrement * (OPENING_THRESHOLD + 1); - boolean open = !breaker.at(startTime).incrementAndCheckState(OPENING_THRESHOLD + 1); + final long startTime = timeIncrement * (OPENING_THRESHOLD + 1); + final boolean open = !breaker.at(startTime).incrementAndCheckState(OPENING_THRESHOLD + 1); assertTrue(open, "Not open"); assertFalse(breaker.isClosed(), "Closed"); } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java index 068b5b6db..973f72b6c 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java @@ -273,7 +273,7 @@ public class MultiBackgroundInitializerTest { child.ex = new RuntimeException(); initializer.addInitializer(CHILD_INIT, child); initializer.start(); - Exception ex = assertThrows(Exception.class, initializer::get); + final Exception ex = assertThrows(Exception.class, initializer::get); assertEquals(child.ex, ex, "Wrong exception"); } diff --git a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java index 27797b2a5..1736e1380 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java @@ -69,7 +69,7 @@ public class EventUtilsTest { final PropertyChangeSource src = new PropertyChangeSource(); final EventCountingInvociationHandler handler = new EventCountingInvociationHandler(); final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class); - IllegalArgumentException e = + final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> EventUtils.addEventListener(src, ObjectChangeListener.class, listener)); assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage()); @@ -90,7 +90,7 @@ public class EventUtilsTest { final PropertyChangeSource src = new PropertyChangeSource(); final EventCountingInvociationHandler handler = new EventCountingInvociationHandler(); final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class); - IllegalArgumentException e = + final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> EventUtils.addEventListener(src, VetoableChangeListener.class, listener)); assertEquals("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".", e.getMessage()); diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java index 5eafdf308..fb7a9fbf3 100644 --- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java @@ -566,7 +566,7 @@ public class ExceptionUtilsTest { @Test public void testThrow() { final Exception expected = new InterruptedException(); - Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected)); + final Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected)); assertSame(expected, actual); } @@ -678,25 +678,25 @@ public class ExceptionUtilsTest { @Test public void testWrapAndUnwrapCheckedException() { - Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IOException())); + final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IOException())); assertTrue(ExceptionUtils.hasCause(t, IOException.class)); } @Test public void testWrapAndUnwrapError() { - Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new OutOfMemoryError())); + final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new OutOfMemoryError())); assertTrue(ExceptionUtils.hasCause(t, Error.class)); } @Test public void testWrapAndUnwrapRuntimeException() { - Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IllegalArgumentException())); + final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IllegalArgumentException())); assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class)); } @Test public void testWrapAndUnwrapThrowable() { - Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable())); + final Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable())); assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class)); } } diff --git a/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java index 291e70a20..9db1f8070 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java @@ -173,7 +173,7 @@ public class FieldUtilsTest { final Field[] allFields = FieldUtils.getAllFields(PublicChild.class); // Under Jacoco,0.8.1 and Java 10, the field count is 7. int expected = 5; - for (Field field : allFields) { + for (final Field field : allFields) { if (field.getName().equals(JACOCO_DATA_FIELD_NAME)) { expected++; } @@ -193,7 +193,7 @@ public class FieldUtilsTest { final List allFields = FieldUtils.getAllFieldsList(PublicChild.class); // Under Jacoco,0.8.1 and Java 10, the field count is 7. int expected = 5; - for (Field field : allFields) { + for (final Field field : allFields) { if (field.getName().equals(JACOCO_DATA_FIELD_NAME)) { expected++; } @@ -672,7 +672,7 @@ public class FieldUtilsTest { @Test public void testWriteStaticField() throws Exception { - Field field = StaticContainer.class.getDeclaredField("mutablePublic"); + final Field field = StaticContainer.class.getDeclaredField("mutablePublic"); FieldUtils.writeStaticField(field, "new"); assertEquals("new", StaticContainer.mutablePublic); assertThrows( @@ -830,7 +830,7 @@ public class FieldUtilsTest { @Test public void testWriteField() throws Exception { - Field field = parentClass.getDeclaredField("s"); + final Field field = parentClass.getDeclaredField("s"); FieldUtils.writeField(field, publicChild, "S"); assertEquals("S", field.get(publicChild)); assertThrows( @@ -1049,10 +1049,10 @@ public class FieldUtilsTest { * @param forceAccess {@link Boolean} to be curried into * {@link FieldUtils#removeFinalModifier(Field, boolean)}. */ - private void callRemoveFinalModifierCheckForException(Field field, Boolean forceAccess) { + private void callRemoveFinalModifierCheckForException(final Field field, final Boolean forceAccess) { try { FieldUtils.removeFinalModifier(field, forceAccess); - } catch (UnsupportedOperationException exception) { + } catch (final UnsupportedOperationException exception) { if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_12)) { assertTrue(exception.getCause() instanceof NoSuchFieldException); } else { diff --git a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java index 735b13234..cd13cdaad 100644 --- a/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java @@ -521,7 +521,7 @@ public class StrBuilderTest { final StrBuilder sb = new StrBuilder(); sb.append("junit"); - char[] a = new char[5]; + final char[] a = new char[5]; sb.getChars(0, 5, a, 0); assertArrayEquals(new char[]{'j', 'u', 'n', 'i', 't'}, a); @@ -538,7 +538,7 @@ public class StrBuilderTest { //----------------------------------------------------------------------- @Test public void testDeleteIntInt() { - StrBuilder sb = new StrBuilder("abc"); + final StrBuilder sb = new StrBuilder("abc"); sb.delete(0, 1); assertEquals("bc", sb.toString()); sb.delete(1, 2); @@ -679,7 +679,7 @@ public class StrBuilderTest { // ----------------------------------------------------------------------- @Test public void testReplace_int_int_String() { - StrBuilder sb = new StrBuilder("abc"); + final StrBuilder sb = new StrBuilder("abc"); sb.replace(0, 1, "d"); assertEquals("dbc", sb.toString()); sb.replace(0, 1, "aaa"); @@ -693,12 +693,12 @@ public class StrBuilderTest { sb.replace(0, 1000, "text"); assertEquals("text", sb.toString()); - StrBuilder sb1 = new StrBuilder("atext"); + final StrBuilder sb1 = new StrBuilder("atext"); sb1.replace(1, 1, "ny"); assertEquals("anytext", sb1.toString()); assertThrows(IndexOutOfBoundsException.class, () -> sb1.replace(2, 1, "anything")); - StrBuilder sb2 = new StrBuilder(); + final StrBuilder sb2 = new StrBuilder(); assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(1, 2, "anything")); assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(-1, 1, "anything")); } @@ -960,13 +960,13 @@ public class StrBuilderTest { sb.replace(StrMatcher.stringMatcher("aa"), "-", 10, sb.length(), -1); assertEquals("aaxaaaayaa", sb.toString()); - StrBuilder sb1 = new StrBuilder("aaxaaaayaa"); + final StrBuilder sb1 = new StrBuilder("aaxaaaayaa"); assertThrows( IndexOutOfBoundsException.class, () -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 11, sb1.length(), -1)); assertEquals("aaxaaaayaa", sb1.toString()); - StrBuilder sb2 = new StrBuilder("aaxaaaayaa"); + final StrBuilder sb2 = new StrBuilder("aaxaaaayaa"); assertThrows( IndexOutOfBoundsException.class, () -> sb2.replace(StrMatcher.stringMatcher("aa"), "-", -1, sb2.length(), -1)); @@ -1019,7 +1019,7 @@ public class StrBuilderTest { sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 1000, -1); assertEquals("-x--y-", sb.toString()); - StrBuilder sb1 = new StrBuilder("aaxaaaayaa"); + final StrBuilder sb1 = new StrBuilder("aaxaaaayaa"); assertThrows( IndexOutOfBoundsException.class, () -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 2, 1, -1)); diff --git a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java index f2f224dd0..a5879b680 100644 --- a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java +++ b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java @@ -245,7 +245,7 @@ public class StrSubstitutorTest { map.put("critterSpeed", "quick"); map.put("critterColor", "brown"); map.put("critterType", "${animal}"); - StrSubstitutor sub = new StrSubstitutor(map); + final StrSubstitutor sub = new StrSubstitutor(map); assertThrows( IllegalStateException.class, () -> sub.replace("The ${animal} jumps over the ${target}."), @@ -253,7 +253,7 @@ public class StrSubstitutorTest { // also check even when default value is set. map.put("critterType", "${animal:-fox}"); - StrSubstitutor sub2 = new StrSubstitutor(map); + final StrSubstitutor sub2 = new StrSubstitutor(map); assertThrows( IllegalStateException.class, () -> sub2.replace("The ${animal} jumps over the ${target}."), diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java index 90070d59f..64cfde87d 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java @@ -1514,10 +1514,10 @@ public class DateUtilsTest { it = DateUtils.iterator((Object) now, DateUtils.RANGE_WEEK_CENTER); assertWeekIterator(it, centered); - Iterator it2 = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER); + final Iterator it2 = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER); assertWeekIterator(it2, centered); assertThrows(NoSuchElementException.class, it2::next); - Iterator it3 = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER); + final Iterator it3 = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER); it3.next(); assertThrows(UnsupportedOperationException.class, it3::remove); diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java index e948a249f..ce8e4bf2f 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java @@ -140,7 +140,7 @@ public class FastDateParserSDFTest { checkParsePosition(input.toLowerCase(locale), format, locale, valid); } - private void checkParse(final String formattedDate, String format, Locale locale, boolean valid) { + private void checkParse(final String formattedDate, final String format, final Locale locale, final boolean valid) { final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); sdf.setTimeZone(timeZone); final DateParser fdf = new FastDateParser(format, timeZone, locale); @@ -176,7 +176,7 @@ public class FastDateParserSDFTest { assertEquals(sdfE, fdfE, locale.toString()+" "+formattedDate + " expected same Exception "); } } - private void checkParsePosition(final String formattedDate, String format, Locale locale, boolean valid) { + private void checkParsePosition(final String formattedDate, final String format, final Locale locale, final boolean valid) { final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); sdf.setTimeZone(timeZone); final DateParser fdf = new FastDateParser(format, timeZone, locale); diff --git a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java index 98a6ea535..290022922 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java @@ -37,7 +37,7 @@ public class FastDatePrinterTimeZonesTest { @ParameterizedTest @MethodSource("data") - public void testCalendarTimezoneRespected(TimeZone timeZone) { + public void testCalendarTimezoneRespected(final TimeZone timeZone) { final Calendar cal = Calendar.getInstance(timeZone); final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN); diff --git a/src/test/java/org/apache/commons/lang3/time/WeekYearTest.java b/src/test/java/org/apache/commons/lang3/time/WeekYearTest.java index ca2c71078..9a3a31741 100644 --- a/src/test/java/org/apache/commons/lang3/time/WeekYearTest.java +++ b/src/test/java/org/apache/commons/lang3/time/WeekYearTest.java @@ -54,7 +54,7 @@ public class WeekYearTest { @ParameterizedTest @MethodSource("data") - public void testParser(Calendar vulgar, String isoForm) { + public void testParser(final Calendar vulgar, final String isoForm) { final DateParser parser = new FastDateParser("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault()); final Calendar cal = Calendar.getInstance(); @@ -68,7 +68,7 @@ public class WeekYearTest { @ParameterizedTest @MethodSource("data") - public void testPrinter(Calendar vulgar, String isoForm) { + public void testPrinter(final Calendar vulgar, final String isoForm) { final FastDatePrinter printer = new FastDatePrinter("YYYY-'W'ww-u", TimeZone.getDefault(), Locale.getDefault()); vulgar.setMinimalDaysInFirstWeek(4); diff --git a/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java b/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java index 218c81419..f4e189a58 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutablePairTest.java @@ -154,7 +154,7 @@ public class ImmutablePairTest { assertNull(pair2.getLeft()); assertEquals("bar", pair2.right); assertEquals("bar", pair2.getRight()); - ImmutablePair pair3 = ImmutablePair.of(null, null); + final ImmutablePair pair3 = ImmutablePair.of(null, null); assertNull(pair3.left); assertNull(pair3.right); } @@ -182,11 +182,11 @@ public class ImmutablePairTest { @Test public void testUseAsKeyOfHashMap() { - HashMap, String> map = new HashMap<>(); - Object o1 = new Object(); - Object o2 = new Object(); - ImmutablePair key1 = ImmutablePair.of(o1, o2); - String value1 = "a1"; + final HashMap, String> map = new HashMap<>(); + final Object o1 = new Object(); + final Object o2 = new Object(); + final ImmutablePair key1 = ImmutablePair.of(o1, o2); + final String value1 = "a1"; map.put(key1, value1); assertEquals(value1, map.get(key1)); assertEquals(value1, map.get(ImmutablePair.of(o1, o2))); @@ -194,17 +194,17 @@ public class ImmutablePairTest { @Test public void testUseAsKeyOfTreeMap() { - TreeMap, String> map = new TreeMap<>(); + final TreeMap, String> map = new TreeMap<>(); map.put(ImmutablePair.of(1, 2), "12"); map.put(ImmutablePair.of(1, 1), "11"); map.put(ImmutablePair.of(0, 1), "01"); - ArrayList> expected = new ArrayList<>(); + final ArrayList> expected = new ArrayList<>(); expected.add(ImmutablePair.of(0, 1)); expected.add(ImmutablePair.of(1, 1)); expected.add(ImmutablePair.of(1, 2)); - Iterator, String>> it = map.entrySet().iterator(); - for (ImmutablePair item : expected) { - Entry, String> entry = it.next(); + final Iterator, String>> it = map.entrySet().iterator(); + for (final ImmutablePair item : expected) { + final Entry, String> entry = it.next(); assertEquals(item, entry.getKey()); assertEquals(item.getLeft() + "" + item.getRight(), entry.getValue()); } diff --git a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java index 4c6cd17fc..d6d8a64a1 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java @@ -163,12 +163,12 @@ public class ImmutableTripleTest { @Test public void testUseAsKeyOfHashMap() { - HashMap, String> map = new HashMap<>(); - Object o1 = new Object(); - Object o2 = new Object(); - Object o3 = new Object(); - ImmutableTriple key1 = ImmutableTriple.of(o1, o2, o3); - String value1 = "a1"; + final HashMap, String> map = new HashMap<>(); + final Object o1 = new Object(); + final Object o2 = new Object(); + final Object o3 = new Object(); + final ImmutableTriple key1 = ImmutableTriple.of(o1, o2, o3); + final String value1 = "a1"; map.put(key1, value1); assertEquals(value1, map.get(key1)); assertEquals(value1, map.get(ImmutableTriple.of(o1, o2, o3))); @@ -176,17 +176,17 @@ public class ImmutableTripleTest { @Test public void testUseAsKeyOfTreeMap() { - TreeMap, String> map = new TreeMap<>(); + final TreeMap, String> map = new TreeMap<>(); map.put(ImmutableTriple.of(0, 1, 2), "012"); map.put(ImmutableTriple.of(0, 1, 1), "011"); map.put(ImmutableTriple.of(0, 0, 1), "001"); - ArrayList> expected = new ArrayList<>(); + final ArrayList> expected = new ArrayList<>(); expected.add(ImmutableTriple.of(0, 0, 1)); expected.add(ImmutableTriple.of(0, 1, 1)); expected.add(ImmutableTriple.of(0, 1, 2)); - Iterator, String>> it = map.entrySet().iterator(); - for (ImmutableTriple item : expected) { - Entry, String> entry = it.next(); + final Iterator, String>> it = map.entrySet().iterator(); + for (final ImmutableTriple item : expected) { + final Entry, String> entry = it.next(); assertEquals(item, entry.getKey()); assertEquals(item.getLeft() + "" + item.getMiddle() + "" + item.getRight(), entry.getValue()); } diff --git a/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java b/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java index 731f17818..57a6d490d 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/MutablePairTest.java @@ -123,7 +123,7 @@ public class MutablePairTest { final MutablePair pair2 = MutablePair.of(null, "bar"); assertNull(pair2.getLeft()); assertEquals("bar", pair2.getRight()); - MutablePair pair3 = MutablePair.of(null, null); + final MutablePair pair3 = MutablePair.of(null, null); assertNull(pair3.left); assertNull(pair3.right); } diff --git a/src/test/java/org/apache/commons/lang3/tuple/PairTest.java b/src/test/java/org/apache/commons/lang3/tuple/PairTest.java index 6ec78ccaa..2ad4f50b6 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/PairTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/PairTest.java @@ -123,7 +123,7 @@ public class PairTest { assertTrue(pair2 instanceof ImmutablePair); assertNull(((ImmutablePair) pair2).left); assertEquals("bar", ((ImmutablePair) pair2).right); - Pair pair3 = Pair.of(null, null); + final Pair pair3 = Pair.of(null, null); assertNull(pair3.getLeft()); assertNull(pair3.getRight()); }