diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java index c445e6ecc..d428162e1 100644 --- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; @@ -394,10 +393,7 @@ public class LocaleUtilsTest { break; } } - if (!found) { - fail("Could not find language: " + language - + " for country: " + country); - } + assertTrue(found, "Could not find language: " + language + " for country: " + country); } assertUnmodifiableCollection(list); } @@ -445,10 +441,7 @@ public class LocaleUtilsTest { break; } } - if (!found) { - fail("Could not find language: " + country - + " for country: " + language); - } + assertTrue(found, "Could not find language: " + country + " for country: " + language); } assertUnmodifiableCollection(list); } diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index 79d163d88..dd7aff566 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -200,10 +200,9 @@ public class RandomStringUtilsTest { } } for (int i = 0; i < testChars.length; i++) { - if (!found[i]) { - fail("alphanumeric character not generated in 1000 attempts: " - + testChars[i] +" -- repeated failures indicate a problem "); - } + assertTrue(found[i], + "alphanumeric character not generated in 1000 attempts: " + + testChars[i] + " -- repeated failures indicate a problem "); } } @@ -224,10 +223,9 @@ public class RandomStringUtilsTest { } } for (int i = 0; i < testChars.length; i++) { - if (!found[i]) { - fail("digit not generated in 1000 attempts: " - + testChars[i] +" -- repeated failures indicate a problem "); - } + assertTrue(found[i], + "digit not generated in 1000 attempts: " + testChars[i] + + " -- repeated failures indicate a problem "); } } @@ -248,10 +246,9 @@ public class RandomStringUtilsTest { } } for (int i = 0; i < testChars.length; i++) { - if (!found[i]) { - fail("alphanumeric character not generated in 1000 attempts: " - + testChars[i] +" -- repeated failures indicate a problem "); - } + assertTrue(found[i], + "alphanumeric character not generated in 1000 attempts: " + testChars[i] + + " -- repeated failures indicate a problem "); } } @@ -272,11 +269,9 @@ public class RandomStringUtilsTest { } } for (int i = 0; i < testChars.length; i++) { - if (!found[i]) { - fail("ascii character not generated in 1000 attempts: " - + (int) testChars[i] + - " -- repeated failures indicate a problem"); - } + assertTrue(found[i], + "ascii character not generated in 1000 attempts: " + (int) testChars[i] + + " -- repeated failures indicate a problem"); } } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 802ed59a6..16a4f8fb9 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; @@ -2849,18 +2848,16 @@ public class StringUtilsTest { // don't actively test for that. final Class[] params = m.getParameterTypes(); if (params.length > 0 && (params[0] == CharSequence.class || params[0] == CharSequence[].class)) { - if (!ArrayUtils.contains(excludeMethods, methodStr)) { - fail("The method \"" + methodStr + "\" appears to be mutable in spirit and therefore must not accept a CharSequence"); - } + assertTrue(!ArrayUtils.contains(excludeMethods, methodStr), + "The method \"" + methodStr + "\" appears to be mutable in spirit and therefore must not accept a CharSequence"); } } else { // Assume this is immutable in spirit and ensure the first parameter is not String. // As above, it may be something other than CharSequence. final Class[] params = m.getParameterTypes(); if (params.length > 0 && (params[0] == String.class || params[0] == String[].class)) { - if (!ArrayUtils.contains(excludeMethods, methodStr)) { - fail("The method \"" + methodStr + "\" appears to be immutable in spirit and therefore must not accept a String"); - } + assertTrue(ArrayUtils.contains(excludeMethods, methodStr), + "The method \"" + methodStr + "\" appears to be immutable in spirit and therefore must not accept a String"); } } } diff --git a/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java b/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java index 66ad0e2bb..281bdf0f3 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledExecutorService; @@ -105,9 +104,7 @@ public class TimedSemaphoreTest { int count = 0; do { Thread.sleep(PERIOD); - if (count++ > trials) { - fail("endOfPeriod() not called!"); - } + assertFalse(count++ > trials, "endOfPeriod() not called!"); } while (semaphore.getPeriodEnds() <= 0); semaphore.shutdown(); } diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index a935931e2..a819c3da6 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; @@ -1395,10 +1394,9 @@ public class NumberUtilsTest { private void compareIsCreatableWithCreateNumber(final String val, final boolean expected) { final boolean isValid = NumberUtils.isCreatable(val); final boolean canCreate = checkCreateNumber(val); - if (isValid == expected && canCreate == expected) { - return; - } - fail("Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate); + assertTrue( + isValid == expected && canCreate == expected, + "Expecting " + expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate); } /** @@ -1501,10 +1499,9 @@ public class NumberUtilsTest { private void compareIsNumberWithCreateNumber(final String val, final boolean expected) { final boolean isValid = NumberUtils.isCreatable(val); final boolean canCreate = checkCreateNumber(val); - if (isValid == expected && canCreate == expected) { - return; - } - fail("Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate); + assertTrue( + isValid == expected && canCreate == expected, + "Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate); } @Test 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 0136ecd24..e948a249f 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserSDFTest.java @@ -17,9 +17,9 @@ package org.apache.commons.lang3.time; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.text.ParseException; import java.text.ParsePosition; @@ -163,15 +163,11 @@ public class FastDateParserSDFTest { Class fdfE = null; try { actualTime = fdf.parse(formattedDate); - if (!valid) { - // failure in test - fail("Expected FDP parse to fail, but got " + actualTime); - } + // failure in test + assertTrue(valid, "Expected FDP parse to fail, but got " + actualTime); } catch (final ParseException e) { - if (valid) { - // failure in test - fail("Expected FDP parse to succeed, but got " + e); - } + // failure in test + assertFalse(valid, "Expected FDP parse to succeed, but got " + e); fdfE = e.getClass(); } if (valid) { diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java index 16efdc00e..a7647c2db 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.io.Serializable; import java.text.ParseException; @@ -444,9 +443,7 @@ public class FastDateParserTest { final SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US); sdf.setTimeZone(NEW_YORK); dsdf = sdf.parse(date); - if (shouldFail) { - fail("Expected SDF failure, but got " + dsdf + " for ["+format+","+date+"]"); - } + assertFalse(shouldFail, "Expected SDF failure, but got " + dsdf + " for ["+format+","+date+"]"); } catch (final Exception e) { s = e; if (!shouldFail) { @@ -457,9 +454,7 @@ public class FastDateParserTest { try { final DateParser fdp = getInstance(format, NEW_YORK, Locale.US); dfdp = fdp.parse(date); - if (shouldFail) { - fail("Expected FDF failure, but got " + dfdp + " for ["+format+","+date+"]"); - } + assertFalse(shouldFail, "Expected FDF failure, but got " + dfdp + " for ["+format+","+date+"]"); } catch (final Exception e) { f = e; if (!shouldFail) {