Junit 5 wip
diff --git a/pom.xml b/pom.xml
index 696bde1..b58a863 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,12 +103,24 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-junit</artifactId>
+ <version>2.0.0.0</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.11.0</version>
@@ -120,6 +132,12 @@
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.24.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/src/test/java/org/apache/maven/shared/utils/CaseTest.java b/src/test/java/org/apache/maven/shared/utils/CaseTest.java
index 113c441..5c71a6b 100644
--- a/src/test/java/org/apache/maven/shared/utils/CaseTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/CaseTest.java
@@ -20,11 +20,11 @@
import java.util.Locale;
-import org.apache.commons.text.StringEscapeUtils;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.ComparisonFailure;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case for character case changes, to precisely point the situations when character case comparison doesn't
@@ -35,7 +35,7 @@
* @author Hervé Boutemy
* @see <a href="http://sim.ivi.co/2011/07/trap-of-case-insensitive-string.html">Simple Smiles - Xuelei Fan's Blog</a>
*/
-public class CaseTest extends Assert {
+class CaseTest { // } extends Assert {
private static final Locale LOCALE_TURKISH = new Locale("tr");
/** common ASCII 'i' */
@@ -55,8 +55,8 @@
private static final Locale SAVED_DEFAULT_LOCALE = Locale.getDefault();
- @AfterClass
- public static void restoreDefaultLocale() {
+ @AfterAll
+ static void restoreDefaultLocale() {
Locale.setDefault(SAVED_DEFAULT_LOCALE);
}
@@ -65,35 +65,33 @@
* @see <a href="http://mattryall.net/blog/2009/02/the-infamous-turkish-locale-bug">The infamous Turkish locale bug</a>
*/
@Test
- public void testTurkishI() {
+ void turkishI() {
// check common i and I
- assertEquals("common lowercase i should have a dot", 'i', DOTTED_i);
- assertEquals("common uppercase I should not have a dot", 'I', DOTLESS_I);
+ assertEquals('i', DOTTED_i, "common lowercase i should have a dot");
+ assertEquals('I', DOTLESS_I, "common uppercase I should not have a dot");
final String iIıİ = "iIıİ";
// check source encoding doesn't wreck havoc */
- assertUnicodeEquals(
- "misc i directly in (UTF-8) source", iIıİ, "" + DOTTED_i + DOTLESS_I + DOTLESS_i + DOTTED_I);
+ assertEquals("" + DOTTED_i + DOTLESS_I + DOTLESS_i + DOTTED_I, "misc i directly in (UTF-8) source", iIıİ);
// check toUpperCase and toLowerCase difference with turkish and english locales
- assertUnicodeEquals(
+ assertEquals(
+ iIıİ.toUpperCase(LOCALE_TURKISH),
"'iIıİ'.toUpperCase('tr')=='İIIİ'",
- "" + DOTTED_I + DOTLESS_I + DOTLESS_I + DOTTED_I,
- iIıİ.toUpperCase(LOCALE_TURKISH));
- assertUnicodeEquals(
+ "" + DOTTED_I + DOTLESS_I + DOTLESS_I + DOTTED_I);
+ assertEquals(
+ iIıİ.toLowerCase(LOCALE_TURKISH),
"'iIıİ'.toLowerCase('tr')=='iııi'",
- "" + DOTTED_i + DOTLESS_i + DOTLESS_i + DOTTED_i,
- iIıİ.toLowerCase(LOCALE_TURKISH));
- assertUnicodeEquals(
+ "" + DOTTED_i + DOTLESS_i + DOTLESS_i + DOTTED_i);
+ assertEquals(
+ iIıİ.toUpperCase(Locale.ENGLISH),
"'iIıİ'.toUpperCase('en')=='IIIİ'",
- "" + DOTLESS_I + DOTLESS_I + DOTLESS_I + DOTTED_I,
- iIıİ.toUpperCase(Locale.ENGLISH));
+ "" + DOTLESS_I + DOTLESS_I + DOTLESS_I + DOTTED_I);
String lower = iIıİ.toLowerCase(Locale.ENGLISH); // on some platforms, ends with extra COMBINED DOT ABOVE
- assertUnicodeEquals(
- "'iIıİ'.toLowerCase('en')=='iiıi'",
- "" + DOTTED_i + DOTTED_i + DOTLESS_i + DOTTED_i + (lower.length() > 4 ? COMBINING_DOT_ABOVE : ""),
- lower);
+ String message =
+ "" + DOTTED_i + DOTTED_i + DOTLESS_i + DOTTED_i + (lower.length() > 4 ? COMBINING_DOT_ABOVE : "");
+ assertEquals(lower, "'iIıİ'.toLowerCase('en')=='iiıi'", message);
// check equalsIgnoreCase() , which has no locale
for (int i = 0; i < iIıİ.length(); i++) {
@@ -105,31 +103,16 @@
}
String current = sb.toString();
- assertTrue("'" + current + "'.equalsIgnoreCase('" + iIıİ + "')", current.equalsIgnoreCase(iIıİ));
+ assertTrue(current.equalsIgnoreCase(iIıİ), "'" + current + "'.equalsIgnoreCase('" + iIıİ + "')");
}
}
/**
- * Assert equals, and in case the result isn't as expected, display content unicode-escaped.
- * @param message
- * @param expected
- * @param actual
- */
- private void assertUnicodeEquals(String message, String expected, String actual) {
- if (expected.equals(actual)) {
- return;
- }
-
- throw new ComparisonFailure(
- message, StringEscapeUtils.escapeJava(expected), StringEscapeUtils.escapeJava(actual));
- }
-
- /**
* Test case change on all ascii characters with every available locale, to check that turkish i is the only
* exception on these characters.
*/
@Test
- public void testAsciiAvailableLocales() {
+ void asciiAvailableLocales() {
final String lower = "abcdefghijklmnopqrstuvwxyz";
final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -149,26 +132,26 @@
}
assertEquals(
- "'" + lower + "'.toUpperCase('" + locale.toString() + "')",
expectedToUpperCase,
- lower.toUpperCase(locale));
+ lower.toUpperCase(locale),
+ "'" + lower + "'.toUpperCase('" + locale.toString() + "')");
assertEquals(
- "'" + upper + "'.toLowerCase('" + locale.toString() + "')",
expectedToLowerCase,
- upper.toLowerCase(locale));
+ upper.toLowerCase(locale),
+ "'" + upper + "'.toLowerCase('" + locale.toString() + "')");
// check that toLowerCase on lower and toUpperCase on upper don't cause harm
- assertEquals("'" + lower + "'.toLowerCase('" + locale.toString() + "')", lower, lower.toLowerCase(locale));
- assertEquals("'" + upper + "'.toUpperCase('" + locale.toString() + "')", upper, upper.toUpperCase(locale));
+ assertEquals(lower, lower.toLowerCase(locale), "'" + lower + "'.toLowerCase('" + locale.toString() + "')");
+ assertEquals(upper, upper.toUpperCase(locale), "'" + upper + "'.toUpperCase('" + locale.toString() + "')");
// check equalsIgnoreCase
- assertTrue("'" + upper + "'.equalsIgnoreCase('" + lower + "')", upper.equalsIgnoreCase(lower));
+ assertTrue(upper.equalsIgnoreCase(lower), "'" + upper + "'.equalsIgnoreCase('" + lower + "')");
assertTrue(
- "'" + upper + "'.equalsIgnoreCase('" + expectedToLowerCase + "')",
- upper.equalsIgnoreCase(expectedToLowerCase));
+ upper.equalsIgnoreCase(expectedToLowerCase),
+ "'" + upper + "'.equalsIgnoreCase('" + expectedToLowerCase + "')");
assertTrue(
- "'" + expectedToUpperCase + "'.equalsIgnoreCase('" + lower + "')",
- expectedToUpperCase.equalsIgnoreCase(lower));
+ expectedToUpperCase.equalsIgnoreCase(lower),
+ "'" + expectedToUpperCase + "'.equalsIgnoreCase('" + lower + "')");
}
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/OsTest.java b/src/test/java/org/apache/maven/shared/utils/OsTest.java
index e5a321a..a7172ee 100644
--- a/src/test/java/org/apache/maven/shared/utils/OsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/OsTest.java
@@ -20,26 +20,25 @@
import java.util.Set;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests the 'Os' class which evaluates operation system specific settings.
*
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
*/
-public class OsTest {
+class OsTest {
private String origOsName;
private String origOsArch;
private String origOsVersion;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
origOsName = System.getProperty("os.name");
origOsArch = System.getProperty("os.arch");
origOsVersion = System.getProperty("os.version");
@@ -50,8 +49,8 @@
System.setProperty("os.version", "2.1.32");
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
// set the original OS settings again
System.setProperty("os.name", origOsName);
System.setProperty("os.arch", origOsArch);
@@ -59,92 +58,92 @@
}
@Test
- public void testConstructor() {
+ void constructor() {
Os os = new Os();
os.eval();
- Assert.assertTrue(Os.isName(Os.FAMILY_OS2));
+ assertTrue(Os.isName(Os.FAMILY_OS2));
- Assert.assertFalse(Os.isName(Os.FAMILY_DOS));
- Assert.assertFalse(Os.isName(Os.FAMILY_MAC));
- Assert.assertFalse(Os.isName(Os.FAMILY_NETWARE));
- Assert.assertFalse(Os.isName(Os.FAMILY_OPENVMS));
- Assert.assertFalse(Os.isName(Os.FAMILY_OS400));
- Assert.assertFalse(Os.isName(Os.FAMILY_TANDEM));
- Assert.assertFalse(Os.isName(Os.FAMILY_UNIX));
- Assert.assertFalse(Os.isName(Os.FAMILY_WIN9X));
- Assert.assertFalse(Os.isName(Os.FAMILY_WINDOWS));
- Assert.assertFalse(Os.isName(Os.FAMILY_ZOS));
+ assertFalse(Os.isName(Os.FAMILY_DOS));
+ assertFalse(Os.isName(Os.FAMILY_MAC));
+ assertFalse(Os.isName(Os.FAMILY_NETWARE));
+ assertFalse(Os.isName(Os.FAMILY_OPENVMS));
+ assertFalse(Os.isName(Os.FAMILY_OS400));
+ assertFalse(Os.isName(Os.FAMILY_TANDEM));
+ assertFalse(Os.isName(Os.FAMILY_UNIX));
+ assertFalse(Os.isName(Os.FAMILY_WIN9X));
+ assertFalse(Os.isName(Os.FAMILY_WINDOWS));
+ assertFalse(Os.isName(Os.FAMILY_ZOS));
}
@Test
- public void testFamilyNames() {
- Assert.assertEquals(Os.FAMILY_DOS, "dos");
- Assert.assertEquals(Os.FAMILY_MAC, "mac");
- Assert.assertEquals(Os.FAMILY_NETWARE, "netware");
- Assert.assertEquals(Os.FAMILY_OPENVMS, "openvms");
- Assert.assertEquals(Os.FAMILY_OS2, "os/2");
- Assert.assertEquals(Os.FAMILY_OS400, "os/400");
- Assert.assertEquals(Os.FAMILY_TANDEM, "tandem");
- Assert.assertEquals(Os.FAMILY_UNIX, "unix");
- Assert.assertEquals(Os.FAMILY_WIN9X, "win9x");
- Assert.assertEquals(Os.FAMILY_WINDOWS, "windows");
- Assert.assertEquals(Os.FAMILY_ZOS, "z/os");
+ void familyNames() {
+ assertEquals(Os.FAMILY_DOS, "dos");
+ assertEquals(Os.FAMILY_MAC, "mac");
+ assertEquals(Os.FAMILY_NETWARE, "netware");
+ assertEquals(Os.FAMILY_OPENVMS, "openvms");
+ assertEquals(Os.FAMILY_OS2, "os/2");
+ assertEquals(Os.FAMILY_OS400, "os/400");
+ assertEquals(Os.FAMILY_TANDEM, "tandem");
+ assertEquals(Os.FAMILY_UNIX, "unix");
+ assertEquals(Os.FAMILY_WIN9X, "win9x");
+ assertEquals(Os.FAMILY_WINDOWS, "windows");
+ assertEquals(Os.FAMILY_ZOS, "z/os");
}
@Test
- public void testGetValidFamilies() {
+ void getValidFamilies() {
Set<String> osFamilies = Os.getValidFamilies();
- Assert.assertTrue("OsFamilies Set size", osFamilies.size() >= 11);
+ assertTrue(osFamilies.size() >= 11, "OsFamilies Set size");
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_DOS));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_MAC));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_NETWARE));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_OPENVMS));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS2));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS400));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_TANDEM));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_UNIX));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_WIN9X));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_WINDOWS));
- Assert.assertTrue(osFamilies.contains(Os.FAMILY_ZOS));
+ assertTrue(osFamilies.contains(Os.FAMILY_DOS));
+ assertTrue(osFamilies.contains(Os.FAMILY_MAC));
+ assertTrue(osFamilies.contains(Os.FAMILY_NETWARE));
+ assertTrue(osFamilies.contains(Os.FAMILY_OPENVMS));
+ assertTrue(osFamilies.contains(Os.FAMILY_OS2));
+ assertTrue(osFamilies.contains(Os.FAMILY_OS400));
+ assertTrue(osFamilies.contains(Os.FAMILY_TANDEM));
+ assertTrue(osFamilies.contains(Os.FAMILY_UNIX));
+ assertTrue(osFamilies.contains(Os.FAMILY_WIN9X));
+ assertTrue(osFamilies.contains(Os.FAMILY_WINDOWS));
+ assertTrue(osFamilies.contains(Os.FAMILY_ZOS));
}
@Test
- public void testIsArch() {
- assertThat("Arch is i386", Os.isArch("i386"), is(true));
+ void isArch() {
+ assertThat(Os.isArch("i386")).as("Arch is i386").isEqualTo(true);
- assertThat("Os is not Mac", Os.isArch("x86_64"), is(false));
+ assertThat(Os.isArch("x86_64")).as("Os is not Mac").isEqualTo(false);
}
@Test
- public void testIsFamily() {
- assertThat("Family is os/2", Os.isFamily(Os.FAMILY_OS2), is(true));
+ void isFamily() {
+ assertThat(Os.isFamily(Os.FAMILY_OS2)).as("Family is os/2").isEqualTo(true);
- assertThat("Family is not mac", Os.isFamily(Os.FAMILY_MAC), is(false));
+ assertThat(Os.isFamily(Os.FAMILY_MAC)).as("Family is not mac").isEqualTo(false);
}
@Test
- public void testIsName() {
- assertThat("Name is os/2", Os.isName("os/2"), is(true));
+ void isName() {
+ assertThat(Os.isName("os/2")).as("Name is os/2").isEqualTo(true);
- assertThat("Name is not Mac OS X", Os.isName("Mac OS X"), is(false));
+ assertThat(Os.isName("Mac OS X")).as("Name is not Mac OS X").isEqualTo(false);
}
@Test
- public void testIsValidFamily() {
- assertThat("os/2 isValidFamily", Os.isValidFamily(Os.FAMILY_OS2), is(true));
+ void isValidFamily() {
+ assertThat(Os.isValidFamily(Os.FAMILY_OS2)).as("os/2 isValidFamily").isEqualTo(true);
- assertThat("iPone != isValidFamily", Os.isValidFamily("iPhone"), is(false));
+ assertThat(Os.isValidFamily("iPhone")).as("iPone != isValidFamily").isEqualTo(false);
}
@Test
- public void testIsVersion() {
- assertThat("isVersion", Os.isVersion("2.1.32"), is(true));
+ void isVersion() {
+ assertThat(Os.isVersion("2.1.32")).as("isVersion").isEqualTo(true);
- assertThat("isVersion", Os.isVersion("2.1"), is(false));
+ assertThat(Os.isVersion("2.1")).as("isVersion").isEqualTo(false);
- assertThat("isVersion", Os.isVersion("4.5"), is(false));
+ assertThat(Os.isVersion("4.5")).as("isVersion").isEqualTo(false);
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/PathToolTest.java b/src/test/java/org/apache/maven/shared/utils/PathToolTest.java
index 3aa0da3..a43ea62 100644
--- a/src/test/java/org/apache/maven/shared/utils/PathToolTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/PathToolTest.java
@@ -20,14 +20,13 @@
import java.io.File;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assume;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.io.TempDir;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.condition.OS.WINDOWS;
/**
* Test the {@link PathTool} class.
@@ -36,88 +35,96 @@
*/
public class PathToolTest {
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir
+ public File tempFolder;
- @Test
// Keep in sync with testGetRelativeFilePath_Windows()
- public void testGetRelativeFilePath_NonWindows() {
- Assume.assumeThat(File.separatorChar, is('/'));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void getRelativeFilePath_NonWindows() {
+ assertThat(PathTool.getRelativeFilePath(null, null)).isEqualTo("");
- assertThat(PathTool.getRelativeFilePath(null, null), is(""));
+ assertThat(PathTool.getRelativeFilePath(null, "/usr/local/java/bin")).isEqualTo("");
- assertThat(PathTool.getRelativeFilePath(null, "/usr/local/java/bin"), is(""));
+ assertThat(PathTool.getRelativeFilePath("/usr/local", null)).isEqualTo("");
- assertThat(PathTool.getRelativeFilePath("/usr/local", null), is(""));
+ assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"))
+ .isEqualTo("java/bin");
- assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"), is("java/bin"));
+ assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"))
+ .isEqualTo("java/bin/");
- assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"), is("java/bin/"));
+ assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"))
+ .isEqualTo("../../");
- assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"), is("../../"));
+ assertThat(PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"))
+ .isEqualTo("java/bin/java.sh");
- assertThat(PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("java/bin/java.sh"));
+ assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"))
+ .isEqualTo("../../../");
- assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"), is("../../../"));
+ assertThat(PathTool.getRelativeFilePath("/usr/local/", "/bin")).isEqualTo("../../bin");
- assertThat(PathTool.getRelativeFilePath("/usr/local/", "/bin"), is("../../bin"));
-
- assertThat(PathTool.getRelativeFilePath("/bin", "/usr/local/"), is("../usr/local/"));
+ assertThat(PathTool.getRelativeFilePath("/bin", "/usr/local/")).isEqualTo("../usr/local/");
}
- @Test
// Keep in sync with testGetRelativeFilePath_NonWindows()
- public void testGetRelativeFilePath_Windows() {
- Assume.assumeThat(File.separatorChar, is('\\'));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void getRelativeFilePath_Windows() {
+ assertThat(PathTool.getRelativeFilePath(null, null)).isEqualTo("");
- assertThat(PathTool.getRelativeFilePath(null, null), is(""));
+ assertThat(PathTool.getRelativeFilePath(null, "c:\\usr\\local\\java\\bin"))
+ .isEqualTo("");
- assertThat(PathTool.getRelativeFilePath(null, "c:\\usr\\local\\java\\bin"), is(""));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", null)).isEqualTo("");
- assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", null), is(""));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin"))
+ .isEqualTo("java\\bin");
- assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin"), is("java\\bin"));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin\\"))
+ .isEqualTo("java\\bin\\");
- assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin\\"), is("java\\bin\\"));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin", "c:\\usr\\local\\"))
+ .isEqualTo("..\\..\\");
- assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin", "c:\\usr\\local\\"), is("..\\..\\"));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\usr\\local\\java\\bin\\java.sh"))
+ .isEqualTo("java\\bin\\java.sh");
- assertThat(
- PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\usr\\local\\java\\bin\\java.sh"),
- is("java\\bin\\java.sh"));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin\\java.sh", "c:\\usr\\local\\"))
+ .isEqualTo("..\\..\\..\\");
- assertThat(
- PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin\\java.sh", "c:\\usr\\local\\"),
- is("..\\..\\..\\"));
+ assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\bin")).isEqualTo("..\\..\\bin");
- assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\bin"), is("..\\..\\bin"));
-
- assertThat(PathTool.getRelativeFilePath("c:\\bin", "c:\\usr\\local\\"), is("..\\usr\\local\\"));
+ assertThat(PathTool.getRelativeFilePath("c:\\bin", "c:\\usr\\local\\")).isEqualTo("..\\usr\\local\\");
}
@Test
- public void testGetRelativePath_2parm() {
- assertThat(PathTool.getRelativePath(null, null), is(""));
+ void getRelativePath_2parm() {
+ assertThat(PathTool.getRelativePath(null, null)).isEqualTo("");
- assertThat(PathTool.getRelativePath(null, "/usr/local/java/bin"), is(""));
+ assertThat(PathTool.getRelativePath(null, "/usr/local/java/bin")).isEqualTo("");
- assertThat(PathTool.getRelativePath("/usr/local/", null), is(""));
+ assertThat(PathTool.getRelativePath("/usr/local/", null)).isEqualTo("");
- assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"), is(".."));
+ assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"))
+ .isEqualTo("..");
- assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("../.."));
+ assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"))
+ .isEqualTo("../..");
- assertThat(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"), is(""));
+ assertThat(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"))
+ .isEqualTo("");
}
@Test
- public void testUppercaseDrive() {
- assertThat(PathTool.uppercaseDrive(null), CoreMatchers.nullValue());
+ void uppercaseDrive() {
+ assertThat(PathTool.uppercaseDrive(null)).isNull();
- assertThat(PathTool.uppercaseDrive("d:"), is("D:"));
+ assertThat(PathTool.uppercaseDrive("d:")).isEqualTo("D:");
- assertThat(PathTool.uppercaseDrive("D:"), is("D:"));
+ assertThat(PathTool.uppercaseDrive("D:")).isEqualTo("D:");
- assertThat(PathTool.uppercaseDrive("/notadrive"), is("/notadrive"));
+ assertThat(PathTool.uppercaseDrive("/notadrive")).isEqualTo("/notadrive");
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java
index 24940a9..bee37f4 100644
--- a/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java
@@ -32,13 +32,10 @@
import java.net.URL;
import java.util.Properties;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
public class PropertyUtilsTest {
@@ -46,116 +43,122 @@
@Target(ElementType.METHOD)
@interface NeedsTemporaryFolder {}
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir
+ public File tempFolder;
- @Test
- @SuppressWarnings("deprecation")
// @ReproducesPlexusBug( "Should return null on error like url and file do" )
- public void loadNullInputStream() throws Exception {
- assertThat(PropertyUtils.loadProperties((InputStream) null), is(new Properties()));
+ @Test
+ @SuppressWarnings("deprecation")
+ void loadNullInputStream() throws Exception {
+ assertThat(PropertyUtils.loadProperties((InputStream) null)).isEqualTo(new Properties());
}
@Test
- public void loadOptionalNullInputStream() throws Exception {
- assertThat(PropertyUtils.loadOptionalProperties((InputStream) null), is(new Properties()));
+ void loadOptionalNullInputStream() throws Exception {
+ assertThat(PropertyUtils.loadOptionalProperties((InputStream) null)).isEqualTo(new Properties());
}
@Test
- public void loadOptionalProperties_ioException() throws Exception {
+ void loadOptionalProperties_ioException() throws Exception {
URL url = new URL("https://nonesuch12344.foo.bar.com");
- assertThat(PropertyUtils.loadOptionalProperties(url), is(new Properties()));
+ assertThat(PropertyUtils.loadOptionalProperties(url)).isEqualTo(new Properties());
}
@Test
@SuppressWarnings("deprecation")
- public void loadNullURL() throws Exception {
- assertThat(PropertyUtils.loadProperties((URL) null), nullValue(Properties.class));
+ void loadNullURL() throws Exception {
+ assertThat(PropertyUtils.loadProperties((URL) null)).isNull();
}
@Test
- public void loadOptionalNullURL() throws Exception {
- assertThat(PropertyUtils.loadOptionalProperties((URL) null), is(new Properties()));
+ void loadOptionalNullURL() throws Exception {
+ assertThat(PropertyUtils.loadOptionalProperties((URL) null)).isEqualTo(new Properties());
}
@Test
@SuppressWarnings("deprecation")
- public void loadNullFile() throws Exception {
- assertThat(PropertyUtils.loadProperties((File) null), nullValue(Properties.class));
+ void loadNullFile() throws Exception {
+ assertThat(PropertyUtils.loadProperties((File) null)).isNull();
}
@Test
- public void loadOptionalNullFile() throws Exception {
- assertThat(PropertyUtils.loadOptionalProperties((File) null), is(new Properties()));
+ void loadOptionalNullFile() throws Exception {
+ assertThat(PropertyUtils.loadOptionalProperties((File) null)).isEqualTo(new Properties());
}
@Test
@SuppressWarnings("deprecation")
- public void loadEmptyInputStream() throws Exception {
- assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
+ void loadEmptyInputStream() throws Exception {
+ assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])))
+ .isEqualTo(new Properties());
- assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
+ assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])))
+ .isEqualTo(new Properties());
}
@Test
@NeedsTemporaryFolder
@SuppressWarnings("deprecation")
- public void loadEmptyFile() throws Exception {
- assertThat(PropertyUtils.loadProperties(tempFolder.newFile("empty")), is(new Properties()));
- assertThat(PropertyUtils.loadOptionalProperties(tempFolder.newFile("optional")), is(new Properties()));
+ void loadEmptyFile() throws Exception {
+ assertThat(PropertyUtils.loadProperties(File.createTempFile("empty", null, tempFolder)))
+ .isEqualTo(new Properties());
+ assertThat(PropertyUtils.loadOptionalProperties(File.createTempFile("optional", null, tempFolder)))
+ .isEqualTo(new Properties());
}
@Test
@NeedsTemporaryFolder
@SuppressWarnings("deprecation")
- public void loadEmptyURL() throws Exception {
- assertThat(
- PropertyUtils.loadProperties(tempFolder.newFile("empty").toURI().toURL()), is(new Properties()));
+ void loadEmptyURL() throws Exception {
+ assertThat(PropertyUtils.loadProperties(
+ File.createTempFile("empty", null, tempFolder).toURI().toURL()))
+ .isEqualTo(new Properties());
- assertThat(
- PropertyUtils.loadOptionalProperties(
- tempFolder.newFile("optional").toURI().toURL()),
- is(new Properties()));
+ assertThat(PropertyUtils.loadOptionalProperties(File.createTempFile("optional", null, tempFolder)
+ .toURI()
+ .toURL()))
+ .isEqualTo(new Properties());
}
@Test
@SuppressWarnings("deprecation")
- public void loadValidInputStream() throws UnsupportedEncodingException {
+ void loadValidInputStream() throws UnsupportedEncodingException {
Properties value = new Properties();
value.setProperty("a", "b");
- assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))), is(value));
+ assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))))
+ .isEqualTo(value);
- assertThat(
- PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))),
- is(value));
+ assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))))
+ .isEqualTo(value);
}
@Test
@NeedsTemporaryFolder
@SuppressWarnings("deprecation")
- public void loadValidFile() throws IOException {
- File valid = tempFolder.newFile("valid");
+ void loadValidFile() throws IOException {
+ File valid = File.createTempFile("valid", null, tempFolder);
Properties value = new Properties();
value.setProperty("a", "b");
try (OutputStream out = new FileOutputStream(valid)) {
value.store(out, "a test");
- assertThat(PropertyUtils.loadProperties(valid), is(value));
- assertThat(PropertyUtils.loadOptionalProperties(valid), is(value));
+ assertThat(PropertyUtils.loadProperties(valid)).isEqualTo(value);
+ assertThat(PropertyUtils.loadOptionalProperties(valid)).isEqualTo(value);
}
}
@Test
@NeedsTemporaryFolder
@SuppressWarnings("deprecation")
- public void loadValidURL() throws IOException {
- File valid = tempFolder.newFile("valid");
+ void loadValidURL() throws IOException {
+ File valid = File.createTempFile("valid", null, tempFolder);
Properties value = new Properties();
value.setProperty("a", "b");
try (OutputStream out = new FileOutputStream(valid)) {
value.store(out, "a test");
- assertThat(PropertyUtils.loadProperties(valid.toURI().toURL()), is(value));
- assertThat(PropertyUtils.loadOptionalProperties(valid.toURI().toURL()), is(value));
+ assertThat(PropertyUtils.loadProperties(valid.toURI().toURL())).isEqualTo(value);
+ assertThat(PropertyUtils.loadOptionalProperties(valid.toURI().toURL()))
+ .isEqualTo(value);
}
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java
index 3cd129a..929bda7 100644
--- a/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java
@@ -23,1487 +23,1507 @@
import java.util.Iterator;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Test the {@link StringUtils} class.
*
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
*/
-public class StringUtilsTest {
+class StringUtilsTest {
- @Test(expected = NullPointerException.class)
- public void testAbbreviate_NPE() {
- assertThat(StringUtils.abbreviate(null, 10), nullValue());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testAbbreviate_MinLength() {
- assertThat(StringUtils.abbreviate("This is a longtext", 3), is("T"));
+ @Test
+ void abbreviate_NPE() {
+ assertThrows(NullPointerException.class, () -> assertThat(StringUtils.abbreviate(null, 10))
+ .isNull());
}
@Test
- public void testAbbreviate() {
- assertThat(StringUtils.abbreviate("This is a longtext", 10), is("This is..."));
-
- assertThat(StringUtils.abbreviate("This is a longtext", 50), is("This is a longtext"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testAbbreviate_Offset_NPE() {
- assertThat(StringUtils.abbreviate(null, 10, 20), nullValue());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testAbbreviate_Offset_MinLength() {
- assertThat(StringUtils.abbreviate("This is a longtext", 10, 3), is("T"));
+ void abbreviate_MinLength() {
+ assertThrows(IllegalArgumentException.class, () -> assertThat(StringUtils.abbreviate("This is a longtext", 3))
+ .isEqualTo("T"));
}
@Test
- public void testAbbreviate_Offset() {
- assertThat(StringUtils.abbreviate("This is a longtext", 5, 10), is("...is a..."));
+ void abbreviate() {
+ assertThat(StringUtils.abbreviate("This is a longtext", 10)).isEqualTo("This is...");
- assertThat(StringUtils.abbreviate("This is a longtext", 10, 20), is("This is a longtext"));
-
- assertThat(StringUtils.abbreviate("This is a longtext", 50, 20), is("This is a longtext"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testAddAndDeHump_NPE() {
- StringUtils.addAndDeHump(null);
+ assertThat(StringUtils.abbreviate("This is a longtext", 50)).isEqualTo("This is a longtext");
}
@Test
- public void testAddAndDeHump() {
- assertThat(StringUtils.addAndDeHump("lalala"), is("lalala"));
-
- assertThat(StringUtils.addAndDeHump("LaLaLa"), is("la-la-la"));
-
- assertThat(StringUtils.addAndDeHump("ALLUPPER"), is("a-l-l-u-p-p-e-r"));
+ void abbreviate_Offset_NPE() {
+ assertThrows(NullPointerException.class, () -> assertThat(StringUtils.abbreviate(null, 10, 20))
+ .isNull());
}
@Test
- public void testCapitalise() {
- assertThat(StringUtils.capitalise(null), nullValue());
-
- assertThat(StringUtils.capitalise("startBig"), is("StartBig"));
+ void abbreviate_Offset_MinLength() {
+ assertThrows(
+ IllegalArgumentException.class, () -> assertThat(StringUtils.abbreviate("This is a longtext", 10, 3))
+ .isEqualTo("T"));
}
@Test
- public void testCapitaliseAllWords() {
- assertThat(StringUtils.capitaliseAllWords(null), nullValue());
+ void abbreviate_Offset() {
+ assertThat(StringUtils.abbreviate("This is a longtext", 5, 10)).isEqualTo("...is a...");
- assertThat(StringUtils.capitaliseAllWords("start all big"), is("Start All Big"));
- }
+ assertThat(StringUtils.abbreviate("This is a longtext", 10, 20)).isEqualTo("This is a longtext");
- @Test(expected = NullPointerException.class)
- public void testCapitalizeFirstLetter_NPE() {
- assertThat(StringUtils.capitalizeFirstLetter(null), nullValue());
+ assertThat(StringUtils.abbreviate("This is a longtext", 50, 20)).isEqualTo("This is a longtext");
}
@Test
- public void testCapitalizeFirstLetter() {
- assertThat(StringUtils.capitalizeFirstLetter("Dings"), is("Dings"));
-
- assertThat(StringUtils.capitalizeFirstLetter(" dings"), is(" dings"));
-
- assertThat(StringUtils.capitalizeFirstLetter("start all big"), is("Start all big"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testCenter_NPE() {
- StringUtils.center(null, 20);
+ void addAndDeHump_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.addAndDeHump(null));
}
@Test
- public void testCenter() {
- assertThat(StringUtils.center("centerMe", 20), is(" centerMe "));
+ void addAndDeHump() {
+ assertThat(StringUtils.addAndDeHump("lalala")).isEqualTo("lalala");
- assertThat(StringUtils.center("centerMe", 4), is("centerMe"));
+ assertThat(StringUtils.addAndDeHump("LaLaLa")).isEqualTo("la-la-la");
- assertThat(StringUtils.center(" centerMe", 20), is(" centerMe "));
- }
-
- @Test(expected = NullPointerException.class)
- public void testCenter_Delim_NPE() {
- StringUtils.center(null, 20, "*");
+ assertThat(StringUtils.addAndDeHump("ALLUPPER")).isEqualTo("a-l-l-u-p-p-e-r");
}
@Test
- public void testCenter_Delim() {
- assertThat(StringUtils.center("centerMe", 20, "*"), is("******centerMe******"));
+ void capitalise() {
+ assertThat(StringUtils.capitalise(null)).isNull();
- assertThat(StringUtils.center("centerMe", 4, "*"), is("centerMe"));
-
- assertThat(StringUtils.center(" centerMe", 20, "*"), is("** centerMe**"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChomp_NPE() {
- StringUtils.chomp(null);
+ assertThat(StringUtils.capitalise("startBig")).isEqualTo("StartBig");
}
@Test
- public void testChomp() {
- assertThat(StringUtils.chomp("dings"), is("dings"));
+ void capitaliseAllWords() {
+ assertThat(StringUtils.capitaliseAllWords(null)).isNull();
- assertThat(StringUtils.chomp("dings\n"), is("dings"));
-
- assertThat(StringUtils.chomp("dings\nbums"), is("dings"));
-
- assertThat(StringUtils.chomp("dings\nbums\ndongs"), is("dings\nbums"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChomp_Delim_NPE() {
- StringUtils.chomp(null, "+");
+ assertThat(StringUtils.capitaliseAllWords("start all big")).isEqualTo("Start All Big");
}
@Test
- public void testChomp_Delim() {
- assertThat(StringUtils.chomp("dings", "+"), is("dings"));
-
- assertThat(StringUtils.chomp("dings+", "+"), is("dings"));
-
- assertThat(StringUtils.chomp("dings+bums", "+"), is("dings"));
-
- assertThat(StringUtils.chomp("dings+bums+dongs", "+"), is("dings+bums"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChompLast_NPE() {
- StringUtils.chompLast(null);
+ void capitalizeFirstLetter_NPE() {
+ assertThrows(NullPointerException.class, () -> assertThat(StringUtils.capitalizeFirstLetter(null))
+ .isNull());
}
@Test
- public void testChompLast() {
- assertThat(StringUtils.chompLast("dings"), is("dings"));
+ void capitalizeFirstLetter() {
+ assertThat(StringUtils.capitalizeFirstLetter("Dings")).isEqualTo("Dings");
- assertThat(StringUtils.chompLast("\n"), is(""));
+ assertThat(StringUtils.capitalizeFirstLetter(" dings")).isEqualTo(" dings");
- assertThat(StringUtils.chompLast("dings\n"), is("dings"));
-
- assertThat(StringUtils.chompLast("dings\nbums"), is("dings\nbums"));
-
- assertThat(StringUtils.chompLast("dings\nbums\ndongs\n"), is("dings\nbums\ndongs"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChompLast_Delim_NPE() {
- StringUtils.chompLast(null, "+");
+ assertThat(StringUtils.capitalizeFirstLetter("start all big")).isEqualTo("Start all big");
}
@Test
- public void testChompLast_Delim() {
- assertThat(StringUtils.chompLast("dings", "+"), is("dings"));
-
- assertThat(StringUtils.chompLast("+", "+"), is(""));
-
- assertThat(StringUtils.chompLast("dings+", "+"), is("dings"));
-
- assertThat(StringUtils.chompLast("dings+bums", "+"), is("dings+bums"));
-
- assertThat(StringUtils.chompLast("dings+bums+dongs+", "+"), is("dings+bums+dongs"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChop_NPE() {
- StringUtils.chop(null);
+ void center_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.center(null, 20));
}
@Test
- public void testChop() {
- assertThat(StringUtils.chop("dings"), is("ding"));
+ void center() {
+ assertThat(StringUtils.center("centerMe", 20)).isEqualTo(" centerMe ");
- assertThat(StringUtils.chop("x"), is(""));
+ assertThat(StringUtils.center("centerMe", 4)).isEqualTo("centerMe");
- assertThat(StringUtils.chop("dings\n"), is("dings"));
-
- assertThat(StringUtils.chop("dings\r\n"), is("dings"));
-
- assertThat(StringUtils.chop("dings\n\r"), is("dings\n"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testChopNewline_NPE() {
- StringUtils.chopNewline(null);
+ assertThat(StringUtils.center(" centerMe", 20)).isEqualTo(" centerMe ");
}
@Test
- public void testChopNewline() {
- assertThat(StringUtils.chopNewline("dings"), is("dings"));
-
- assertThat(StringUtils.chopNewline("x"), is("x"));
-
- assertThat(StringUtils.chopNewline("dings\n"), is("dings"));
-
- assertThat(StringUtils.chopNewline("dings\r\n"), is("dings"));
-
- assertThat(StringUtils.chopNewline("dings\n\r"), is("dings\n\r"));
+ void center_Delim_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.center(null, 20, "*"));
}
@Test
- public void testClean() {
- assertThat(StringUtils.clean(null), is(""));
+ void center_Delim() {
+ assertThat(StringUtils.center("centerMe", 20, "*")).isEqualTo("******centerMe******");
- assertThat(StringUtils.clean(" "), is(""));
+ assertThat(StringUtils.center("centerMe", 4, "*")).isEqualTo("centerMe");
- assertThat(StringUtils.clean(" c "), is("c"));
-
- assertThat(StringUtils.clean(" dings \n "), is("dings"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testConcatenate_NPE() {
- StringUtils.concatenate(null);
+ assertThat(StringUtils.center(" centerMe", 20, "*")).isEqualTo("** centerMe**");
}
@Test
- public void testConcatenate() {
- assertThat(StringUtils.concatenate(new String[0]), is(""));
-
- assertThat(StringUtils.concatenate(new String[] {"x"}), is("x"));
-
- assertThat(StringUtils.concatenate(new String[] {"x", "y", "z"}), is("xyz"));
+ void chomp_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chomp(null));
}
@Test
- public void testContains_String() {
- assertThat(StringUtils.contains(null, null), is(false));
+ void chomp() {
+ assertThat(StringUtils.chomp("dings")).isEqualTo("dings");
- assertThat(StringUtils.contains(null, "string"), is(false));
+ assertThat(StringUtils.chomp("dings\n")).isEqualTo("dings");
- assertThat(StringUtils.contains("string", null), is(false));
+ assertThat(StringUtils.chomp("dings\nbums")).isEqualTo("dings");
- assertThat(StringUtils.contains("string", ""), is(true));
-
- assertThat(StringUtils.contains("string", "in"), is(true));
-
- assertThat(StringUtils.contains("string", "IN"), is(false));
+ assertThat(StringUtils.chomp("dings\nbums\ndongs")).isEqualTo("dings\nbums");
}
@Test
- public void testContains_Char() {
- assertThat(StringUtils.contains(null, 'c'), is(false));
-
- assertThat(StringUtils.contains("string", "c"), is(false));
-
- assertThat(StringUtils.contains("string", ""), is(true));
-
- assertThat(StringUtils.contains("string", "r"), is(true));
-
- assertThat(StringUtils.contains("string", "R"), is(false));
- }
-
- @Test(expected = NullPointerException.class)
- public void testCountMatches_NPE() {
- StringUtils.countMatches(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testCountMatches_NPE2() {
- StringUtils.countMatches("this is it", null);
+ void chomp_Delim_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chomp(null, "+"));
}
@Test
- public void testCountMatches() {
- assertThat(StringUtils.countMatches(null, "is"), is(0));
+ void chomp_Delim() {
+ assertThat(StringUtils.chomp("dings", "+")).isEqualTo("dings");
- assertThat(StringUtils.countMatches("this is it", "is"), is(2));
+ assertThat(StringUtils.chomp("dings+", "+")).isEqualTo("dings");
- assertThat(StringUtils.countMatches("this is it", "notincluded"), is(0));
+ assertThat(StringUtils.chomp("dings+bums", "+")).isEqualTo("dings");
+
+ assertThat(StringUtils.chomp("dings+bums+dongs", "+")).isEqualTo("dings+bums");
}
@Test
- public void testDefaultString() {
- assertThat(StringUtils.defaultString(null), is(""));
-
- assertThat(StringUtils.defaultString("dings"), is("dings"));
+ void chompLast_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chompLast(null));
}
@Test
- public void testDefaultString_defaultValue() {
- assertThat(StringUtils.defaultString(null, "defaultValue"), is("defaultValue"));
+ void chompLast() {
+ assertThat(StringUtils.chompLast("dings")).isEqualTo("dings");
- assertThat(StringUtils.defaultString("dings", "defaultValue"), is("dings"));
- }
+ assertThat(StringUtils.chompLast("\n")).isEqualTo("");
- @Test(expected = NullPointerException.class)
- public void testDeleteWhitespace_NPE() {
- StringUtils.deleteWhitespace(null);
+ assertThat(StringUtils.chompLast("dings\n")).isEqualTo("dings");
+
+ assertThat(StringUtils.chompLast("dings\nbums")).isEqualTo("dings\nbums");
+
+ assertThat(StringUtils.chompLast("dings\nbums\ndongs\n")).isEqualTo("dings\nbums\ndongs");
}
@Test
- public void testDeleteWhitespace() {
- assertThat(StringUtils.deleteWhitespace(" \t \n"), is(""));
-
- assertThat(StringUtils.deleteWhitespace(" \t \b \n"), is("\b"));
-
- assertThat(StringUtils.deleteWhitespace("dings"), is("dings"));
-
- assertThat(StringUtils.deleteWhitespace("\n dings \t "), is("dings"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testDifference_NPE() {
- StringUtils.difference(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testDifference_NPE2() {
- StringUtils.difference(null, "another");
- }
-
- @Test(expected = NullPointerException.class)
- public void testDifference_NPE3() {
- StringUtils.difference("this", null);
+ void chompLast_Delim_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chompLast(null, "+"));
}
@Test
- public void testDifference() {
- assertThat(StringUtils.difference("this", "another"), is("another"));
+ void chompLast_Delim() {
+ assertThat(StringUtils.chompLast("dings", "+")).isEqualTo("dings");
- assertThat(StringUtils.difference("I am human", "I am a robot"), is("a robot"));
+ assertThat(StringUtils.chompLast("+", "+")).isEqualTo("");
- assertThat(StringUtils.difference("I am human", "I AM a robot"), is("AM a robot"));
- }
+ assertThat(StringUtils.chompLast("dings+", "+")).isEqualTo("dings");
- @Test(expected = NullPointerException.class)
- public void testDifferenceAt_NPE() {
- StringUtils.differenceAt(null, null);
- }
+ assertThat(StringUtils.chompLast("dings+bums", "+")).isEqualTo("dings+bums");
- @Test(expected = NullPointerException.class)
- public void testDifferenceAt_NPE2() {
- StringUtils.differenceAt("test", null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testDifferenceAt_NPE3() {
- StringUtils.differenceAt(null, "test");
+ assertThat(StringUtils.chompLast("dings+bums+dongs+", "+")).isEqualTo("dings+bums+dongs");
}
@Test
- public void testDifferenceAt() {
- assertThat(StringUtils.differenceAt("this", "another"), is(0));
-
- assertThat(StringUtils.differenceAt("I am human", "I am a robot"), is(5));
-
- assertThat(StringUtils.differenceAt("I am human", "I AM a robot"), is(2));
+ void chop_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chop(null));
}
@Test
- public void testEndsWithIgnoreCase() {
- assertThat(StringUtils.endsWithIgnoreCase(null, null), is(false));
+ void chop() {
+ assertThat(StringUtils.chop("dings")).isEqualTo("ding");
- assertThat(StringUtils.endsWithIgnoreCase(null, "string"), is(false));
+ assertThat(StringUtils.chop("x")).isEqualTo("");
- assertThat(StringUtils.endsWithIgnoreCase("string", null), is(false));
+ assertThat(StringUtils.chop("dings\n")).isEqualTo("dings");
- assertThat(StringUtils.endsWithIgnoreCase("string", "ing"), is(true));
+ assertThat(StringUtils.chop("dings\r\n")).isEqualTo("dings");
- assertThat(StringUtils.endsWithIgnoreCase("string", "a string"), is(false));
-
- assertThat(StringUtils.endsWithIgnoreCase("string", "str"), is(false));
+ assertThat(StringUtils.chop("dings\n\r")).isEqualTo("dings\n");
}
@Test
- public void testEquals() {
- assertThat(StringUtils.equals(null, null), is(true));
-
- assertThat(StringUtils.equals("x", null), is(false));
-
- assertThat(StringUtils.equals(null, "x"), is(false));
-
- assertThat(StringUtils.equals("X", "x"), is(false));
-
- assertThat(StringUtils.equals("dings", "dings"), is(true));
+ void chopNewline_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.chopNewline(null));
}
@Test
- public void testEqualsIgnoreCase() {
- assertThat(StringUtils.equalsIgnoreCase(null, null), is(true));
+ void chopNewline() {
+ assertThat(StringUtils.chopNewline("dings")).isEqualTo("dings");
- assertThat(StringUtils.equalsIgnoreCase("x", null), is(false));
+ assertThat(StringUtils.chopNewline("x")).isEqualTo("x");
- assertThat(StringUtils.equalsIgnoreCase(null, "x"), is(false));
+ assertThat(StringUtils.chopNewline("dings\n")).isEqualTo("dings");
- assertThat(StringUtils.equalsIgnoreCase("X", "x"), is(true));
+ assertThat(StringUtils.chopNewline("dings\r\n")).isEqualTo("dings");
- assertThat(StringUtils.equalsIgnoreCase("dings", "dings"), is(true));
-
- assertThat(StringUtils.equalsIgnoreCase("dings", "diNGs"), is(true));
- }
-
- @Test(expected = NullPointerException.class)
- public void testEscape_NPE() {
- StringUtils.escape(null);
+ assertThat(StringUtils.chopNewline("dings\n\r")).isEqualTo("dings\n\r");
}
@Test
- public void testEscape() {
- assertThat(StringUtils.escape("dings"), is("dings"));
+ void clean() {
+ assertThat(StringUtils.clean(null)).isEqualTo("");
- assertThat(StringUtils.escape("dings\tbums"), is("dings\\tbums"));
+ assertThat(StringUtils.clean(" ")).isEqualTo("");
- assertThat(StringUtils.escape("dings\nbums"), is("dings\\nbums"));
+ assertThat(StringUtils.clean(" c ")).isEqualTo("c");
+
+ assertThat(StringUtils.clean(" dings \n ")).isEqualTo("dings");
}
@Test
- public void testEscape2() {
- assertThat(StringUtils.escape(null, null, '#'), nullValue());
-
- assertThat(StringUtils.escape("dings", new char[] {'\t', '\b'}, '+'), is("dings"));
-
- assertThat(StringUtils.escape("dings\tbums", new char[] {'\t', '\b'}, '+'), is("dings+\tbums"));
-
- assertThat(StringUtils.escape("dings\nbums", new char[] {'\t', '\b'}, '+'), is("dings\nbums"));
- assertThat(StringUtils.escape("dings\bbums", new char[] {'\t', '\b'}, '+'), is("dings+\bbums"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetChomp_NPE1() {
- StringUtils.getChomp(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetChomp_NPE2() {
- StringUtils.getChomp("dings", null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetChomp_NPE3() {
- StringUtils.getChomp(null, "dings");
+ void concatenate_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.concatenate(null));
}
@Test
- public void testGetChomp() {
- assertThat(StringUtils.getChomp("dings-bums", "-"), is("-bums"));
+ void concatenate() {
+ assertThat(StringUtils.concatenate(new String[0])).isEqualTo("");
- assertThat(StringUtils.getChomp("dings-", "-"), is("-"));
+ assertThat(StringUtils.concatenate(new String[] {"x"})).isEqualTo("x");
- assertThat(StringUtils.getChomp("dingsbums", "-"), is(""));
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetNestedString_NPE() {
- assertThat(StringUtils.getNestedString(" +dings+ ", null), nullValue());
+ assertThat(StringUtils.concatenate(new String[] {"x", "y", "z"})).isEqualTo("xyz");
}
@Test
- public void testGetNestedString() {
- assertThat(StringUtils.getNestedString(null, null), nullValue());
+ void contains_String() {
+ assertThat(StringUtils.contains(null, null)).isEqualTo(false);
- assertThat(StringUtils.getNestedString(" +dings+ ", "+"), is("dings"));
+ assertThat(StringUtils.contains(null, "string")).isEqualTo(false);
- assertThat(StringUtils.getNestedString(" +dings+ ", "not"), nullValue());
- }
+ assertThat(StringUtils.contains("string", null)).isEqualTo(false);
- @Test(expected = NullPointerException.class)
- public void testGetNestedString2_NPE1() {
- assertThat(StringUtils.getNestedString(" +dings+ ", null, null), nullValue());
- }
+ assertThat(StringUtils.contains("string", "")).isEqualTo(true);
- @Test(expected = NullPointerException.class)
- public void testGetNestedString2_NPE2() {
- assertThat(StringUtils.getNestedString(" +dings+ ", null, "neither"), nullValue());
+ assertThat(StringUtils.contains("string", "in")).isEqualTo(true);
+
+ assertThat(StringUtils.contains("string", "IN")).isEqualTo(false);
}
@Test
- public void testGetNestedString2() {
- assertThat(StringUtils.getNestedString(null, null, null), nullValue());
+ void contains_Char() {
+ assertThat(StringUtils.contains(null, 'c')).isEqualTo(false);
- assertThat(StringUtils.getNestedString(" +dings+ ", "not", null), nullValue());
+ assertThat(StringUtils.contains("string", "c")).isEqualTo(false);
- assertThat(StringUtils.getNestedString(" +dings- ", "+", "-"), is("dings"));
+ assertThat(StringUtils.contains("string", "")).isEqualTo(true);
- assertThat(StringUtils.getNestedString(" +dings+ ", "not", "neither"), nullValue());
- }
+ assertThat(StringUtils.contains("string", "r")).isEqualTo(true);
- @Test(expected = NullPointerException.class)
- public void testGetPrechomp_NPE1() {
- StringUtils.getPrechomp(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetPrechomp_NPE2() {
- StringUtils.getPrechomp(null, "bums");
+ assertThat(StringUtils.contains("string", "R")).isEqualTo(false);
}
@Test
- public void testGetPrechomp() {
- assertThat(StringUtils.getPrechomp("dings bums dongs", "bums"), is("dings bums"));
-
- assertThat(StringUtils.getPrechomp("dings bums dongs", "non"), is(""));
+ void countMatches_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.countMatches(null, null));
}
@Test
- public void testIndexOfAny() {
- assertThat(StringUtils.indexOfAny(null, null), is(-1));
-
- assertThat(StringUtils.indexOfAny("dings", null), is(-1));
-
- assertThat(StringUtils.indexOfAny(null, new String[] {}), is(-1));
-
- assertThat(StringUtils.indexOfAny("dings bums dongs", new String[] {"knuff", "bums"}), is(6));
- }
-
- @Test(expected = NullPointerException.class)
- public void testInterpolate_NPE() {
- StringUtils.interpolate(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testInterpolate_NPE2() {
- StringUtils.interpolate("This ${text} will get replaced", null);
+ void countMatches_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.countMatches("this is it", null));
}
@Test
- public void testInterpolate() {
+ void countMatches() {
+ assertThat(StringUtils.countMatches(null, "is")).isEqualTo(0);
+
+ assertThat(StringUtils.countMatches("this is it", "is")).isEqualTo(2);
+
+ assertThat(StringUtils.countMatches("this is it", "notincluded")).isEqualTo(0);
+ }
+
+ @Test
+ void defaultString() {
+ assertThat(StringUtils.defaultString(null)).isEqualTo("");
+
+ assertThat(StringUtils.defaultString("dings")).isEqualTo("dings");
+ }
+
+ @Test
+ void defaultString_defaultValue() {
+ assertThat(StringUtils.defaultString(null, "defaultValue")).isEqualTo("defaultValue");
+
+ assertThat(StringUtils.defaultString("dings", "defaultValue")).isEqualTo("dings");
+ }
+
+ @Test
+ void deleteWhitespace_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.deleteWhitespace(null));
+ }
+
+ @Test
+ void deleteWhitespace() {
+ assertThat(StringUtils.deleteWhitespace(" \t \n")).isEqualTo("");
+
+ assertThat(StringUtils.deleteWhitespace(" \t \b \n")).isEqualTo("\b");
+
+ assertThat(StringUtils.deleteWhitespace("dings")).isEqualTo("dings");
+
+ assertThat(StringUtils.deleteWhitespace("\n dings \t ")).isEqualTo("dings");
+ }
+
+ @Test
+ void difference_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.difference(null, null));
+ }
+
+ @Test
+ void difference_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.difference(null, "another"));
+ }
+
+ @Test
+ void difference_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.difference("this", null));
+ }
+
+ @Test
+ void difference() {
+ assertThat(StringUtils.difference("this", "another")).isEqualTo("another");
+
+ assertThat(StringUtils.difference("I am human", "I am a robot")).isEqualTo("a robot");
+
+ assertThat(StringUtils.difference("I am human", "I AM a robot")).isEqualTo("AM a robot");
+ }
+
+ @Test
+ void differenceAt_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.differenceAt(null, null));
+ }
+
+ @Test
+ void differenceAt_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.differenceAt("test", null));
+ }
+
+ @Test
+ void differenceAt_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.differenceAt(null, "test"));
+ }
+
+ @Test
+ void differenceAt() {
+ assertThat(StringUtils.differenceAt("this", "another")).isEqualTo(0);
+
+ assertThat(StringUtils.differenceAt("I am human", "I am a robot")).isEqualTo(5);
+
+ assertThat(StringUtils.differenceAt("I am human", "I AM a robot")).isEqualTo(2);
+ }
+
+ @Test
+ void endsWithIgnoreCase() {
+ assertThat(StringUtils.endsWithIgnoreCase(null, null)).isEqualTo(false);
+
+ assertThat(StringUtils.endsWithIgnoreCase(null, "string")).isEqualTo(false);
+
+ assertThat(StringUtils.endsWithIgnoreCase("string", null)).isEqualTo(false);
+
+ assertThat(StringUtils.endsWithIgnoreCase("string", "ing")).isEqualTo(true);
+
+ assertThat(StringUtils.endsWithIgnoreCase("string", "a string")).isEqualTo(false);
+
+ assertThat(StringUtils.endsWithIgnoreCase("string", "str")).isEqualTo(false);
+ }
+
+ @Test
+ void equals() {
+ assertThat(StringUtils.equals(null, null)).isEqualTo(true);
+
+ assertThat(StringUtils.equals("x", null)).isEqualTo(false);
+
+ assertThat(StringUtils.equals(null, "x")).isEqualTo(false);
+
+ assertThat(StringUtils.equals("X", "x")).isEqualTo(false);
+
+ assertThat(StringUtils.equals("dings", "dings")).isEqualTo(true);
+ }
+
+ @Test
+ void equalsIgnoreCase() {
+ assertThat(StringUtils.equalsIgnoreCase(null, null)).isEqualTo(true);
+
+ assertThat(StringUtils.equalsIgnoreCase("x", null)).isEqualTo(false);
+
+ assertThat(StringUtils.equalsIgnoreCase(null, "x")).isEqualTo(false);
+
+ assertThat(StringUtils.equalsIgnoreCase("X", "x")).isEqualTo(true);
+
+ assertThat(StringUtils.equalsIgnoreCase("dings", "dings")).isEqualTo(true);
+
+ assertThat(StringUtils.equalsIgnoreCase("dings", "diNGs")).isEqualTo(true);
+ }
+
+ @Test
+ void escape_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.escape(null));
+ }
+
+ @Test
+ void escape() {
+ assertThat(StringUtils.escape("dings")).isEqualTo("dings");
+
+ assertThat(StringUtils.escape("dings\tbums")).isEqualTo("dings\\tbums");
+
+ assertThat(StringUtils.escape("dings\nbums")).isEqualTo("dings\\nbums");
+ }
+
+ @Test
+ void escape2() {
+ assertThat(StringUtils.escape(null, null, '#')).isNull();
+
+ assertThat(StringUtils.escape("dings", new char[] {'\t', '\b'}, '+')).isEqualTo("dings");
+
+ assertThat(StringUtils.escape("dings\tbums", new char[] {'\t', '\b'}, '+'))
+ .isEqualTo("dings+\tbums");
+
+ assertThat(StringUtils.escape("dings\nbums", new char[] {'\t', '\b'}, '+'))
+ .isEqualTo("dings\nbums");
+ assertThat(StringUtils.escape("dings\bbums", new char[] {'\t', '\b'}, '+'))
+ .isEqualTo("dings+\bbums");
+ }
+
+ @Test
+ void getChomp_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.getChomp(null, null));
+ }
+
+ @Test
+ void getChomp_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.getChomp("dings", null));
+ }
+
+ @Test
+ void getChomp_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.getChomp(null, "dings"));
+ }
+
+ @Test
+ void getChomp() {
+ assertThat(StringUtils.getChomp("dings-bums", "-")).isEqualTo("-bums");
+
+ assertThat(StringUtils.getChomp("dings-", "-")).isEqualTo("-");
+
+ assertThat(StringUtils.getChomp("dingsbums", "-")).isEqualTo("");
+ }
+
+ @Test
+ void getNestedString_NPE() {
+ assertThrows(NullPointerException.class, () -> assertThat(StringUtils.getNestedString(" +dings+ ", null))
+ .isNull());
+ }
+
+ @Test
+ void getNestedString() {
+ assertThat(StringUtils.getNestedString(null, null)).isNull();
+
+ assertThat(StringUtils.getNestedString(" +dings+ ", "+")).isEqualTo("dings");
+
+ assertThat(StringUtils.getNestedString(" +dings+ ", "not")).isNull();
+ }
+
+ @Test
+ void getNestedString2_NPE1() {
+ assertThrows(NullPointerException.class, () -> assertThat(StringUtils.getNestedString(" +dings+ ", null, null))
+ .isNull());
+ }
+
+ @Test
+ void getNestedString2_NPE2() {
+ assertThrows(
+ NullPointerException.class, () -> assertThat(StringUtils.getNestedString(" +dings+ ", null, "neither"))
+ .isNull());
+ }
+
+ @Test
+ void getNestedString2() {
+ assertThat(StringUtils.getNestedString(null, null, null)).isNull();
+
+ assertThat(StringUtils.getNestedString(" +dings+ ", "not", null)).isNull();
+
+ assertThat(StringUtils.getNestedString(" +dings- ", "+", "-")).isEqualTo("dings");
+
+ assertThat(StringUtils.getNestedString(" +dings+ ", "not", "neither")).isNull();
+ }
+
+ @Test
+ void getPrechomp_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.getPrechomp(null, null));
+ }
+
+ @Test
+ void getPrechomp_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.getPrechomp(null, "bums"));
+ }
+
+ @Test
+ void getPrechomp() {
+ assertThat(StringUtils.getPrechomp("dings bums dongs", "bums")).isEqualTo("dings bums");
+
+ assertThat(StringUtils.getPrechomp("dings bums dongs", "non")).isEqualTo("");
+ }
+
+ @Test
+ void indexOfAny() {
+ assertThat(StringUtils.indexOfAny(null, null)).isEqualTo(-1);
+
+ assertThat(StringUtils.indexOfAny("dings", null)).isEqualTo(-1);
+
+ assertThat(StringUtils.indexOfAny(null, new String[] {})).isEqualTo(-1);
+
+ assertThat(StringUtils.indexOfAny("dings bums dongs", "knuff", "bums")).isEqualTo(6);
+ }
+
+ @Test
+ void interpolate_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.interpolate(null, null));
+ }
+
+ @Test
+ void interpolate_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.interpolate("This ${text} will get replaced", null));
+ }
+
+ @Test
+ void interpolate() {
Map<String, String> variables = new HashMap<>();
- assertThat(
- StringUtils.interpolate("This ${text} will get replaced", variables),
- is("This ${text} will get replaced"));
+ assertThat(StringUtils.interpolate("This ${text} will get replaced", variables))
+ .isEqualTo("This ${text} will get replaced");
variables.put("text", "with a special content");
- assertThat(
- StringUtils.interpolate("This ${text} will get replaced", variables),
- is("This with a special content will get replaced"));
+ assertThat(StringUtils.interpolate("This ${text} will get replaced", variables))
+ .isEqualTo("This with a special content will get replaced");
}
@Test
- public void testIsAlpha() {
- assertThat(StringUtils.isAlpha(null), is(false));
+ void isAlpha() {
+ assertThat(StringUtils.isAlpha(null)).isEqualTo(false);
- assertThat(StringUtils.isAlpha("2"), is(false));
+ assertThat(StringUtils.isAlpha("2")).isEqualTo(false);
- assertThat(StringUtils.isAlpha("asvsdfSDF"), is(true));
+ assertThat(StringUtils.isAlpha("asvsdfSDF")).isEqualTo(true);
- assertThat(StringUtils.isAlpha("asvsdfSDF \t "), is(false));
+ assertThat(StringUtils.isAlpha("asvsdfSDF \t ")).isEqualTo(false);
- assertThat(StringUtils.isAlpha("435afsafd3!"), is(false));
+ assertThat(StringUtils.isAlpha("435afsafd3!")).isEqualTo(false);
}
@Test
- public void testIsAlphaSpace() {
- assertThat(StringUtils.isAlphaSpace(null), is(false));
+ void isAlphaSpace() {
+ assertThat(StringUtils.isAlphaSpace(null)).isEqualTo(false);
- assertThat(StringUtils.isAlphaSpace("2"), is(false));
+ assertThat(StringUtils.isAlphaSpace("2")).isEqualTo(false);
- assertThat(StringUtils.isAlphaSpace("asvsdfSDF"), is(true));
+ assertThat(StringUtils.isAlphaSpace("asvsdfSDF")).isEqualTo(true);
- assertThat(StringUtils.isAlphaSpace("asvsdfSDF "), is(true));
+ assertThat(StringUtils.isAlphaSpace("asvsdfSDF ")).isEqualTo(true);
- assertThat(StringUtils.isAlphaSpace("asvsdfSDF \t "), is(false));
+ assertThat(StringUtils.isAlphaSpace("asvsdfSDF \t ")).isEqualTo(false);
- assertThat(StringUtils.isAlphaSpace("435afsafd3!"), is(false));
+ assertThat(StringUtils.isAlphaSpace("435afsafd3!")).isEqualTo(false);
}
@Test
- public void testIsAlphanumeric() {
- assertThat(StringUtils.isAlphanumeric(null), is(false));
+ void isAlphanumeric() {
+ assertThat(StringUtils.isAlphanumeric(null)).isEqualTo(false);
- assertThat(StringUtils.isAlphanumeric("2"), is(true));
+ assertThat(StringUtils.isAlphanumeric("2")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumeric("asvsdfSDF"), is(true));
+ assertThat(StringUtils.isAlphanumeric("asvsdfSDF")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumeric("asvsdfSDF "), is(false));
+ assertThat(StringUtils.isAlphanumeric("asvsdfSDF ")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumeric("asvsdfSDF \t "), is(false));
+ assertThat(StringUtils.isAlphanumeric("asvsdfSDF \t ")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumeric("435afsafd3!"), is(false));
+ assertThat(StringUtils.isAlphanumeric("435afsafd3!")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumeric("435afsafd3"), is(true));
+ assertThat(StringUtils.isAlphanumeric("435afsafd3")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumeric("435 "), is(false));
+ assertThat(StringUtils.isAlphanumeric("435 ")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumeric("435"), is(true));
+ assertThat(StringUtils.isAlphanumeric("435")).isEqualTo(true);
}
@Test
- public void testIsAlphanumericSpace() {
- assertThat(StringUtils.isAlphanumericSpace(null), is(false));
+ void isAlphanumericSpace() {
+ assertThat(StringUtils.isAlphanumericSpace(null)).isEqualTo(false);
- assertThat(StringUtils.isAlphanumericSpace("2"), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("2")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF"), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF "), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF ")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF \t "), is(false));
+ assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF \t ")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumericSpace("435afsafd3!"), is(false));
+ assertThat(StringUtils.isAlphanumericSpace("435afsafd3!")).isEqualTo(false);
- assertThat(StringUtils.isAlphanumericSpace("435afsafd3"), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("435afsafd3")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumericSpace("435 "), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("435 ")).isEqualTo(true);
- assertThat(StringUtils.isAlphanumericSpace("435"), is(true));
+ assertThat(StringUtils.isAlphanumericSpace("435")).isEqualTo(true);
}
@Test
- public void testIsBlank() {
- assertThat(StringUtils.isBlank(null), is(true));
+ void isBlank() {
+ assertThat(StringUtils.isBlank(null)).isEqualTo(true);
- assertThat(StringUtils.isBlank("xx"), is(false));
+ assertThat(StringUtils.isBlank("xx")).isEqualTo(false);
- assertThat(StringUtils.isBlank("xx "), is(false));
+ assertThat(StringUtils.isBlank("xx ")).isEqualTo(false);
- assertThat(StringUtils.isBlank(" "), is(true));
+ assertThat(StringUtils.isBlank(" ")).isEqualTo(true);
- assertThat(StringUtils.isBlank(" \t "), is(true));
+ assertThat(StringUtils.isBlank(" \t ")).isEqualTo(true);
- assertThat(StringUtils.isBlank(" \n "), is(true));
+ assertThat(StringUtils.isBlank(" \n ")).isEqualTo(true);
}
@Test
- public void testEmpty() {
- assertThat(StringUtils.isEmpty(null), is(true));
+ void empty() {
+ assertThat(StringUtils.isEmpty(null)).isEqualTo(true);
- assertThat(StringUtils.isEmpty("xx"), is(false));
+ assertThat(StringUtils.isEmpty("xx")).isEqualTo(false);
- assertThat(StringUtils.isEmpty("xx "), is(false));
+ assertThat(StringUtils.isEmpty("xx ")).isEqualTo(false);
- assertThat(StringUtils.isEmpty(" "), is(true));
+ assertThat(StringUtils.isEmpty(" ")).isEqualTo(true);
- assertThat(StringUtils.isEmpty(" \t "), is(true));
+ assertThat(StringUtils.isEmpty(" \t ")).isEqualTo(true);
- assertThat(StringUtils.isEmpty(" \n "), is(true));
+ assertThat(StringUtils.isEmpty(" \n ")).isEqualTo(true);
}
@Test
- public void testNotBlank() {
- assertThat(StringUtils.isNotBlank(null), is(false));
+ void notBlank() {
+ assertThat(StringUtils.isNotBlank(null)).isEqualTo(false);
- assertThat(StringUtils.isNotBlank("xx"), is(true));
+ assertThat(StringUtils.isNotBlank("xx")).isEqualTo(true);
- assertThat(StringUtils.isNotBlank("xx "), is(true));
+ assertThat(StringUtils.isNotBlank("xx ")).isEqualTo(true);
- assertThat(StringUtils.isNotBlank(" "), is(false));
+ assertThat(StringUtils.isNotBlank(" ")).isEqualTo(false);
- assertThat(StringUtils.isNotBlank(" \t "), is(false));
+ assertThat(StringUtils.isNotBlank(" \t ")).isEqualTo(false);
- assertThat(StringUtils.isNotBlank(" \n "), is(false));
+ assertThat(StringUtils.isNotBlank(" \n ")).isEqualTo(false);
}
@Test
- public void testNotEmpty() {
- assertThat(StringUtils.isNotEmpty(null), is(false));
+ void notEmpty() {
+ assertThat(StringUtils.isNotEmpty(null)).isEqualTo(false);
- assertThat(StringUtils.isNotEmpty("xx"), is(true));
+ assertThat(StringUtils.isNotEmpty("xx")).isEqualTo(true);
- assertThat(StringUtils.isNotEmpty("xx "), is(true));
+ assertThat(StringUtils.isNotEmpty("xx ")).isEqualTo(true);
- assertThat(StringUtils.isNotEmpty(" "), is(true));
+ assertThat(StringUtils.isNotEmpty(" ")).isEqualTo(true);
- assertThat(StringUtils.isNotEmpty(""), is(false));
+ assertThat(StringUtils.isNotEmpty("")).isEqualTo(false);
- assertThat(StringUtils.isNotEmpty(" \t "), is(true));
+ assertThat(StringUtils.isNotEmpty(" \t ")).isEqualTo(true);
- assertThat(StringUtils.isNotEmpty(" \n "), is(true));
+ assertThat(StringUtils.isNotEmpty(" \n ")).isEqualTo(true);
}
@Test
- public void testIsNumeric() {
- assertThat(StringUtils.isNumeric(null), is(false));
+ void isNumeric() {
+ assertThat(StringUtils.isNumeric(null)).isEqualTo(false);
- assertThat(StringUtils.isNumeric("2"), is(true));
+ assertThat(StringUtils.isNumeric("2")).isEqualTo(true);
- assertThat(StringUtils.isNumeric("asvsdfSDF"), is(false));
+ assertThat(StringUtils.isNumeric("asvsdfSDF")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("asvsdfSDF "), is(false));
+ assertThat(StringUtils.isNumeric("asvsdfSDF ")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("asvsdfSDF \t "), is(false));
+ assertThat(StringUtils.isNumeric("asvsdfSDF \t ")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("435afsafd3!"), is(false));
+ assertThat(StringUtils.isNumeric("435afsafd3!")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("435afsafd3"), is(false));
+ assertThat(StringUtils.isNumeric("435afsafd3")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("435 "), is(false));
+ assertThat(StringUtils.isNumeric("435 ")).isEqualTo(false);
- assertThat(StringUtils.isNumeric("435"), is(true));
+ assertThat(StringUtils.isNumeric("435")).isEqualTo(true);
}
@Test
- public void testIsWhitespace() {
- assertThat(StringUtils.isWhitespace(null), is(false));
+ void isWhitespace() {
+ assertThat(StringUtils.isWhitespace(null)).isEqualTo(false);
- assertThat(StringUtils.isWhitespace("xx"), is(false));
+ assertThat(StringUtils.isWhitespace("xx")).isEqualTo(false);
- assertThat(StringUtils.isWhitespace("xx "), is(false));
+ assertThat(StringUtils.isWhitespace("xx ")).isEqualTo(false);
- assertThat(StringUtils.isWhitespace(" "), is(true));
+ assertThat(StringUtils.isWhitespace(" ")).isEqualTo(true);
- assertThat(StringUtils.isWhitespace(""), is(true));
+ assertThat(StringUtils.isWhitespace("")).isEqualTo(true);
- assertThat(StringUtils.isWhitespace(" \t "), is(true));
+ assertThat(StringUtils.isWhitespace(" \t ")).isEqualTo(true);
- assertThat(StringUtils.isWhitespace(" \n "), is(true));
- }
-
- @Test(expected = NullPointerException.class)
- public void testJoin_Array_NPE() {
- StringUtils.join((Object[]) null, null);
+ assertThat(StringUtils.isWhitespace(" \n ")).isEqualTo(true);
}
@Test
- public void testJoin_Array() {
- assertThat(StringUtils.join(new Object[0], null), is(""));
-
- assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, null), is("abc"));
-
- assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, "__"), is("a__b__c"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testJoin_Iterator_NPE() {
- StringUtils.join((Iterator<?>) null, null);
+ void join_Array_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.join((Object[]) null, null));
}
@Test
- public void testJoin_Iterator() {
+ void join_Array() {
+ assertThat(StringUtils.join(new Object[0], null)).isEqualTo("");
+
+ assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, null)).isEqualTo("abc");
+
+ assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, "__")).isEqualTo("a__b__c");
+ }
+
+ @Test
+ void join_Iterator_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.join((Iterator<?>) null, null));
+ }
+
+ @Test
+ void join_Iterator() {
ArrayList<String> list = new ArrayList<>();
- assertThat(StringUtils.join(list.iterator(), null), is(""));
+ assertThat(StringUtils.join(list.iterator(), null)).isEqualTo("");
list.add("a");
list.add("b");
list.add("c");
- assertThat(StringUtils.join(list.iterator(), null), is("abc"));
+ assertThat(StringUtils.join(list.iterator(), null)).isEqualTo("abc");
- assertThat(StringUtils.join(list.iterator(), "__"), is("a__b__c"));
+ assertThat(StringUtils.join(list.iterator(), "__")).isEqualTo("a__b__c");
}
@Test
- public void testLastIndexOfAny() {
- assertThat(StringUtils.lastIndexOfAny(null, null), is(-1));
+ void lastIndexOfAny() {
+ assertThat(StringUtils.lastIndexOfAny(null, null)).isEqualTo(-1);
- assertThat(StringUtils.lastIndexOfAny("dings", null), is(-1));
+ assertThat(StringUtils.lastIndexOfAny("dings", null)).isEqualTo(-1);
- assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"ms", " b"}), is(13));
+ assertThat(StringUtils.lastIndexOfAny("dings bums boms", "ms", " b")).isEqualTo(13);
- assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"nix", "da"}), is(-1));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testLeft_IAE() {
- StringUtils.left(null, -1);
+ assertThat(StringUtils.lastIndexOfAny("dings bums boms", "nix", "da")).isEqualTo(-1);
}
@Test
- public void testLeft() {
- assertThat(StringUtils.left(null, 4), nullValue());
-
- assertThat(StringUtils.left("dingsbums", 4), is("ding"));
-
- assertThat(StringUtils.left("dingsbums", 40), is("dingsbums"));
-
- assertThat(StringUtils.left("dingsbums", 0), is(""));
- }
-
- @Test(expected = NullPointerException.class)
- public void testLeftPad1_NPE() {
- StringUtils.leftPad(null, 0);
+ void left_IAE() {
+ assertThrows(IllegalArgumentException.class, () -> StringUtils.left(null, -1));
}
@Test
- public void testLeftPad1() {
- assertThat(StringUtils.leftPad("dings", 0), is("dings"));
+ void left() {
+ assertThat(StringUtils.left(null, 4)).isNull();
- assertThat(StringUtils.leftPad("dings", 2), is("dings"));
+ assertThat(StringUtils.left("dingsbums", 4)).isEqualTo("ding");
- assertThat(StringUtils.leftPad("dings", 10), is(" dings"));
- }
+ assertThat(StringUtils.left("dingsbums", 40)).isEqualTo("dingsbums");
- @Test(expected = NullPointerException.class)
- public void testLeftPad2_NPE1() {
- StringUtils.leftPad(null, 0, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testLeftPad2_NPE2() {
- StringUtils.leftPad("dings", 0, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testLeftPad2_NPE3() {
- StringUtils.leftPad(null, 0, "*");
+ assertThat(StringUtils.left("dingsbums", 0)).isEqualTo("");
}
@Test
- public void testLeftPad2() {
- assertThat(StringUtils.leftPad("dings", 0, "*"), is("dings"));
-
- assertThat(StringUtils.leftPad("dings", 2, "*"), is("dings"));
-
- assertThat(StringUtils.leftPad("dings", 10, "*"), is("*****dings"));
+ void leftPad1_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.leftPad(null, 0));
}
@Test
- public void testLowerCase() {
- assertThat(StringUtils.lowerCase(null), nullValue());
+ void leftPad1() {
+ assertThat(StringUtils.leftPad("dings", 0)).isEqualTo("dings");
- assertThat(StringUtils.lowerCase("dinGSbuMS"), is("dingsbums"));
+ assertThat(StringUtils.leftPad("dings", 2)).isEqualTo("dings");
- assertThat(StringUtils.lowerCase(""), is(""));
- }
-
- @Test(expected = NullPointerException.class)
- public void testLowerCaseFirstLetter_NPE() {
- StringUtils.lowercaseFirstLetter(null);
+ assertThat(StringUtils.leftPad("dings", 10)).isEqualTo(" dings");
}
@Test
- public void testLowerCaseFirstLetter() {
- assertThat(StringUtils.lowercaseFirstLetter("Dings Bums"), is("dings Bums"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testMid_NegativeLen() {
- StringUtils.mid(null, 0, -2);
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testMid_WrongPos() {
- StringUtils.mid(null, -2, 3);
+ void leftPad2_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.leftPad(null, 0, null));
}
@Test
- public void testMid() {
- assertThat(StringUtils.mid(null, 0, 0), nullValue());
-
- assertThat(StringUtils.mid("dings bums", 0, 0), is(""));
-
- assertThat(StringUtils.mid("dings bums", 3, 4), is("gs b"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testOverlayString_NPE1() {
- StringUtils.overlayString(null, null, 0, 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void testOverlayString_NPE2() {
- StringUtils.overlayString("dings", null, 0, 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void testOverlayString_NPE3() {
- StringUtils.overlayString(null, "bums", 0, 0);
+ void leftPad2_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.leftPad("dings", 0, null));
}
@Test
- public void testOverlayString() {
- assertThat(StringUtils.overlayString("dings", "bums", 0, 0), is("bumsdings"));
-
- assertThat(StringUtils.overlayString("dings", "bums", 2, 4), is("dibumss"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testPrechomp_NPE1() {
- StringUtils.prechomp(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testPrechomp_NPE2() {
- StringUtils.prechomp("dings", null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testPrechomp_NPE3() {
- StringUtils.prechomp(null, "bums");
+ void leftPad2_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.leftPad(null, 0, "*"));
}
@Test
- public void testPrechomp() {
- assertThat(StringUtils.prechomp("dings bums", " "), is("bums"));
+ void leftPad2() {
+ assertThat(StringUtils.leftPad("dings", 0, "*")).isEqualTo("dings");
- assertThat(StringUtils.prechomp("dings bums", "nix"), is("dings bums"));
+ assertThat(StringUtils.leftPad("dings", 2, "*")).isEqualTo("dings");
+
+ assertThat(StringUtils.leftPad("dings", 10, "*")).isEqualTo("*****dings");
}
@Test
- public void testQuoteAndEscape1() {
- assertThat(StringUtils.quoteAndEscape(null, '+'), nullValue());
+ void lowerCase() {
+ assertThat(StringUtils.lowerCase(null)).isNull();
- assertThat(StringUtils.quoteAndEscape("", '+'), is(""));
+ assertThat(StringUtils.lowerCase("dinGSbuMS")).isEqualTo("dingsbums");
- assertThat(StringUtils.quoteAndEscape("abc", '"'), is("abc"));
-
- assertThat(StringUtils.quoteAndEscape("a\"bc", '"'), is("\"a\\\"bc\""));
-
- assertThat(StringUtils.quoteAndEscape("a\'bc", '\''), is("\'a\\'bc\'"));
-
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\''), is("a\"bc"));
+ assertThat(StringUtils.lowerCase("")).isEqualTo("");
}
@Test
- public void testQuoteAndEscape2() {
- assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}), nullValue());
-
- assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}), is(""));
-
- assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}), is("abc"));
-
- assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}), is("\"a\\\"bc\""));
-
- assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}), is("\'a\\'bc\'"));
-
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}), is("a\"bc"));
-
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}), is("\'a\"bc\'"));
+ void lowerCaseFirstLetter_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.lowercaseFirstLetter(null));
}
@Test
- public void testQuoteAndEscape3() {
- assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', false), nullValue());
+ void lowerCaseFirstLetter() {
+ assertThat(StringUtils.lowercaseFirstLetter("Dings Bums")).isEqualTo("dings Bums");
+ }
- assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', false), is(""));
+ @Test
+ void mid_NegativeLen() {
+ assertThrows(IllegalArgumentException.class, () -> StringUtils.mid(null, 0, -2));
+ }
- assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', false), is("abc"));
+ @Test
+ void mid_WrongPos() {
+ assertThrows(IndexOutOfBoundsException.class, () -> StringUtils.mid(null, -2, 3));
+ }
- assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', false), is("\"a\\\"bc\""));
+ @Test
+ void mid() {
+ assertThat(StringUtils.mid(null, 0, 0)).isNull();
- assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', false), is("a\'bc"));
+ assertThat(StringUtils.mid("dings bums", 0, 0)).isEqualTo("");
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', false), is("a\"bc"));
+ assertThat(StringUtils.mid("dings bums", 3, 4)).isEqualTo("gs b");
+ }
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', false), is("\'a\\\"bc\'"));
+ @Test
+ void overlayString_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.overlayString(null, null, 0, 0));
+ }
+
+ @Test
+ void overlayString_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.overlayString("dings", null, 0, 0));
+ }
+
+ @Test
+ void overlayString_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.overlayString(null, "bums", 0, 0));
+ }
+
+ @Test
+ void overlayString() {
+ assertThat(StringUtils.overlayString("dings", "bums", 0, 0)).isEqualTo("bumsdings");
+
+ assertThat(StringUtils.overlayString("dings", "bums", 2, 4)).isEqualTo("dibumss");
+ }
+
+ @Test
+ void prechomp_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.prechomp(null, null));
+ }
+
+ @Test
+ void prechomp_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.prechomp("dings", null));
+ }
+
+ @Test
+ void prechomp_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.prechomp(null, "bums"));
+ }
+
+ @Test
+ void prechomp() {
+ assertThat(StringUtils.prechomp("dings bums", " ")).isEqualTo("bums");
+
+ assertThat(StringUtils.prechomp("dings bums", "nix")).isEqualTo("dings bums");
+ }
+
+ @Test
+ void quoteAndEscape1() {
+ assertThat(StringUtils.quoteAndEscape(null, '+')).isNull();
+
+ assertThat(StringUtils.quoteAndEscape("", '+')).isEqualTo("");
+
+ assertThat(StringUtils.quoteAndEscape("abc", '"')).isEqualTo("abc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"')).isEqualTo("\"a\\\"bc\"");
+
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'')).isEqualTo("'a\\'bc'");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'')).isEqualTo("a\"bc");
+ }
+
+ @Test
+ void quoteAndEscape2() {
+ assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'})).isNull();
+
+ assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'})).isEqualTo("");
+
+ assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'})).isEqualTo("abc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'})).isEqualTo("\"a\\\"bc\"");
+
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'', new char[] {'"'})).isEqualTo("'a\\'bc'");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''})).isEqualTo("a\"bc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}))
+ .isEqualTo("'a\"bc'");
+ }
+
+ @Test
+ void quoteAndEscape3() {
+ assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', false))
+ .isNull();
+
+ assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', false))
+ .isEqualTo("");
+
+ assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', false))
+ .isEqualTo("abc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', false))
+ .isEqualTo("\"a\\\"bc\"");
+
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'', new char[] {'"'}, '\\', false))
+ .isEqualTo("a'bc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', false))
+ .isEqualTo("a\"bc");
+
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', false))
+ .isEqualTo("'a\\\"bc'");
// with force flag
- assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', true), nullValue());
+ assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', true))
+ .isNull();
- assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', true), is("++"));
+ assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', true))
+ .isEqualTo("++");
- assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', true), is("\"abc\""));
+ assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', true))
+ .isEqualTo("\"abc\"");
- assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', true), is("\"a\\\"bc\""));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', true))
+ .isEqualTo("\"a\\\"bc\"");
- assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', true), is("\'a\'bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'', new char[] {'"'}, '\\', true))
+ .isEqualTo("'a'bc'");
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', true), is("\'a\"bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', true))
+ .isEqualTo("'a\"bc'");
- assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', true), is("\'a\\\"bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', true))
+ .isEqualTo("'a\\\"bc'");
}
@Test
- public void testQuoteAndEscape4() {
- assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', false), nullValue());
+ void quoteAndEscape4() {
+ assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', false))
+ .isNull();
- assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', false), is(""));
+ assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', false))
+ .isEqualTo("");
- assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false), is("abc"));
+ assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false))
+ .isEqualTo("abc");
- assertThat(
- StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false),
- is("\"a\\\"bc\""));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false))
+ .isEqualTo("\"a\\\"bc\"");
- assertThat(
- StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', false),
- is("a\'bc"));
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', false))
+ .isEqualTo("a'bc");
- assertThat(
- StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', false),
- is("\'a\"bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', false))
+ .isEqualTo("'a\"bc'");
- assertThat(
- StringUtils.quoteAndEscape("\'a\"bc\'", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', false),
- is("\'a\"bc\'"));
+ assertThat(StringUtils.quoteAndEscape("'a\"bc'", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', false))
+ .isEqualTo("'a\"bc'");
// with force flag
- assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', true), nullValue());
+ assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', true))
+ .isNull();
- assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', true), is("++"));
+ assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', true))
+ .isEqualTo("++");
- assertThat(
- StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true), is("\"abc\""));
+ assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true))
+ .isEqualTo("\"abc\"");
- assertThat(
- StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true),
- is("\"a\\\"bc\""));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true))
+ .isEqualTo("\"a\\\"bc\"");
- assertThat(
- StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', true),
- is("\'a\'bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', true))
+ .isEqualTo("'a'bc'");
- assertThat(
- StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', true),
- is("\'a\"bc\'"));
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', true))
+ .isEqualTo("'a\"bc'");
- assertThat(
- StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', true),
- is("\'a\\\"bc\'"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testRemoveAndHump_NPE1() {
- StringUtils.removeAndHump(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testRemoveAndHump_NPE2() {
- StringUtils.removeAndHump("dings", null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testRemoveAndHump_NPE3() {
- StringUtils.removeAndHump(null, "bums");
+ assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', true))
+ .isEqualTo("'a\\\"bc'");
}
@Test
- public void testRemoveAndHump() {
- assertThat(StringUtils.removeAndHump("dings", "bums"), is("Ding"));
-
- assertThat(StringUtils.removeAndHump("this-is-it", "-"), is("ThisIsIt"));
-
- assertThat(StringUtils.removeAndHump("THIS-IS-IT", "-"), is("THISISIT"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testRemoveDuplicateWhitespace_NPE() {
- StringUtils.removeDuplicateWhitespace(null);
+ void removeAndHump_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.removeAndHump(null, null));
}
@Test
- public void testRemoveDuplicateWhitespace() {
- assertThat(StringUtils.removeDuplicateWhitespace("dings"), is("dings"));
-
- assertThat(StringUtils.removeDuplicateWhitespace("dings bums"), is("dings bums"));
-
- assertThat(StringUtils.removeDuplicateWhitespace("dings bums"), is("dings bums"));
-
- assertThat(StringUtils.removeDuplicateWhitespace("dings \t bums"), is("dings bums"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testRepeat_NPE() {
- StringUtils.repeat(null, 0);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void testRepeat_NegativeAmount() {
- StringUtils.repeat("dings", -1);
+ void removeAndHump_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.removeAndHump("dings", null));
}
@Test
- public void testRepeat() {
- assertThat(StringUtils.repeat("dings", 0), is(""));
-
- assertThat(StringUtils.repeat("dings", 1), is("dings"));
-
- assertThat(StringUtils.repeat("dings", 3), is("dingsdingsdings"));
+ void removeAndHump_NPE3() {
+ assertThrows(NullPointerException.class, () -> StringUtils.removeAndHump(null, "bums"));
}
@Test
- public void testReplace_char() {
- assertThat(StringUtils.replace(null, 'i', 'o'), nullValue());
+ void removeAndHump() {
+ assertThat(StringUtils.removeAndHump("dings", "bums")).isEqualTo("Ding");
- assertThat(StringUtils.replace("dings", 'i', 'o'), is("dongs"));
+ assertThat(StringUtils.removeAndHump("this-is-it", "-")).isEqualTo("ThisIsIt");
- assertThat(StringUtils.replace("dingsbims", 'i', 'o'), is("dongsboms"));
-
- assertThat(StringUtils.replace("dings", 'x', 'o'), is("dings"));
+ assertThat(StringUtils.removeAndHump("THIS-IS-IT", "-")).isEqualTo("THISISIT");
}
@Test
- public void testReplace2_char_max() {
- assertThat(StringUtils.replace(null, 'i', 'o', 0), nullValue());
-
- assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 3), is("dongsobumso"));
-
- assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 2), is("dongsobumsi"));
-
- assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 0), is("dongsobumso"));
-
- assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', -2), is("dongsobumso"));
-
- assertThat(StringUtils.replace("dings", 'x', 'o', 2), is("dings"));
+ void removeDuplicateWhitespace_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.removeDuplicateWhitespace(null));
}
@Test
- public void testReplace_string() {
- assertThat(StringUtils.replace(null, "in", "ox"), nullValue());
+ void removeDuplicateWhitespace() {
+ assertThat(StringUtils.removeDuplicateWhitespace("dings")).isEqualTo("dings");
- assertThat(StringUtils.replace("dings", "in", "ox"), is("doxgs"));
+ assertThat(StringUtils.removeDuplicateWhitespace("dings bums")).isEqualTo("dings bums");
- assertThat(StringUtils.replace("dingsbins", "in", "ox"), is("doxgsboxs"));
+ assertThat(StringUtils.removeDuplicateWhitespace("dings bums")).isEqualTo("dings bums");
- assertThat(StringUtils.replace("dings", "nin", "ox"), is("dings"));
+ assertThat(StringUtils.removeDuplicateWhitespace("dings \t bums")).isEqualTo("dings bums");
}
@Test
- public void testReplace2_string_max() {
- assertThat(StringUtils.replace(null, "in", "ox", 0), nullValue());
-
- assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 3), is("dingxobumxo"));
-
- assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 2), is("dingxobumxo"));
-
- assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 1), is("dingxobumsi"));
-
- assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 0), is("dingxobumxo"));
-
- assertThat(StringUtils.replace("dingsibumsi", "si", "xo", -2), is("dingxobumxo"));
-
- assertThat(StringUtils.replace("dings", "si", "xo", 2), is("dings"));
+ void repeat_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.repeat(null, 0));
}
@Test
- public void testReplaceOnce_char() {
- assertThat(StringUtils.replaceOnce(null, 'i', 'o'), nullValue());
-
- assertThat(StringUtils.replaceOnce("dingsibumsi", 'i', 'o'), is("dongsibumsi"));
-
- assertThat(StringUtils.replaceOnce("dings", 'x', 'o'), is("dings"));
+ void repeat_NegativeAmount() {
+ assertThrows(NegativeArraySizeException.class, () -> StringUtils.repeat("dings", -1));
}
@Test
- public void testReplaceOnce_string() {
- assertThat(StringUtils.replaceOnce(null, "in", "ox"), nullValue());
+ void repeat() {
+ assertThat(StringUtils.repeat("dings", 0)).isEqualTo("");
- assertThat(StringUtils.replaceOnce("dingsibumsi", "si", "xo"), is("dingxobumsi"));
+ assertThat(StringUtils.repeat("dings", 1)).isEqualTo("dings");
- assertThat(StringUtils.replaceOnce("dings", "si", "xo"), is("dings"));
+ assertThat(StringUtils.repeat("dings", 3)).isEqualTo("dingsdingsdings");
}
@Test
- public void testReverse() {
- assertThat(StringUtils.reverse(null), nullValue());
+ void replace_char() {
+ assertThat(StringUtils.replace(null, 'i', 'o')).isNull();
- assertThat(StringUtils.reverse(""), is(""));
+ assertThat(StringUtils.replace("dings", 'i', 'o')).isEqualTo("dongs");
- assertThat(StringUtils.reverse("dings"), is("sgnid"));
+ assertThat(StringUtils.replace("dingsbims", 'i', 'o')).isEqualTo("dongsboms");
- assertThat(StringUtils.reverse(" dings "), is(" sgnid "));
- }
-
- @Test(expected = NullPointerException.class)
- public void testReverseDelimitedString_NPE1() {
- StringUtils.reverseDelimitedString(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testReverseDelimitedString_NPE2() {
- StringUtils.reverseDelimitedString(null, " ");
+ assertThat(StringUtils.replace("dings", 'x', 'o')).isEqualTo("dings");
}
@Test
- public void testReverseDelimitedString() {
- assertThat(StringUtils.reverseDelimitedString("dings", null), is("dings"));
+ void replace2_char_max() {
+ assertThat(StringUtils.replace(null, 'i', 'o', 0)).isNull();
- assertThat(StringUtils.reverseDelimitedString("", " "), is(""));
+ assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 3)).isEqualTo("dongsobumso");
- assertThat(StringUtils.reverseDelimitedString("dings", " "), is("dings"));
+ assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 2)).isEqualTo("dongsobumsi");
- assertThat(StringUtils.reverseDelimitedString(" dings ", " "), is("dings"));
+ assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 0)).isEqualTo("dongsobumso");
- assertThat(StringUtils.reverseDelimitedString("dings bums", " "), is("bums dings"));
- }
+ assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', -2)).isEqualTo("dongsobumso");
- @Test(expected = IllegalArgumentException.class)
- public void testRight_IAE1() {
- StringUtils.right(null, -1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testRight_IAE2() {
- StringUtils.right("dings", -1);
+ assertThat(StringUtils.replace("dings", 'x', 'o', 2)).isEqualTo("dings");
}
@Test
- public void testRight() {
- assertThat(StringUtils.right(null, 0), nullValue());
+ void replace_string() {
+ assertThat(StringUtils.replace(null, "in", "ox")).isNull();
- assertThat(StringUtils.right("dings", 0), is(""));
+ assertThat(StringUtils.replace("dings", "in", "ox")).isEqualTo("doxgs");
- assertThat(StringUtils.right("dings", 3), is("ngs"));
+ assertThat(StringUtils.replace("dingsbins", "in", "ox")).isEqualTo("doxgsboxs");
- assertThat(StringUtils.right("dings ", 3), is("gs "));
- }
-
- @Test(expected = NullPointerException.class)
- public void testRightPad1_NPE() {
- StringUtils.rightPad(null, 0);
+ assertThat(StringUtils.replace("dings", "nin", "ox")).isEqualTo("dings");
}
@Test
- public void testRightPad1() {
- assertThat(StringUtils.rightPad("dings", 0), is("dings"));
+ void replace2_string_max() {
+ assertThat(StringUtils.replace(null, "in", "ox", 0)).isNull();
- assertThat(StringUtils.rightPad("dings", 3), is("dings"));
+ assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 3)).isEqualTo("dingxobumxo");
- assertThat(StringUtils.rightPad("dings", 10), is("dings "));
- }
+ assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 2)).isEqualTo("dingxobumxo");
- @Test(expected = NullPointerException.class)
- public void testRightPad2_NPE1() {
- StringUtils.rightPad(null, 0, null);
- }
+ assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 1)).isEqualTo("dingxobumsi");
- @Test(expected = NullPointerException.class)
- public void testRightPad2_NPE2() {
- StringUtils.rightPad("dings", 0, null);
- }
+ assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 0)).isEqualTo("dingxobumxo");
- @Test(expected = NullPointerException.class)
- public void testRightPad2_NPE23() {
- StringUtils.rightPad(null, 0, "+");
+ assertThat(StringUtils.replace("dingsibumsi", "si", "xo", -2)).isEqualTo("dingxobumxo");
+
+ assertThat(StringUtils.replace("dings", "si", "xo", 2)).isEqualTo("dings");
}
@Test
- public void testRightPad2() {
- assertThat(StringUtils.rightPad("dings", 0, "+"), is("dings"));
+ void replaceOnce_char() {
+ assertThat(StringUtils.replaceOnce(null, 'i', 'o')).isNull();
- assertThat(StringUtils.rightPad("dings", 3, "+"), is("dings"));
+ assertThat(StringUtils.replaceOnce("dingsibumsi", 'i', 'o')).isEqualTo("dongsibumsi");
- assertThat(StringUtils.rightPad("dings", 10, "+"), is("dings+++++"));
- }
-
- @Test(expected = NullPointerException.class)
- public void testSplit1_NPE() {
- StringUtils.split(null);
+ assertThat(StringUtils.replaceOnce("dings", 'x', 'o')).isEqualTo("dings");
}
@Test
- public void testSplit1() {
- assertThat(StringUtils.split("dings"), is(new String[] {"dings"}));
+ void replaceOnce_string() {
+ assertThat(StringUtils.replaceOnce(null, "in", "ox")).isNull();
- assertThat(StringUtils.split("dings bums"), is(new String[] {"dings", "bums"}));
- }
+ assertThat(StringUtils.replaceOnce("dingsibumsi", "si", "xo")).isEqualTo("dingxobumsi");
- @Test(expected = NullPointerException.class)
- public void testSplit2_NPE1() {
- StringUtils.split(null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testSplit2_NPE2() {
- StringUtils.split(null, " ");
+ assertThat(StringUtils.replaceOnce("dings", "si", "xo")).isEqualTo("dings");
}
@Test
- public void testSplit2() {
- assertThat(StringUtils.split("dings", null), is(new String[] {"dings"}));
+ void reverse() {
+ assertThat(StringUtils.reverse(null)).isNull();
- assertThat(StringUtils.split("dings bums", null), is(new String[] {"dings", "bums"}));
+ assertThat(StringUtils.reverse("")).isEqualTo("");
- assertThat(StringUtils.split("dings", "+"), is(new String[] {"dings"}));
+ assertThat(StringUtils.reverse("dings")).isEqualTo("sgnid");
- assertThat(StringUtils.split("dings+bums", "+"), is(new String[] {"dings", "bums"}));
- }
-
- @Test(expected = NullPointerException.class)
- public void testSplit3_NPE1() {
- StringUtils.split(null, null, 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void testSplit3_NPE2() {
- StringUtils.split(null, " ", 1);
+ assertThat(StringUtils.reverse(" dings ")).isEqualTo(" sgnid ");
}
@Test
- public void testSplit3() {
- assertThat(StringUtils.split("dings", null, 3), is(new String[] {"dings"}));
-
- assertThat(StringUtils.split("dings bums", null, 3), is(new String[] {"dings", "bums"}));
-
- assertThat(StringUtils.split("dings", "+", 3), is(new String[] {"dings"}));
-
- assertThat(StringUtils.split("dings+bums", "+", 3), is(new String[] {"dings", "bums"}));
-
- assertThat(StringUtils.split("dings+bums", "+", 1), is(new String[] {"dings+bums"}));
-
- assertThat(StringUtils.split("dings+bums", "+", 0), is(new String[] {"dings", "bums"}));
-
- assertThat(StringUtils.split("dings+bums", "+", -5), is(new String[] {"dings", "bums"}));
+ void reverseDelimitedString_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.reverseDelimitedString(null, null));
}
@Test
- public void testStrip1() {
- assertThat(StringUtils.strip(null), nullValue());
-
- assertThat(StringUtils.strip("dings"), is("dings"));
-
- assertThat(StringUtils.strip(" dings \t "), is("dings"));
+ void reverseDelimitedString_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.reverseDelimitedString(null, " "));
}
@Test
- public void testStrip2() {
- assertThat(StringUtils.strip(null, " "), nullValue());
+ void reverseDelimitedString() {
+ assertThat(StringUtils.reverseDelimitedString("dings", null)).isEqualTo("dings");
- assertThat(StringUtils.strip(null, null), nullValue());
+ assertThat(StringUtils.reverseDelimitedString("", " ")).isEqualTo("");
- assertThat(StringUtils.strip("dings", " "), is("dings"));
+ assertThat(StringUtils.reverseDelimitedString("dings", " ")).isEqualTo("dings");
- assertThat(StringUtils.strip(" dings \t ", " "), is("dings \t"));
+ assertThat(StringUtils.reverseDelimitedString(" dings ", " ")).isEqualTo("dings");
+
+ assertThat(StringUtils.reverseDelimitedString("dings bums", " ")).isEqualTo("bums dings");
}
@Test
- public void testStripAll1() {
- assertThat(StringUtils.stripAll(null), nullValue());
-
- assertThat(StringUtils.stripAll(new String[] {}), is(new String[] {}));
-
- assertThat(StringUtils.stripAll(new String[] {"dings"}), is(new String[] {"dings"}));
-
- assertThat(StringUtils.stripAll(new String[] {" dings ", " bums \t "}), is(new String[] {"dings", "bums"}));
+ void right_IAE1() {
+ assertThrows(IllegalArgumentException.class, () -> StringUtils.right(null, -1));
}
@Test
- public void testStripAll2() {
- assertThat(StringUtils.stripAll(null, " "), nullValue());
-
- assertThat(StringUtils.stripAll(new String[] {}, " "), is(new String[] {}));
-
- assertThat(StringUtils.stripAll(new String[] {"dings"}, " "), is(new String[] {"dings"}));
-
- assertThat(
- StringUtils.stripAll(new String[] {" dings ", " bums \t "}, " "),
- is(new String[] {"dings", "bums \t"}));
+ void right_IAE2() {
+ assertThrows(IllegalArgumentException.class, () -> StringUtils.right("dings", -1));
}
@Test
- public void testStripEnd() {
- assertThat(StringUtils.stripEnd(null, null), nullValue());
+ void right() {
+ assertThat(StringUtils.right(null, 0)).isNull();
- assertThat(StringUtils.stripEnd("dings", null), is("dings"));
+ assertThat(StringUtils.right("dings", 0)).isEqualTo("");
- assertThat(StringUtils.stripEnd(" dings \t ", null), is(" dings"));
+ assertThat(StringUtils.right("dings", 3)).isEqualTo("ngs");
- assertThat(StringUtils.stripEnd(null, " "), nullValue());
-
- assertThat(StringUtils.stripEnd("dings", " "), is("dings"));
-
- assertThat(StringUtils.stripEnd(" dings \t ", " "), is(" dings \t"));
+ assertThat(StringUtils.right("dings ", 3)).isEqualTo("gs ");
}
@Test
- public void testStripStart() {
- assertThat(StringUtils.stripStart(null, null), nullValue());
-
- assertThat(StringUtils.stripStart("dings", null), is("dings"));
-
- assertThat(StringUtils.stripStart(" dings \t ", null), is("dings \t "));
-
- assertThat(StringUtils.stripStart(null, " "), nullValue());
-
- assertThat(StringUtils.stripStart("dings", " "), is("dings"));
-
- assertThat(StringUtils.stripStart(" \t dings \t ", " "), is("\t dings \t "));
+ void rightPad1_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.rightPad(null, 0));
}
@Test
- public void testSubstring1() {
- assertThat(StringUtils.substring(null, 0), nullValue());
- assertThat(StringUtils.substring(null, -3), nullValue());
+ void rightPad1() {
+ assertThat(StringUtils.rightPad("dings", 0)).isEqualTo("dings");
- assertThat(StringUtils.substring("dings", 2), is("ngs"));
+ assertThat(StringUtils.rightPad("dings", 3)).isEqualTo("dings");
- assertThat(StringUtils.substring("dings", -2), is("gs"));
-
- assertThat(StringUtils.substring("dings", 20), is(""));
+ assertThat(StringUtils.rightPad("dings", 10)).isEqualTo("dings ");
}
@Test
- public void testSubstring2() {
- assertThat(StringUtils.substring(null, 0, 2), nullValue());
-
- assertThat(StringUtils.substring(null, -3, 0), nullValue());
-
- assertThat(StringUtils.substring("dings", 2, 4), is("ng"));
-
- assertThat(StringUtils.substring("dings", -2, 4), is("g"));
-
- assertThat(StringUtils.substring("dings", 20, 23), is(""));
-
- assertThat(StringUtils.substring("dings", 4, 2), is(""));
+ void rightPad2_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.rightPad(null, 0, null));
}
@Test
- public void testSwapCase() {
- assertThat(StringUtils.swapCase(null), nullValue());
-
- assertThat(StringUtils.swapCase("dings"), is("DINGS"));
-
- assertThat(StringUtils.swapCase("DinGs"), is("dINgS"));
+ void rightPad2_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.rightPad("dings", 0, null));
}
@Test
- public void testTrim() {
- assertThat(StringUtils.trim(null), nullValue());
-
- assertThat(StringUtils.trim(" "), is(""));
-
- assertThat(StringUtils.trim(" c "), is("c"));
-
- assertThat(StringUtils.trim(" dings \n "), is("dings"));
+ void rightPad2_NPE23() {
+ assertThrows(NullPointerException.class, () -> StringUtils.rightPad(null, 0, "+"));
}
@Test
- public void testUncapitalise() {
- assertThat(StringUtils.uncapitalise(null), nullValue());
+ void rightPad2() {
+ assertThat(StringUtils.rightPad("dings", 0, "+")).isEqualTo("dings");
- assertThat(StringUtils.uncapitalise(" "), is(" "));
+ assertThat(StringUtils.rightPad("dings", 3, "+")).isEqualTo("dings");
- assertThat(StringUtils.uncapitalise("dings"), is("dings"));
-
- assertThat(StringUtils.uncapitalise("Dings"), is("dings"));
-
- assertThat(StringUtils.uncapitalise("DINGS"), is("dINGS"));
+ assertThat(StringUtils.rightPad("dings", 10, "+")).isEqualTo("dings+++++");
}
@Test
- public void testUncapitaliseAllWords() {
- assertThat(StringUtils.uncapitaliseAllWords(null), nullValue());
-
- assertThat(StringUtils.uncapitaliseAllWords(" "), is(" "));
-
- assertThat(StringUtils.uncapitaliseAllWords("dings bums"), is("dings bums"));
-
- assertThat(StringUtils.uncapitaliseAllWords("Dings Bums"), is("dings bums"));
-
- assertThat(StringUtils.uncapitaliseAllWords("DINGS Bums"), is("dINGS bums"));
+ void split1_NPE() {
+ assertThrows(NullPointerException.class, () -> StringUtils.split(null));
}
@Test
- public void testUnifyLineSeparators1() {
- String sls = System.getProperty("line.separator");
+ void split1() {
+ assertThat(StringUtils.split("dings")).isEqualTo(new String[] {"dings"});
- assertThat(StringUtils.unifyLineSeparators(null), nullValue());
-
- assertThat(StringUtils.unifyLineSeparators(" "), is(" "));
-
- assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs"), is("dings" + sls + "bums" + sls + "dongs"));
+ assertThat(StringUtils.split("dings bums")).isEqualTo(new String[] {"dings", "bums"});
}
@Test
- public void testUnifyLineSeparators2() {
- assertThat(StringUtils.unifyLineSeparators(null, "\n"), nullValue());
-
- assertThat(StringUtils.unifyLineSeparators(" ", "\n"), is(" "));
-
- assertThat(
- StringUtils.unifyLineSeparators(" ", null) // takes the sytem line separator
- ,
- is(" "));
-
- assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs", "\n"), is("dings\nbums\ndongs"));
+ void split2_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.split(null, null));
}
@Test
- public void testUppercase() {
- assertThat(StringUtils.upperCase(null), nullValue());
+ void split2_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.split(null, " "));
+ }
- assertThat(StringUtils.upperCase(" "), is(" "));
+ @Test
+ void split2() {
+ assertThat(StringUtils.split("dings", null)).isEqualTo(new String[] {"dings"});
- assertThat(StringUtils.upperCase(""), is(""));
+ assertThat(StringUtils.split("dings bums", null)).isEqualTo(new String[] {"dings", "bums"});
- assertThat(StringUtils.upperCase("dings"), is("DINGS"));
+ assertThat(StringUtils.split("dings", "+")).isEqualTo(new String[] {"dings"});
+
+ assertThat(StringUtils.split("dings+bums", "+")).isEqualTo(new String[] {"dings", "bums"});
+ }
+
+ @Test
+ void split3_NPE1() {
+ assertThrows(NullPointerException.class, () -> StringUtils.split(null, null, 1));
+ }
+
+ @Test
+ void split3_NPE2() {
+ assertThrows(NullPointerException.class, () -> StringUtils.split(null, " ", 1));
+ }
+
+ @Test
+ void split3() {
+ assertThat(StringUtils.split("dings", null, 3)).isEqualTo(new String[] {"dings"});
+
+ assertThat(StringUtils.split("dings bums", null, 3)).isEqualTo(new String[] {"dings", "bums"});
+
+ assertThat(StringUtils.split("dings", "+", 3)).isEqualTo(new String[] {"dings"});
+
+ assertThat(StringUtils.split("dings+bums", "+", 3)).isEqualTo(new String[] {"dings", "bums"});
+
+ assertThat(StringUtils.split("dings+bums", "+", 1)).isEqualTo(new String[] {"dings+bums"});
+
+ assertThat(StringUtils.split("dings+bums", "+", 0)).isEqualTo(new String[] {"dings", "bums"});
+
+ assertThat(StringUtils.split("dings+bums", "+", -5)).isEqualTo(new String[] {"dings", "bums"});
+ }
+
+ @Test
+ void strip1() {
+ assertThat(StringUtils.strip(null)).isNull();
+
+ assertThat(StringUtils.strip("dings")).isEqualTo("dings");
+
+ assertThat(StringUtils.strip(" dings \t ")).isEqualTo("dings");
+ }
+
+ @Test
+ void strip2() {
+ assertThat(StringUtils.strip(null, " ")).isNull();
+
+ assertThat(StringUtils.strip(null, null)).isNull();
+
+ assertThat(StringUtils.strip("dings", " ")).isEqualTo("dings");
+
+ assertThat(StringUtils.strip(" dings \t ", " ")).isEqualTo("dings \t");
+ }
+
+ @Test
+ void stripAll1() {
+ assertThat(StringUtils.stripAll(null)).isNull();
+
+ assertThat(StringUtils.stripAll()).isEqualTo(new String[] {});
+
+ assertThat(StringUtils.stripAll("dings")).isEqualTo(new String[] {"dings"});
+
+ assertThat(StringUtils.stripAll(" dings ", " bums \t ")).isEqualTo(new String[] {"dings", "bums"});
+ }
+
+ @Test
+ void stripAll2() {
+ assertThat(StringUtils.stripAll(null, " ")).isNull();
+
+ assertThat(StringUtils.stripAll(new String[] {}, " ")).isEqualTo(new String[] {});
+
+ assertThat(StringUtils.stripAll(new String[] {"dings"}, " ")).isEqualTo(new String[] {"dings"});
+
+ assertThat(StringUtils.stripAll(new String[] {" dings ", " bums \t "}, " "))
+ .isEqualTo(new String[] {"dings", "bums \t"});
+ }
+
+ @Test
+ void stripEnd() {
+ assertThat(StringUtils.stripEnd(null, null)).isNull();
+
+ assertThat(StringUtils.stripEnd("dings", null)).isEqualTo("dings");
+
+ assertThat(StringUtils.stripEnd(" dings \t ", null)).isEqualTo(" dings");
+
+ assertThat(StringUtils.stripEnd(null, " ")).isNull();
+
+ assertThat(StringUtils.stripEnd("dings", " ")).isEqualTo("dings");
+
+ assertThat(StringUtils.stripEnd(" dings \t ", " ")).isEqualTo(" dings \t");
+ }
+
+ @Test
+ void stripStart() {
+ assertThat(StringUtils.stripStart(null, null)).isNull();
+
+ assertThat(StringUtils.stripStart("dings", null)).isEqualTo("dings");
+
+ assertThat(StringUtils.stripStart(" dings \t ", null)).isEqualTo("dings \t ");
+
+ assertThat(StringUtils.stripStart(null, " ")).isNull();
+
+ assertThat(StringUtils.stripStart("dings", " ")).isEqualTo("dings");
+
+ assertThat(StringUtils.stripStart(" \t dings \t ", " ")).isEqualTo("\t dings \t ");
+ }
+
+ @Test
+ void substring1() {
+ assertThat(StringUtils.substring(null, 0)).isNull();
+ assertThat(StringUtils.substring(null, -3)).isNull();
+
+ assertThat(StringUtils.substring("dings", 2)).isEqualTo("ngs");
+
+ assertThat(StringUtils.substring("dings", -2)).isEqualTo("gs");
+
+ assertThat(StringUtils.substring("dings", 20)).isEqualTo("");
+ }
+
+ @Test
+ void substring2() {
+ assertThat(StringUtils.substring(null, 0, 2)).isNull();
+
+ assertThat(StringUtils.substring(null, -3, 0)).isNull();
+
+ assertThat(StringUtils.substring("dings", 2, 4)).isEqualTo("ng");
+
+ assertThat(StringUtils.substring("dings", -2, 4)).isEqualTo("g");
+
+ assertThat(StringUtils.substring("dings", 20, 23)).isEqualTo("");
+
+ assertThat(StringUtils.substring("dings", 4, 2)).isEqualTo("");
+ }
+
+ @Test
+ void swapCase() {
+ assertThat(StringUtils.swapCase(null)).isNull();
+
+ assertThat(StringUtils.swapCase("dings")).isEqualTo("DINGS");
+
+ assertThat(StringUtils.swapCase("DinGs")).isEqualTo("dINgS");
+ }
+
+ @Test
+ void trim() {
+ assertThat(StringUtils.trim(null)).isNull();
+
+ assertThat(StringUtils.trim(" ")).isEqualTo("");
+
+ assertThat(StringUtils.trim(" c ")).isEqualTo("c");
+
+ assertThat(StringUtils.trim(" dings \n ")).isEqualTo("dings");
+ }
+
+ @Test
+ void uncapitalise() {
+ assertThat(StringUtils.uncapitalise(null)).isNull();
+
+ assertThat(StringUtils.uncapitalise(" ")).isEqualTo(" ");
+
+ assertThat(StringUtils.uncapitalise("dings")).isEqualTo("dings");
+
+ assertThat(StringUtils.uncapitalise("Dings")).isEqualTo("dings");
+
+ assertThat(StringUtils.uncapitalise("DINGS")).isEqualTo("dINGS");
+ }
+
+ @Test
+ void uncapitaliseAllWords() {
+ assertThat(StringUtils.uncapitaliseAllWords(null)).isNull();
+
+ assertThat(StringUtils.uncapitaliseAllWords(" ")).isEqualTo(" ");
+
+ assertThat(StringUtils.uncapitaliseAllWords("dings bums")).isEqualTo("dings bums");
+
+ assertThat(StringUtils.uncapitaliseAllWords("Dings Bums")).isEqualTo("dings bums");
+
+ assertThat(StringUtils.uncapitaliseAllWords("DINGS Bums")).isEqualTo("dINGS bums");
+ }
+
+ @Test
+ void unifyLineSeparators1() {
+ String sls = System.lineSeparator();
+
+ assertThat(StringUtils.unifyLineSeparators(null)).isNull();
+
+ assertThat(StringUtils.unifyLineSeparators(" ")).isEqualTo(" ");
+
+ assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs"))
+ .isEqualTo("dings" + sls + "bums" + sls + "dongs");
+ }
+
+ @Test
+ void unifyLineSeparators2() {
+ assertThat(StringUtils.unifyLineSeparators(null, "\n")).isNull();
+
+ assertThat(StringUtils.unifyLineSeparators(" ", "\n")).isEqualTo(" ");
+
+ assertThat(StringUtils.unifyLineSeparators(" ", null)).isEqualTo(" ");
+
+ assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs", "\n"))
+ .isEqualTo("dings\nbums\ndongs");
+ }
+
+ @Test
+ void uppercase() {
+ assertThat(StringUtils.upperCase(null)).isNull();
+
+ assertThat(StringUtils.upperCase(" ")).isEqualTo(" ");
+
+ assertThat(StringUtils.upperCase("")).isEqualTo("");
+
+ assertThat(StringUtils.upperCase("dings")).isEqualTo("DINGS");
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
index a61637b..78ab701 100644
--- a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java
@@ -23,16 +23,18 @@
import java.io.InputStream;
import java.io.SequenceInputStream;
-import junit.framework.ComparisonFailure;
-import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
import org.apache.maven.shared.utils.xml.XmlStreamReader;
+import org.junit.jupiter.api.Test;
+import org.opentest4j.AssertionFailedError;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
*/
-public class XmlStreamReaderTest extends TestCase {
+class XmlStreamReaderTest {
/** french */
private static final String TEXT_LATIN1 = "eacute: \u00E9";
/** greek */
@@ -95,66 +97,77 @@
checkXmlContent(xml, effectiveEncoding, bom);
}
- public void testNoXmlHeader() throws IOException {
+ @Test
+ void noXmlHeader() throws IOException {
String xml = "<text>text with no XML header</text>";
checkXmlContent(xml, "UTF-8");
checkXmlContent(xml, "UTF-8", BOM_UTF8);
}
- public void testDefaultEncoding() throws IOException {
+ @Test
+ void defaultEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8");
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8);
}
- public void testUTF8Encoding() throws IOException {
+ @Test
+ void uTF8Encoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-8");
checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8);
}
- public void testUTF16Encoding() throws IOException {
+ @Test
+ void uTF16Encoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null);
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE);
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE);
}
- public void testUTF16BEEncoding() throws IOException {
+ @Test
+ void uTF16BEEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE");
}
- public void testUTF16LEEncoding() throws IOException {
+ @Test
+ void uTF16LEEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE");
}
- public void testLatin1Encoding() throws IOException {
+ @Test
+ void latin1Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1");
}
- public void testLatin7Encoding() throws IOException {
+ @Test
+ void latin7Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7");
}
- public void testLatin15Encoding() throws IOException {
+ @Test
+ void latin15Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15");
}
- public void testEUC_JPEncoding() throws IOException {
+ @Test
+ void eUC_JPEncoding() throws IOException {
checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP");
}
- public void testEBCDICEncoding() throws IOException {
+ @Test
+ void eBCDICEncoding() throws IOException {
checkXmlStreamReader("simple text in EBCDIC", "CP1047");
}
- public void testInappropriateEncoding() throws IOException {
- try {
- checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2");
- fail("Check should have failed, since some characters are not available in the specified encoding");
- } catch (ComparisonFailure cf) {
- // expected failure, since the encoding does not contain some characters
- }
+ @Test
+ void inappropriateEncoding() {
+ assertThrows(
+ AssertionFailedError.class,
+ () -> checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"),
+ "Check should have failed, since some characters are not available in the specified encoding");
}
- public void testEncodingAttribute() throws IOException {
+ @Test
+ void encodingAttribute() throws IOException {
String xml = "<?xml version='1.0' encoding='US-ASCII'?><element encoding='attribute value'/>";
checkXmlContent(xml, "US-ASCII");
diff --git a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
index 7ae03f9..f3f9b1f 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
@@ -25,23 +25,21 @@
import java.util.Properties;
import org.apache.maven.shared.utils.Os;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
-public class CommandLineUtilsTest {
+class CommandLineUtilsTest {
/**
* Tests that case-insensitive environment variables are normalized to upper case.
*/
@Test
- public void testGetSystemEnvVarsCaseInsensitive() {
+ void getSystemEnvVarsCaseInsensitive() {
Properties vars = CommandLineUtils.getSystemEnvVars(false);
for (Object o : vars.keySet()) {
String variable = (String) o;
@@ -50,7 +48,7 @@
}
@Test
- public void testEnsureCaseSensitivity() {
+ void ensureCaseSensitivity() {
Map<String, String> data = new HashMap<>();
data.put("abz", "cool");
assertTrue(CommandLineUtils.ensureCaseSensitivity(data, false).containsKey("ABZ"));
@@ -61,7 +59,7 @@
* Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms.
*/
@Test
- public void testGetSystemEnvVarsWindows() {
+ void getSystemEnvVarsWindows() {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
return;
}
@@ -76,7 +74,7 @@
* Tests the splitting of a command line into distinct arguments.
*/
@Test
- public void testTranslateCommandline() throws Exception {
+ void translateCommandline() throws Exception {
assertCmdLineArgs(new String[] {}, null);
assertCmdLineArgs(new String[] {}, "");
@@ -91,7 +89,7 @@
}
@Test
- public void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenCommandLineExceptionIsThrown() {
+ void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenCommandLineExceptionIsThrown() {
try {
new Commandline("echo \"let\"s go\"").execute();
} catch (CommandLineException e) {
@@ -102,14 +100,14 @@
}
@Test
- public void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned() throws Exception {
+ void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned() throws Exception {
final Process p = new Commandline("echo \"let's go\"").execute();
p.waitFor();
assertEquals(0, p.exitValue());
}
@Test
- public void givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped()
+ void givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped()
throws Exception {
final String command = "echo \"let's go\"";
final String[] expected = new String[] {"echo", "let's go"};
@@ -117,25 +115,23 @@
}
@Test
- public void
- givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
- throws Exception {
+ void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
+ throws Exception {
final String command = "echo \"let\\\"s go\"";
final String[] expected = new String[] {"echo", "let\\\"s go"};
assertCmdLineArgs(expected, command);
}
@Test
- public void
- givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
- throws Exception {
+ void givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
+ throws Exception {
final String command = "echo \"let\\'s go\"";
final String[] expected = new String[] {"echo", "let\\'s go"};
assertCmdLineArgs(expected, command);
}
@Test
- public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenNoExceptionIsThrown()
+ void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenNoExceptionIsThrown()
throws Exception {
Process p = new Commandline("echo \"let\\\"s go\"").execute();
p.waitFor();
@@ -150,7 +146,7 @@
}
@Test
- public void environmentVariableWithNullShouldNotBeSet() {
+ void environmentVariableWithNullShouldNotBeSet() {
Commandline commandline = new Commandline();
commandline.addEnvironment("TEST_NULL_ENV", null);
@@ -162,18 +158,18 @@
}
@Test
- public void environmentVariableFromSystemIsCopiedByDefault() {
+ void environmentVariableFromSystemIsCopiedByDefault() {
Commandline commandline = new Commandline();
String[] environmentVariables = commandline.getEnvironmentVariables();
assertNotNull(environmentVariables);
- assertThat(environmentVariables, hasItemInArray("TEST_SHARED_ENV=TestValue"));
+ assertThat(environmentVariables).contains("TEST_SHARED_ENV=TestValue");
}
@Test
- public void environmentVariableFromSystemIsNotCopiedIfInheritedIsFalse() {
+ void environmentVariableFromSystemIsNotCopiedIfInheritedIsFalse() {
Commandline commandline = new Commandline();
commandline.setShellEnvironmentInherited(false);
@@ -185,7 +181,7 @@
}
@Test
- public void environmentVariableFromSystemIsRemoved() {
+ void environmentVariableFromSystemIsRemoved() {
Commandline commandline = new Commandline();
commandline.addEnvironment("TEST_SHARED_ENV", null);
diff --git a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
index 7883de7..a561e60 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
@@ -22,15 +22,15 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-public class StreamPollFeederTest {
+class StreamPollFeederTest {
@Test
- public void waitUntilFeederDoneOnInputStream() throws Exception {
+ void waitUntilFeederDoneOnInputStream() throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamPollFeeder streamPollFeeder = new StreamPollFeeder(System.in, outputStream);
@@ -47,7 +47,7 @@
}
@Test
- public void dataShouldBeCopied() throws InterruptedException, IOException {
+ void dataShouldBeCopied() throws InterruptedException, IOException {
StringBuilder TEST_DATA = new StringBuilder();
for (int i = 0; i < 100; i++) {
diff --git a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
index c9e9f3c..f763bf4 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java
@@ -20,17 +20,21 @@
import java.util.List;
-import junit.framework.TestCase;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Commandline;
+import org.junit.jupiter.api.Test;
-public class BourneShellTest extends TestCase {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BourneShellTest {
Shell newShell() {
return new BourneShell();
}
- public void testQuoteWorkingDirectoryAndExecutable() {
+ @Test
+ void quoteWorkingDirectoryAndExecutable() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/local/bin");
@@ -41,7 +45,8 @@
assertEquals("/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable);
}
- public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() {
+ @Test
+ void quoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/local/'something else'");
@@ -52,7 +57,8 @@
assertEquals("/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable);
}
- public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() {
+ @Test
+ void quoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() {
Shell sh = newShell();
sh.setWorkingDirectory("\\usr\\local\\'something else'");
@@ -63,7 +69,8 @@
assertEquals("/bin/sh -c cd '\\usr\\local\\'\"'\"'something else'\"'\"'' && 'chmod'", executable);
}
- public void testPreserveSingleQuotesOnArgument() {
+ @Test
+ void preserveSingleQuotesOnArgument() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/bin");
@@ -75,7 +82,8 @@
assertTrue(cli.endsWith("'\"some arg with spaces\"'"));
}
- public void testAddSingleQuotesOnArgumentWithSpaces() {
+ @Test
+ void addSingleQuotesOnArgumentWithSpaces() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/bin");
@@ -87,7 +95,8 @@
assertTrue(cli.endsWith("'some arg with spaces'"));
}
- public void testAddArgumentWithSingleQuote() {
+ @Test
+ void addArgumentWithSingleQuote() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/bin");
@@ -99,7 +108,8 @@
"cd '/usr/bin' && 'chmod' 'arg'\"'\"'withquote'", shellCommandLine.get(shellCommandLine.size() - 1));
}
- public void testArgumentsWithSemicolon() {
+ @Test
+ void argumentsWithSemicolon() {
Shell sh = newShell();
sh.setWorkingDirectory("/usr/bin");
@@ -145,7 +155,8 @@
assertEquals("\"--password ;password\"", lines.get(3));
}
- public void testBourneShellQuotingCharacters() throws Exception {
+ @Test
+ void bourneShellQuotingCharacters() throws Exception {
// { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')' };
// test with values https://steve-parker.org/sh/bourne.shtml Appendix B - Meta-characters and Reserved Words
Commandline commandline = new Commandline(newShell());
diff --git a/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java
index 0e3a467..26454b2 100644
--- a/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java
@@ -23,17 +23,20 @@
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
*/
-public class ReflectionValueExtractorTest extends TestCase {
+class ReflectionValueExtractorTest {
private Project project;
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ void setUp() throws Exception {
Dependency dependency1 = new Dependency();
dependency1.setArtifactId("dep1");
@@ -58,7 +61,8 @@
project.addArtifact(new Artifact("g2", "a2", "v2", "e2", "c2"));
}
- public void testValueExtraction() throws IntrospectionException {
+ @Test
+ void valueExtraction() throws IntrospectionException {
// ----------------------------------------------------------------------
// Top level values
// ----------------------------------------------------------------------
@@ -98,11 +102,11 @@
assertNotNull(dependency);
- assertTrue("dep1".equals(dependency.getArtifactId()));
+ assertEquals("dep1", dependency.getArtifactId());
String artifactId = (String) ReflectionValueExtractor.evaluate("project.dependencies[1].artifactId", project);
- assertTrue("dep2".equals(artifactId));
+ assertEquals("dep2", artifactId);
// Array
@@ -110,11 +114,11 @@
assertNotNull(dependency);
- assertTrue("dep1".equals(dependency.getArtifactId()));
+ assertEquals("dep1", dependency.getArtifactId());
artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[1].artifactId", project);
- assertTrue("dep2".equals(artifactId));
+ assertEquals("dep2", artifactId);
// Map
@@ -122,11 +126,11 @@
assertNotNull(dependency);
- assertTrue("dep1".equals(dependency.getArtifactId()));
+ assertEquals("dep1", dependency.getArtifactId());
artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep2).artifactId", project);
- assertTrue("dep2".equals(artifactId));
+ assertEquals("dep2", artifactId);
// ----------------------------------------------------------------------
// Build
@@ -137,20 +141,23 @@
assertNotNull(build);
}
- public void testValueExtractorWithAInvalidExpression() throws IntrospectionException {
+ @Test
+ void valueExtractorWithAInvalidExpression() throws IntrospectionException {
assertNull(ReflectionValueExtractor.evaluate("project.foo", project));
assertNull(ReflectionValueExtractor.evaluate("project.dependencies[10]", project));
assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project));
}
- public void testMappedDottedKey() throws IntrospectionException {
+ @Test
+ void mappedDottedKey() throws IntrospectionException {
Map<String, String> map = new HashMap<>();
map.put("a.b", "a.b-value");
assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map)));
}
- public void testIndexedMapped() throws IntrospectionException {
+ @Test
+ void indexedMapped() throws IntrospectionException {
Map<Object, Object> map = new HashMap<>();
map.put("a", "a-value");
List<Object> list = new ArrayList<>();
@@ -159,7 +166,8 @@
assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list)));
}
- public void testMappedIndexed() throws IntrospectionException {
+ @Test
+ void mappedIndexed() throws IntrospectionException {
List<Object> list = new ArrayList<>();
list.add("a-value");
Map<Object, Object> map = new HashMap<>();
@@ -167,23 +175,27 @@
assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map)));
}
- public void testMappedMissingDot() throws IntrospectionException {
+ @Test
+ void mappedMissingDot() throws IntrospectionException {
Map<Object, Object> map = new HashMap<>();
map.put("a", new ValueHolder("a-value"));
assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map)));
}
- public void testIndexedMissingDot() throws IntrospectionException {
+ @Test
+ void indexedMissingDot() throws IntrospectionException {
List<Object> list = new ArrayList<>();
list.add(new ValueHolder("a-value"));
assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list)));
}
- public void testDotDot() throws IntrospectionException {
+ @Test
+ void dotDot() throws IntrospectionException {
assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value")));
}
- public void testBadIndexedSyntax() throws IntrospectionException {
+ @Test
+ void badIndexedSyntax() throws IntrospectionException {
List<Object> list = new ArrayList<>();
list.add("a-value");
Object value = new ValueHolder(list);
@@ -196,7 +208,8 @@
assertNull(ReflectionValueExtractor.evaluate("h.value[-1]", value));
}
- public void testBadMappedSyntax() throws IntrospectionException {
+ @Test
+ void badMappedSyntax() throws IntrospectionException {
Map<Object, Object> map = new HashMap<>();
map.put("a", "a-value");
Object value = new ValueHolder(map);
@@ -207,7 +220,8 @@
assertNull(ReflectionValueExtractor.evaluate("h.value(a]", value));
}
- public void testIllegalIndexedType() {
+ @Test
+ void illegalIndexedType() {
try {
ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string"));
} catch (IntrospectionException e) {
@@ -215,7 +229,8 @@
}
}
- public void testIllegalMappedType() {
+ @Test
+ void illegalMappedType() {
try {
ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string"));
} catch (IntrospectionException e) {
@@ -223,11 +238,13 @@
}
}
- public void testTrimRootToken() throws IntrospectionException {
+ @Test
+ void trimRootToken() throws IntrospectionException {
assertNull(ReflectionValueExtractor.evaluate("project", project, true));
}
- public void testArtifactMap() throws IntrospectionException {
+ @Test
+ void artifactMap() throws IntrospectionException {
assertEquals(
"g0",
((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId());
@@ -384,13 +401,12 @@
public Dependency[] getDependenciesAsArray() {
List<Dependency> list = getDependencies();
- return list.toArray(new Dependency[list.size()]);
+ return list.toArray(new Dependency[0]);
}
public Map<String, Dependency> getDependenciesAsMap() {
Map<String, Dependency> ret = new HashMap<>();
- for (Object o : getDependencies()) {
- Dependency dep = (Dependency) o;
+ for (Dependency dep : getDependencies()) {
ret.put(dep.getArtifactId(), dep);
}
return ret;
@@ -452,7 +468,8 @@
}
}
- public void testRootPropertyRegression() throws IntrospectionException {
+ @Test
+ void rootPropertyRegression() throws IntrospectionException {
Project project = new Project();
project.setDescription("c:\\\\org\\apache\\test");
Object evalued = ReflectionValueExtractor.evaluate("description", project);
diff --git a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
index f600d61..2bc9d98 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
@@ -26,29 +26,26 @@
import org.apache.maven.shared.utils.Os;
import org.apache.maven.shared.utils.testhelpers.FileTestHelper;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeFalse;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
@SuppressWarnings("deprecation")
public class DirectoryScannerTest {
private static final String[] NONE = new String[0];
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir
+ public File tempFolder;
private void createTestData() throws IOException {
- File rootDir = tempFolder.getRoot();
+ File rootDir = tempFolder;
File folder1 = new File(rootDir, "folder1");
if (!folder1.mkdirs()) {
- Assert.fail();
+ Assertions.fail();
}
FileTestHelper.generateTestFile(new File(rootDir, "file1.txt"), 11);
@@ -60,13 +57,13 @@
File folder2 = new File(folder1, "ignorefolder");
if (!folder2.mkdirs()) {
- Assert.fail();
+ Assertions.fail();
}
FileTestHelper.generateTestFile(new File(folder2, "file7.txt"), 17);
}
@Test
- public void testSimpleScan() throws Exception {
+ void simpleScan() throws Exception {
createTestData();
fitScanTest(
@@ -100,7 +97,7 @@
}
@Test
- public void testSimpleIncludes() throws Exception {
+ void simpleIncludes() throws Exception {
createTestData();
fitScanTest(
@@ -131,40 +128,40 @@
/* expExclDirs */ NONE);
}
- @Rule
- public ExpectedException xcludesNPExRule = ExpectedException.none();
-
@Test
- public void testIncludesWithNull() throws Exception {
+ void includesWithNull() throws Exception {
testXcludesWithNull(new String[] {null}, null, "includes");
}
@Test
- public void testExcludesWithNull() throws Exception {
+ void excludesWithNull() throws Exception {
testXcludesWithNull(null, new String[] {null}, "excludes");
}
private void testXcludesWithNull(String[] includes, String[] excludes, String listName) throws Exception {
- createTestData();
- xcludesNPExRule.expect(NullPointerException.class);
- xcludesNPExRule.expectMessage("If a non-null " + listName + " list is given, all elements must be non-null");
+ Throwable exception = assertThrows(NullPointerException.class, () -> {
+ createTestData();
- fitScanTest(
- true,
- true,
- true,
- /* includes */ includes,
- /* excludes */ excludes,
- /* expInclFiles */ new String[] {"file3.dat", "folder1/file5.dat"},
- /* expInclDirs */ NONE,
- /* expNotInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"},
- /* expNotInclDirs */ new String[] {"", "folder1"},
- /* expExclFiles */ NONE,
- /* expExclDirs */ NONE);
+ fitScanTest(
+ true,
+ true,
+ true,
+ /* includes */ includes,
+ /* excludes */ excludes,
+ /* expInclFiles */ new String[] {"file3.dat", "folder1/file5.dat"},
+ /* expInclDirs */ NONE,
+ /* expNotInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"},
+ /* expNotInclDirs */ new String[] {"", "folder1"},
+ /* expExclFiles */ NONE,
+ /* expExclDirs */ NONE);
+ });
+ assertTrue(exception
+ .getMessage()
+ .contains("If a non-null " + listName + " list is given, all elements must be non-null"));
}
@Test
- public void checkSymlinkBehaviour() {
+ void checkSymlinkBehaviour() {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File("src/test/resources/symlinks/src"));
ds.setFollowSymlinks(false);
@@ -179,11 +176,11 @@
assertAlwaysIncluded(Arrays.asList(files));
// FIXME getIncludedFiles is broken on Windows; correct answer is 9
- assertTrue("files.length is " + files.length, files.length == 9 || files.length == 11);
+ assertTrue(files.length == 9 || files.length == 11, "files.length is " + files.length);
}
@Test
- public void followSymlinksFalse() throws IOException {
+ void followSymlinksFalse() throws IOException {
assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
File testDir = SymlinkTestSetup.createStandardSymlinkTestDir(new File("target/test/symlinkTestCase"));
@@ -217,7 +214,7 @@
}
@Test
- public void followSymlinks() throws IOException {
+ void followSymlinks() throws IOException {
assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
DirectoryScanner ds = new DirectoryScanner();
@@ -245,7 +242,7 @@
Creates a standard directory layout with symlinks and files.
*/
@Test
- public void testSimpleExcludes() throws Exception {
+ void simpleExcludes() throws Exception {
createTestData();
fitScanTest(
@@ -292,7 +289,7 @@
String[] expectedExcludedFiles,
String[] expectedExcludedDirectories) {
DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(tempFolder.getRoot());
+ ds.setBasedir(tempFolder);
ds.setCaseSensitive(caseSensitive);
ds.setFollowSymlinks(followSymLinks);
@@ -320,10 +317,7 @@
checkFiles("expectedExcludedFiles", expectedExcludedFiles, ds.getExcludedFiles());
checkFiles("expectedExcludedDirectories", expectedExcludedDirectories, ds.getExcludedDirectories());
- checkFiles(
- "visitedFiles",
- expectedIncludedFiles,
- scanConductor.visitedFiles.toArray(new String[scanConductor.visitedFiles.size()]));
+ checkFiles("visitedFiles", expectedIncludedFiles, scanConductor.visitedFiles.toArray(new String[0]));
}
/**
@@ -336,14 +330,14 @@
if (expectedFiles != null) {
String msg = category + " expected: " + Arrays.toString(expectedFiles) + " but got: "
+ Arrays.toString(resolvedFiles);
- Assert.assertNotNull(msg, resolvedFiles);
- assertEquals(msg, expectedFiles.length, resolvedFiles.length);
+ assertNotNull(resolvedFiles, msg);
+ assertEquals(expectedFiles.length, resolvedFiles.length, msg);
Arrays.sort(expectedFiles);
Arrays.sort(resolvedFiles);
for (int i = 0; i < resolvedFiles.length; i++) {
- assertEquals(msg, expectedFiles[i], resolvedFiles[i].replace("\\", "/"));
+ assertEquals(expectedFiles[i], resolvedFiles[i].replace("\\", "/"), msg);
}
}
}
@@ -369,7 +363,7 @@
}
private void removeAndAddSomeFiles() throws IOException {
- File rootDir = tempFolder.getRoot();
+ File rootDir = tempFolder;
File file2 = new File(rootDir, "file2.txt");
file2.delete();
@@ -380,12 +374,12 @@
}
@Test
- public void testScanDiff() throws Exception {
+ void scanDiff() throws Exception {
createTestData();
DirectoryScanner dss = new DirectoryScanner();
- dss.setBasedir(tempFolder.getRoot());
- Assert.assertNotNull(dss);
+ dss.setBasedir(tempFolder);
+ assertNotNull(dss);
// we take the initial snapshot
dss.scan();
@@ -400,17 +394,17 @@
String[] addedFiles = dsr.getFilesAdded();
String[] removedFiles = dsr.getFilesRemoved();
- Assert.assertNotNull(addedFiles);
- Assert.assertNotNull(removedFiles);
+ assertNotNull(addedFiles);
+ assertNotNull(removedFiles);
assertEquals(1, addedFiles.length);
assertEquals(2, removedFiles.length);
}
- @Ignore("Enable this test to run performance checks")
+ @Disabled("Enable this test to run performance checks")
@Test
- public void performanceTest() throws Exception {
+ void performanceTest() throws Exception {
- File rootFolder = tempFolder.getRoot();
+ File rootFolder = tempFolder;
// do some warmup
for (int i = 1; i < 200; i++) {
@@ -447,7 +441,7 @@
directoryScanner.scan();
DirectoryScanResult directoryScanResult = directoryScanner.diffIncludedFiles(oldFiles);
- Assert.assertNotNull(directoryScanResult);
+ assertNotNull(directoryScanResult);
FileUtils.deleteDirectory(rootFolder);
rootFolder.mkdir();
diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
index 5b088c9..98dbb09 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
@@ -25,7 +25,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
@@ -33,35 +32,27 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
+import java.lang.reflect.Method;
import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.io.IOUtils;
-import org.apache.maven.shared.utils.Os;
import org.apache.maven.shared.utils.testhelpers.FileTestHelper;
-import org.hamcrest.CoreMatchers;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.io.TempDir;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeFalse;
-import static org.junit.Assume.assumeThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.condition.OS.*;
/**
* This is used to test FileUtils for correctness.
@@ -78,11 +69,10 @@
// Test data
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir
+ public File tempDir;
- @Rule
- public TestName name = new TestName();
+ public String name;
/**
* Size of test directory.
@@ -97,22 +87,21 @@
private long testFile2Size;
- /**
- * @see junit.framework.TestCase#setUp()
- */
- @Before
- public void setUp() throws Exception {
- testFile1 = tempFolder.newFile("file1-test.txt");
- testFile2 = tempFolder.newFile("file1a-test.txt");
+ @BeforeEach
+ void setUp(TestInfo testInfo) throws Exception {
+ Optional<Method> testMethod = testInfo.getTestMethod();
+ testMethod.ifPresent(method -> this.name = method.getName());
+ testFile1 = File.createTempFile("file1-test.txt", null, tempDir);
+ testFile2 = File.createTempFile("file1a-test.txt", null, tempDir);
testFile1Size = (int) testFile1.length();
testFile2Size = (int) testFile2.length();
- tempFolder.getRoot().mkdirs();
+ tempDir.mkdirs();
createFile(testFile1, testFile1Size);
createFile(testFile2, testFile2Size);
- FileUtils.deleteDirectory(tempFolder.getRoot());
- tempFolder.getRoot().mkdirs();
+ FileUtils.deleteDirectory(tempDir);
+ tempDir.mkdirs();
createFile(testFile1, testFile1Size);
createFile(testFile2, testFile2Size);
}
@@ -138,136 +127,136 @@
numRead = is.read(b1, count, b0.length);
count += numRead;
}
- assertThat("Different number of bytes: ", count, is(b0.length));
+ assertThat(count).as("Different number of bytes: ").isEqualTo(b0.length);
for (int i = 0; i < count; i++) {
- assertEquals("byte " + i + " differs", b1[i], b0[i]);
+ assertEquals(b1[i], b0[i], "byte " + i + " differs");
}
}
}
private void deleteFile(File file) {
if (file.exists()) {
- assertTrue("Couldn't delete file: " + file, file.delete());
+ assertTrue(file.delete(), "Couldn't delete file: " + file);
}
}
// -----------------------------------------------------------------------
@Test
- public void toFile1() throws Exception {
+ void toFile1() throws Exception {
URL url = new URL("file", null, "a/b/c/file.txt");
File file = FileUtils.toFile(url);
- assertThat(file.toString(), containsString("file.txt"));
+ assertThat(file.toString()).contains("file.txt");
}
@Test
- public void toFile2() throws Exception {
+ void toFile2() throws Exception {
URL url = new URL("file", null, "a/b/c/file%20n%61me%2520.tx%74");
File file = FileUtils.toFile(url);
- assertThat(file.toString(), containsString("file name%20.txt"));
+ assertThat(file.toString()).contains("file name%20.txt");
}
@Test
- public void toFile3() throws Exception {
- assertThat(FileUtils.toFile(null), CoreMatchers.nullValue());
- assertThat(FileUtils.toFile(new URL("http://jakarta.apache.org")), CoreMatchers.nullValue());
+ void toFile3() throws Exception {
+ assertThat(FileUtils.toFile(null)).isNull();
+ assertThat(FileUtils.toFile(new URL("http://jakarta.apache.org"))).isNull();
}
- @Test(expected = NumberFormatException.class)
- public void toFile4() throws Exception {
- URL url = new URL("file", null, "a/b/c/file%%20%me.txt%");
- File file = FileUtils.toFile(url);
- assertThat(file.toString(), containsString("file% %me.txt%"));
+ @Test
+ void toFile4() throws Exception {
+ assertThrows(NumberFormatException.class, () -> {
+ URL url = new URL("file", null, "a/b/c/file%%20%me.txt%");
+ File file = FileUtils.toFile(url);
+ assertThat(file.toString()).contains("file% %me.txt%");
+ });
}
/**
* IO-252
*/
@Test
- public void toFile5() throws Exception {
+ void toFile5() throws Exception {
URL url = new URL("file", null, "both%20are%20100%20%25%20true");
File file = FileUtils.toFile(url);
- assertThat(file.toString(), is("both are 100 % true"));
+ assertThat(file.toString()).isEqualTo("both are 100 % true");
}
@Test
- public void toFileUtf8() throws Exception {
+ void toFileUtf8() throws Exception {
URL url = new URL("file", null, "/home/%C3%A4%C3%B6%C3%BC%C3%9F");
File file = FileUtils.toFile(url);
- assertThat(file.toString(), not(containsString("\u00E4\u00F6\u00FC\u00DF")));
+ assertThat(file.toString()).doesNotContain("\u00E4\u00F6\u00FC\u00DF");
}
// toURLs
@Test
- public void toURLs1() throws Exception {
+ void toURLs1() throws Exception {
File[] files = new File[] {
- new File(tempFolder.getRoot(), "file1.txt"),
- new File(tempFolder.getRoot(), "file2.txt"),
- new File(tempFolder.getRoot(), "test file.txt"),
+ new File(tempDir, "file1.txt"), new File(tempDir, "file2.txt"), new File(tempDir, "test file.txt"),
};
URL[] urls = FileUtils.toURLs(files);
- assertThat(urls.length, is(files.length));
- assertThat(urls[0].toExternalForm().startsWith("file:"), is(true));
- assertThat(urls[0].toExternalForm().contains("file1.txt"), is(true));
- assertThat(urls[1].toExternalForm().startsWith("file:"), is(true));
- assertThat(urls[1].toExternalForm(), containsString("file2.txt"));
+ assertThat(urls).hasSize(files.length);
+ assertThat(urls[0].toExternalForm()).startsWith("file:");
+ assertThat(urls[0].toExternalForm()).contains("file1.txt");
+ assertThat(urls[1].toExternalForm()).startsWith("file:");
+ assertThat(urls[1].toExternalForm()).contains("file2.txt");
// Test escaped char
- assertThat(urls[2].toExternalForm().startsWith("file:"), is(true));
- assertThat(urls[2].toExternalForm(), containsString("test%20file.txt"));
+ assertThat(urls[2].toExternalForm()).startsWith("file:");
+ assertThat(urls[2].toExternalForm()).contains("test%20file.txt");
}
// contentEquals
@Test
- public void contentEquals() throws Exception {
+ void contentEquals() throws Exception {
// Non-existent files
- File file = new File(tempFolder.getRoot(), name.getMethodName());
- File file2 = new File(tempFolder.getRoot(), name.getMethodName() + "2");
+ File file = new File(tempDir, name);
+ File file2 = new File(tempDir, name + "2");
// both don't exist
- assertThat(FileUtils.contentEquals(file, file), is(true));
- assertThat(FileUtils.contentEquals(file, file2), is(true));
- assertThat(FileUtils.contentEquals(file2, file2), is(true));
- assertThat(FileUtils.contentEquals(file2, file), is(true));
+ assertThat(FileUtils.contentEquals(file, file)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(file, file2)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(file2, file2)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(file2, file)).isEqualTo(true);
// Directories
- FileUtils.contentEquals(tempFolder.getRoot(), tempFolder.getRoot());
+ FileUtils.contentEquals(tempDir, tempDir);
// Different files
- File objFile1 = new File(tempFolder.getRoot(), name.getMethodName() + ".object");
+ File objFile1 = new File(tempDir, name + ".object");
objFile1.deleteOnExit();
FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1);
- File objFile1b = new File(tempFolder.getRoot(), name.getMethodName() + ".object2");
+ File objFile1b = new File(tempDir, name + ".object2");
objFile1.deleteOnExit();
FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1b);
- File objFile2 = new File(tempFolder.getRoot(), name.getMethodName() + ".collection");
+ File objFile2 = new File(tempDir, name + ".collection");
objFile2.deleteOnExit();
FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2);
- assertThat(FileUtils.contentEquals(objFile1, objFile2), is(false));
- assertThat(FileUtils.contentEquals(objFile1b, objFile2), is(false));
- assertThat(FileUtils.contentEquals(objFile1, objFile1b), is(true));
+ assertThat(FileUtils.contentEquals(objFile1, objFile2)).isEqualTo(false);
+ assertThat(FileUtils.contentEquals(objFile1b, objFile2)).isEqualTo(false);
+ assertThat(FileUtils.contentEquals(objFile1, objFile1b)).isEqualTo(true);
- assertThat(FileUtils.contentEquals(objFile1, objFile1), is(true));
- assertThat(FileUtils.contentEquals(objFile1b, objFile1b), is(true));
- assertThat(FileUtils.contentEquals(objFile2, objFile2), is(true));
+ assertThat(FileUtils.contentEquals(objFile1, objFile1)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(objFile1b, objFile1b)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(objFile2, objFile2)).isEqualTo(true);
// Equal files
file.createNewFile();
file2.createNewFile();
- assertThat(FileUtils.contentEquals(file, file), is(true));
- assertThat(FileUtils.contentEquals(file, file2), is(true));
+ assertThat(FileUtils.contentEquals(file, file)).isEqualTo(true);
+ assertThat(FileUtils.contentEquals(file, file2)).isEqualTo(true);
}
// copyURLToFile
@Test
- public void copyURLToFile() throws Exception {
+ void copyURLToFile() throws Exception {
// Creates file
- File file = new File(tempFolder.getRoot(), name.getMethodName());
+ File file = new File(tempDir, name);
file.deleteOnExit();
// Loads resource
@@ -276,10 +265,8 @@
// Tests that resource was copied correctly
try (FileInputStream fis = new FileInputStream(file)) {
- assertThat(
- "Content is not equal.",
- IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis),
- is(true));
+ assertTrue(
+ IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), "Content is not equal.");
}
// TODO Maybe test copy to itself like for copyFile()
}
@@ -287,74 +274,64 @@
// forceMkdir
@Test
- public void forceMkdir() throws Exception {
+ void forceMkdir() throws Exception {
// Tests with existing directory
- FileUtils.forceMkdir(tempFolder.getRoot());
+ FileUtils.forceMkdir(tempDir);
// Creates test file
- File testFile = new File(tempFolder.getRoot(), name.getMethodName());
+ File testFile = new File(tempDir, name);
testFile.deleteOnExit();
testFile.createNewFile();
- assertThat("Test file does not exist.", testFile.exists(), is(true));
+ assertThat(testFile).as("Test file does not exist.").exists();
// Tests with existing file
- try {
- FileUtils.forceMkdir(testFile);
- fail("Exception expected.");
- } catch (IOException ex) {
- }
+ assertThrows(IOException.class, () -> FileUtils.forceMkdir(testFile));
testFile.delete();
// Tests with non-existent directory
FileUtils.forceMkdir(testFile);
- assertThat("Directory was not created.", testFile.exists(), is(true));
+ assertThat(testFile).as("Directory was not created.").exists();
}
// sizeOfDirectory
@Test
- public void sizeOfDirectory() throws Exception {
- File file = new File(tempFolder.getRoot(), name.getMethodName());
+ void sizeOfDirectory() throws Exception {
+ File file = new File(tempDir, name);
// Non-existent file
- try {
- FileUtils.sizeOfDirectory(file);
- fail("Exception expected.");
- } catch (IllegalArgumentException ex) {
- }
+ assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfDirectory(file));
// Creates file
file.createNewFile();
file.deleteOnExit();
// Existing file
- try {
- FileUtils.sizeOfDirectory(file);
- fail("Exception expected.");
- } catch (IllegalArgumentException ex) {
- }
+ assertThrows(IllegalArgumentException.class, () -> FileUtils.sizeOfDirectory(file));
// Existing directory
file.delete();
file.mkdir();
- assertThat("Unexpected directory size", FileUtils.sizeOfDirectory(file), is((long) TEST_DIRECTORY_SIZE));
+ assertThat(FileUtils.sizeOfDirectory(file))
+ .as("Unexpected directory size")
+ .isEqualTo(TEST_DIRECTORY_SIZE);
}
// copyFile
@Test
- public void copyFile1() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy1.txt");
+ void copyFile1() throws Exception {
+ File destination = new File(tempDir, "copy1.txt");
// Thread.sleep(LAST_MODIFIED_DELAY);
// This is to slow things down so we can catch if
// the lastModified date is not ok
FileUtils.copyFile(testFile1, destination);
- assertThat("Check Exist", destination.exists(), is(true));
- assertThat("Check Full copy", destination.length(), is(testFile1Size));
+ assertThat(destination).as("Check Exist").exists();
+ assertThat(destination).as("Check Full copy").hasSize(testFile1Size);
/* disabled: Thread.sleep doesn't work reliantly for this case
assertTrue("Check last modified date preserved",
testFile1.lastModified() == destination.lastModified());*/
@@ -371,125 +348,125 @@
private static long MODIFIED_LAST_WEEK = MODIFIED_TODAY - TimeUnit.DAYS.toMillis(7);
@Test
- public void copyFileWithNoFiltersAndNoDestination() throws Exception {
+ void copyFileWithNoFiltersAndNoDestination() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!");
- File to = new File(tempFolder.getRoot(), "to.txt");
+ File to = new File(tempDir, "to.txt");
FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null);
- assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello World!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt did not exist so should have been written");
+ assertThat(to).hasContent("Hello World!");
}
@Test
- public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination() throws Exception {
+ void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!");
- File to = new File(tempFolder.getRoot(), "to.txt");
+ File to = new File(tempDir, "to.txt");
from.setLastModified(0);
FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null);
- assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello World!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt did not exist so should have been written");
+ assertThat(to).hasContent("Hello World!");
}
@Test
- public void copyFileWithNoFiltersAndOutdatedDestination() throws Exception {
+ void copyFileWithNoFiltersAndOutdatedDestination() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!");
File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content");
FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null);
- assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello World!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was outdated so should have been overwritten");
+ assertThat(to).hasContent("Hello World!");
}
@Test
- public void copyFileWithNoFiltersAndNewerDestination() throws Exception {
+ void copyFileWithNoFiltersAndNewerDestination() throws Exception {
File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello World!");
File to = write("to.txt", MODIFIED_YESTERDAY, "Older content");
FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null);
- assertTrue("to.txt was newer so should have been left alone", to.lastModified() < MODIFIED_TODAY);
- assertFileContent(to, "Older content");
+ assertTrue(to.lastModified() < MODIFIED_TODAY, "to.txt was newer so should have been left alone");
+ assertThat(to).hasContent("Older content");
}
@Test
- public void copyFileWithNoFiltersAndNewerDestinationButForcedOverwrite() throws Exception {
+ void copyFileWithNoFiltersAndNewerDestinationButForcedOverwrite() throws Exception {
File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello World!");
File to = write("to.txt", MODIFIED_YESTERDAY, "Older content");
FileUtils.copyFile(from, to, null, null, true);
- assertTrue("to.txt was newer but the overwrite should have been forced", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello World!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was newer but the overwrite should have been forced");
+ assertThat(to).hasContent("Hello World!");
}
@Test
- public void copyFileWithFilteringButNoFilters() throws Exception {
+ void copyFileWithFilteringButNoFilters() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!");
File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content");
FileUtils.copyFile(from, to, null);
- assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello ${name}!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was outdated so should have been overwritten");
+ assertThat(to).hasContent("Hello ${name}!");
}
@Test
- public void copyFileWithFilteringAndNoDestination() throws Exception {
+ void copyFileWithFilteringAndNoDestination() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!");
- File to = new File(tempFolder.getRoot(), "to.txt");
+ File to = new File(tempDir, "to.txt");
FileUtils.copyFile(from, to, null, wrappers());
- assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello Bob!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt did not exist so should have been written");
+ assertThat(to).hasContent("Hello Bob!");
}
@Test
- public void copyFileWithFilteringAndOutdatedDestination() throws Exception {
+ void copyFileWithFilteringAndOutdatedDestination() throws Exception {
File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!");
File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content");
FileUtils.copyFile(from, to, null, wrappers());
- assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello Bob!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was outdated so should have been overwritten");
+ assertThat(to).hasContent("Hello Bob!");
}
@Test
- public void copyFileWithFilteringAndNewerDestinationButForcedOverwrite() throws Exception {
+ void copyFileWithFilteringAndNewerDestinationButForcedOverwrite() throws Exception {
File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!");
File to = write("to.txt", MODIFIED_YESTERDAY, "Older content");
FileUtils.copyFile(from, to, null, wrappers(), true);
- assertTrue("to.txt was newer but the overwrite should have been forced", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello Bob!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was newer but the overwrite should have been forced");
+ assertThat(to).hasContent("Hello Bob!");
}
@Test
- public void copyFileWithFilteringAndNewerDestinationButModifiedContent() throws Exception {
+ void copyFileWithFilteringAndNewerDestinationButModifiedContent() throws Exception {
File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!");
File to = write("to.txt", MODIFIED_YESTERDAY, "Hello Charlie!");
FileUtils.copyFile(from, to, null, wrappers());
- assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY);
- assertFileContent(to, "Hello Bob!");
+ assertTrue(to.lastModified() >= MODIFIED_TODAY, "to.txt was outdated so should have been overwritten");
+ assertThat(to).hasContent("Hello Bob!");
}
@Test
- public void copyFileWithFilteringAndNewerDestinationAndMatchingContent() throws Exception {
+ void copyFileWithFilteringAndNewerDestinationAndMatchingContent() throws Exception {
File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!");
File to = write("to.txt", MODIFIED_YESTERDAY, "Hello Bob!");
FileUtils.copyFile(from, to, null, wrappers());
- assertFileContent(to, "Hello Bob!");
- assertTrue("to.txt content should be unchanged and have been left alone", to.lastModified() < MODIFIED_TODAY);
+ assertTrue(to.lastModified() < MODIFIED_TODAY, "to.txt content should be unchanged and have been left alone");
+ assertThat(to).hasContent("Hello Bob!");
}
private static FileUtils.FilterWrapper[] wrappers() {
@@ -504,26 +481,19 @@
}
private File write(@Nonnull String name, long lastModified, @Nonnull String text) throws IOException {
- final File file = new File(tempFolder.getRoot(), name);
+ final File file = new File(tempDir, name);
try (final Writer writer = new FileWriter(file)) {
writer.write(text);
}
assertTrue(file.setLastModified(lastModified));
- assertEquals("Failed to set lastModified date on " + file.getPath(), lastModified, file.lastModified());
+ assertEquals(lastModified, file.lastModified(), "Failed to set lastModified date on " + file.getPath());
return file;
}
- private static void assertFileContent(@Nonnull File file, @Nonnull String expected) throws IOException {
- try (Reader in = new FileReader(file)) {
- assertEquals("Expected " + file.getPath() + " to contain: " + expected, expected, IOUtils.toString(in));
- }
- }
-
@Test
- public void copyFileThatIsSymlink() throws Exception {
- assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
-
- File destination = new File(tempFolder.getRoot(), "symCopy.txt");
+ @DisabledOnOs(WINDOWS)
+ void copyFileThatIsSymlink() throws Exception {
+ File destination = new File(tempDir, "symCopy.txt");
File testDir = SymlinkTestSetup.createStandardSymlinkTestDir(new File("target/test/symlinkCopy"));
@@ -533,71 +503,72 @@
}
@Test
- public void deleteFile() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy1.txt");
+ void deleteFile() throws Exception {
+ File destination = new File(tempDir, "copy1.txt");
FileUtils.copyFile(testFile1, destination);
FileUtils.delete(destination);
- assertThat("Check Exist", destination.exists(), is(false));
- }
-
- @Test(expected = IOException.class)
- public void deleteFileNofile() throws Exception {
- File destination = new File("abc/cde");
- FileUtils.delete(destination);
+ assertThat(destination).as("Check Exist").doesNotExist();
}
@Test
- public void deleteFileLegacy() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy1.txt");
+ void deleteFileNofile() throws Exception {
+ assertThrows(IOException.class, () -> {
+ File destination = new File("abc/cde");
+ FileUtils.delete(destination);
+ });
+ }
+
+ @Test
+ void deleteFileLegacy() throws Exception {
+ File destination = new File(tempDir, "copy1.txt");
FileUtils.copyFile(testFile1, destination);
assertTrue(FileUtils.deleteLegacyStyle(destination));
}
@Test
- public void deleteFileLegacyNofile() throws Exception {
+ void deleteFileLegacyNofile() throws Exception {
File destination = new File("abc/cde");
assertFalse(FileUtils.deleteLegacyStyle(destination));
}
@Test
- public void copyFileWithPermissions() throws Exception {
+ void copyFileWithPermissions() throws Exception {
File source = new File("src/test/resources/executable");
source.setExecutable(true);
- assumeThat("Need an existing file to copy", source.exists(), is(true));
- assumeThat("Need an executable file to copy", source.canExecute(), is(true));
+ assertThat(source).as("Need an existing file to copy").exists();
+ assertTrue(source.canExecute(), "Need an executable file to copy");
- File destination = new File(tempFolder.getRoot(), "executable-copy");
+ File destination = new File(tempDir, "executable-copy");
FileUtils.copyFile(source, destination);
- assertThat(
- "destination not exists: " + destination.getAbsolutePath() + ", directory content: "
- + Arrays.asList(destination.getParentFile().list()),
- Files.exists(destination.toPath()),
- is(true));
+ assertThat(destination)
+ .as("destination not exists: " + destination.getAbsolutePath() + ", directory content: "
+ + Arrays.asList(destination.getParentFile().list()))
+ .exists();
- assertThat("Check copy executable", destination.canExecute(), is(true));
+ assertThat(destination.canExecute()).as("Check copy executable").isEqualTo(true);
}
@Test
- public void copyFile2() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy2.txt");
+ void copyFile2() throws Exception {
+ File destination = new File(tempDir, "copy2.txt");
// Thread.sleep(LAST_MODIFIED_DELAY);
// This is to slow things down so we can catch if
// the lastModified date is not ok
FileUtils.copyFile(testFile1, destination);
- assertThat("Check Exist", destination.exists(), is(true));
- assertThat("Check Full copy", destination.length(), is(testFile2Size));
+ assertThat(destination).as("Check Exist").exists();
+ assertThat(destination).as("Check Full copy").hasSize(testFile2Size);
/* disabled: Thread.sleep doesn't work reliably for this case
assertTrue("Check last modified date preserved",
testFile1.lastModified() == destination.lastModified());*/
}
@Test
- public void copyToSelf() throws IOException {
- File destination = new File(tempFolder.getRoot(), "copy3.txt");
+ void copyToSelf() throws IOException {
+ File destination = new File(tempDir, "copy3.txt");
// Prepare a test file
FileUtils.copyFile(testFile1, destination);
@@ -605,10 +576,10 @@
}
@Test
- public void copyDirectoryToNonExistingDest() throws Exception {
+ void copyDirectoryToNonExistingDest() throws Exception {
createFile(testFile1, 1234);
createFile(testFile2, 4321);
- File srcDir = tempFolder.getRoot();
+ File srcDir = tempDir;
File subDir = new File(srcDir, "sub");
subDir.mkdir();
File subFile = new File(subDir, "A.txt");
@@ -625,10 +596,10 @@
}
@Test
- public void copyDirectoryToExistingDest() throws IOException {
+ void copyDirectoryToExistingDest() throws IOException {
createFile(testFile1, 1234);
createFile(testFile2, 4321);
- File srcDir = tempFolder.getRoot();
+ File srcDir = tempDir;
File subDir = new File(srcDir, "sub");
assertTrue(subDir.mkdir());
File subFile = new File(subDir, "A.txt");
@@ -644,80 +615,58 @@
}
@Test
- public void copyDirectoryErrors_nullDestination() throws IOException {
- try {
- FileUtils.copyDirectory(new File("a"), null);
- fail();
- } catch (NullPointerException ex) {
- }
+ void copyDirectoryErrors_nullDestination() {
+ assertThrows(NullPointerException.class, () -> FileUtils.copyDirectory(new File("a"), null));
}
@Test
- public void copyDirectoryErrors_copyToSelf() {
- try {
- FileUtils.copyDirectory(tempFolder.getRoot(), tempFolder.getRoot());
- fail();
- } catch (IOException ex) {
- }
+ void copyDirectoryErrors_copyToSelf() {
+ assertThrows(IOException.class, () -> FileUtils.copyDirectory(tempDir, tempDir));
}
@Test
- public void copyDirectoryErrors() throws IOException {
- try {
- FileUtils.copyDirectory(null, null);
- fail();
- } catch (NullPointerException ex) {
- }
- try {
- FileUtils.copyDirectory(null, new File("a"));
- fail();
- } catch (NullPointerException ex) {
- }
- try {
- FileUtils.copyDirectory(tempFolder.getRoot(), testFile1);
- fail();
- } catch (IOException ex) {
- }
+ void copyDirectoryErrors() {
+ assertThrows(NullPointerException.class, () -> FileUtils.copyDirectory(null, null));
+
+ assertThrows(NullPointerException.class, () -> FileUtils.copyDirectory(null, new File("a")));
+
+ assertThrows(IOException.class, () -> FileUtils.copyDirectory(tempDir, testFile1));
}
// forceDelete
@Test
- public void forceDeleteAFile1() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy1.txt");
+ void forceDeleteAFile1() throws Exception {
+ File destination = new File(tempDir, "copy1.txt");
destination.createNewFile();
- assertTrue("Copy1.txt doesn't exist to delete", destination.exists());
+ assertThat(destination).as("Copy1.txt doesn't exist to delete").exists();
FileUtils.forceDelete(destination);
- assertFalse(destination.exists());
+ assertThat(destination).doesNotExist();
}
@Test
- public void forceDeleteAFile2() throws Exception {
- File destination = new File(tempFolder.getRoot(), "copy2.txt");
+ void forceDeleteAFile2() throws Exception {
+ File destination = new File(tempDir, "copy2.txt");
destination.createNewFile();
- assertThat("Copy2.txt doesn't exist to delete", destination.exists(), is(true));
+ assertThat(destination).as("Copy2.txt doesn't exist to delete").exists();
FileUtils.forceDelete(destination);
- assertThat("Check No Exist", !destination.exists(), is(true));
+ assertThat(destination).as("Check No Exist").doesNotExist();
}
@Test
- @Ignore("Commons test case that is failing for plexus")
- public void forceDeleteAFile3() throws Exception {
- File destination = new File(tempFolder.getRoot(), "no_such_file");
- assertThat("Check No Exist", !destination.exists(), is(true));
- try {
- FileUtils.forceDelete(destination);
- fail("Should generate FileNotFoundException");
- } catch (FileNotFoundException ignored) {
- }
+ @Disabled("Commons test case that is failing for plexus")
+ void forceDeleteAFile3() throws Exception {
+ File destination = new File(tempDir, "no_such_file");
+ assertThat(destination).as("Check No Exist").doesNotExist();
+ assertThrows(FileNotFoundException.class, () -> FileUtils.forceDelete(destination));
}
// copyFileToDirectory
@Test
- @Ignore("Commons test case that is failing for plexus")
- public void copyFile1ToDir() throws Exception {
- File directory = new File(tempFolder.getRoot(), "subdir");
+ @Disabled("Commons test case that is failing for plexus")
+ void copyFile1ToDir() throws Exception {
+ File directory = new File(tempDir, "subdir");
if (!directory.exists()) {
directory.mkdirs();
}
@@ -728,8 +677,8 @@
// the lastModified date is not ok
FileUtils.copyFileToDirectory(testFile1, directory);
- assertThat("Check Exist", destination.exists(), is(true));
- assertThat("Check Full copy", destination.length(), is(testFile1Size));
+ assertThat(destination.exists()).as("Check Exist").isEqualTo(true);
+ assertThat(destination.length()).as("Check Full copy").isEqualTo(testFile1Size);
/* disabled: Thread.sleep doesn't work reliantly for this case
assertTrue("Check last modified date preserved",
testFile1.lastModified() == destination.lastModified());*/
@@ -743,8 +692,8 @@
}
@Test
- public void copyFile2ToDir() throws Exception {
- File directory = new File(tempFolder.getRoot(), "subdir");
+ void copyFile2ToDir() throws Exception {
+ File directory = new File(tempDir, "subdir");
if (!directory.exists()) {
directory.mkdirs();
}
@@ -755,8 +704,8 @@
// the lastModified date is not ok
FileUtils.copyFileToDirectory(testFile1, directory);
- assertThat("Check Exist", destination.exists(), is(true));
- assertThat("Check Full copy", destination.length(), is(testFile2Size));
+ assertThat(destination.exists()).as("Check Exist").isEqualTo(true);
+ assertThat(destination.length()).as("Check Full copy").isEqualTo(testFile2Size);
/* disabled: Thread.sleep doesn't work reliantly for this case
assertTrue("Check last modified date preserved",
testFile1.lastModified() == destination.lastModified());*/
@@ -765,19 +714,19 @@
// forceDelete
@Test
- public void forceDeleteDir() throws Exception {
- File testDirectory = tempFolder.newFolder(name.getMethodName());
+ void forceDeleteDir() throws Exception {
+ File testDirectory = newFolder(tempDir, name);
FileUtils.forceDelete(testDirectory.getParentFile());
- assertThat("Check No Exist", !testDirectory.getParentFile().exists(), is(true));
+ assertThat(!testDirectory.getParentFile().exists()).as("Check No Exist").isEqualTo(true);
}
/**
* Test the FileUtils implementation.
*/
@Test
- public void fileUtils() throws Exception {
+ void fileUtils() throws Exception {
// Loads file from classpath
- File file1 = new File(tempFolder.getRoot(), "test.txt");
+ File file1 = new File(tempDir, "test.txt");
String filename = file1.getAbsolutePath();
// Create test file on-the-fly
@@ -785,119 +734,121 @@
out.write("This is a test".getBytes("UTF-8"));
}
- File file2 = new File(tempFolder.getRoot(), "test2.txt");
+ File file2 = new File(tempDir, "test2.txt");
FileUtils.fileWrite(file2, "UTF-8", filename);
- assertThat(file2.exists(), is(true));
- assertThat(file2.length() > 0, is(true));
+ assertThat(file2.exists()).isEqualTo(true);
+ assertThat(file2.length() > 0).isEqualTo(true);
String file2contents = FileUtils.fileRead(file2, "UTF-8");
- assertThat("Second file's contents correct", filename.equals(file2contents), is(true));
+ assertThat(filename.equals(file2contents))
+ .as("Second file's contents correct")
+ .isEqualTo(true);
- assertThat(file2.delete(), is(true));
+ assertThat(file2.delete()).isEqualTo(true);
String contents = FileUtils.fileRead(new File(filename), "UTF-8");
- assertThat("FileUtils.fileRead()", contents.equals("This is a test"), is(true));
+ assertThat(contents.equals("This is a test")).as("FileUtils.fileRead()").isEqualTo(true);
}
@Test
- public void fileReadWithDefaultEncoding() throws Exception {
- File file = new File(tempFolder.getRoot(), "read.obj");
+ void fileReadWithDefaultEncoding() throws Exception {
+ File file = new File(tempDir, "read.obj");
FileOutputStream out = new FileOutputStream(file);
byte[] text = "Hello /u1234".getBytes();
out.write(text);
out.close();
String data = FileUtils.fileRead(file);
- assertThat(data, is("Hello /u1234"));
+ assertThat(data).isEqualTo("Hello /u1234");
}
@Test
- public void fileReadWithEncoding() throws Exception {
- File file = new File(tempFolder.getRoot(), "read.obj");
+ void fileReadWithEncoding() throws Exception {
+ File file = new File(tempDir, "read.obj");
FileOutputStream out = new FileOutputStream(file);
byte[] text = "Hello /u1234".getBytes("UTF8");
out.write(text);
out.close();
String data = FileUtils.fileRead(file, "UTF8");
- assertThat(data, is("Hello /u1234"));
+ assertThat(data).isEqualTo("Hello /u1234");
}
@Test
- @Ignore("Commons test case that is failing for plexus")
- public void readLines() throws Exception {
- File file = FileTestHelper.newFile(tempFolder, "lines.txt");
+ @Disabled("Commons test case that is failing for plexus")
+ void readLines() throws Exception {
+ File file = FileTestHelper.newFile(tempDir, "lines.txt");
try {
String[] data = new String[] {"hello", "/u1234", "", "this is", "some text"};
FileTestHelper.createLineBasedFile(file, data);
List<String> lines = FileUtils.loadFile(file);
- assertThat(lines, is(Arrays.asList(data)));
+ assertThat(lines).isEqualTo(Arrays.asList(data));
} finally {
deleteFile(file);
}
}
@Test
- public void writeStringToFile1() throws Exception {
- File file = new File(tempFolder.getRoot(), "write.txt");
+ void writeStringToFile1() throws Exception {
+ File file = new File(tempDir, "write.txt");
FileUtils.fileWrite(file, "UTF8", "Hello /u1234");
byte[] text = "Hello /u1234".getBytes("UTF8");
assertEqualContent(text, file);
}
@Test
- public void writeStringToFile2() throws Exception {
- File file = new File(tempFolder.getRoot(), "write.txt");
+ void writeStringToFile2() throws Exception {
+ File file = new File(tempDir, "write.txt");
FileUtils.fileWrite(file, null, "Hello /u1234");
byte[] text = "Hello /u1234".getBytes();
assertEqualContent(text, file);
}
@Test
- public void writeCharSequence1() throws Exception {
- File file = new File(tempFolder.getRoot(), "write.txt");
+ void writeCharSequence1() throws Exception {
+ File file = new File(tempDir, "write.txt");
FileUtils.fileWrite(file, "UTF8", "Hello /u1234");
byte[] text = "Hello /u1234".getBytes("UTF8");
assertEqualContent(text, file);
}
@Test
- public void writeCharSequence2() throws Exception {
- File file = new File(tempFolder.getRoot(), "write.txt");
+ void writeCharSequence2() throws Exception {
+ File file = new File(tempDir, "write.txt");
FileUtils.fileWrite(file, null, "Hello /u1234");
byte[] text = "Hello /u1234".getBytes();
assertEqualContent(text, file);
}
@Test
- public void writeStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
- File file = FileTestHelper.newFile(tempFolder, "lines.txt");
+ void writeStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
+ File file = FileTestHelper.newFile(tempDir, "lines.txt");
FileUtils.fileWrite(file, null, "This line was there before you...");
FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data");
String expected = "This line was there before you..." + "this is brand new data";
String actual = FileUtils.fileRead(file);
- assertThat(actual, is(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
- public void writeStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
- File file = FileTestHelper.newFile(tempFolder, "lines.txt");
+ void writeStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
+ File file = FileTestHelper.newFile(tempDir, "lines.txt");
FileUtils.fileWrite(file, null, "This line was there before you...");
FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data");
String expected = "This line was there before you..." + "this is brand new data";
String actual = FileUtils.fileRead(file);
- assertThat(actual, is(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
- public void writeStringArrayToFile() throws Exception {
- File file = new File(tempFolder.getRoot(), "writeArray.txt");
+ void writeStringArrayToFile() throws Exception {
+ File file = new File(tempDir, "writeArray.txt");
FileUtils.fileWriteArray(file, new String[] {"line1", "line2", "line3"});
byte[] text = "line1\nline2\nline3".getBytes("UTF8");
@@ -905,8 +856,8 @@
}
@Test
- public void writeStringArrayToFileWithEncoding() throws Exception {
- File file = new File(tempFolder.getRoot(), "writeArray.txt");
+ void writeStringArrayToFileWithEncoding() throws Exception {
+ File file = new File(tempDir, "writeArray.txt");
FileUtils.fileWriteArray(file, "UTF8", new String[] {"line1", "line2", "line3"});
byte[] text = "line1\nline2\nline3".getBytes("UTF8");
@@ -914,62 +865,62 @@
}
@Test
- public void writeWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
- File file = FileTestHelper.newFile(tempFolder, "lines.txt");
+ void writeWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
+ File file = FileTestHelper.newFile(tempDir, "lines.txt");
FileUtils.fileWrite(file, "UTF-8", "This line was there before you...");
FileUtils.fileAppend(file.getAbsolutePath(), "UTF-8", "this is brand new data");
String expected = "This line was there before you..." + "this is brand new data";
String actual = FileUtils.fileRead(file);
- assertThat(actual, is(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
- public void write_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
- File file = FileTestHelper.newFile(tempFolder, "lines.txt");
+ void write_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception {
+ File file = FileTestHelper.newFile(tempDir, "lines.txt");
FileUtils.fileWrite(file, null, "This line was there before you...");
FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data");
String expected = "This line was there before you..." + "this is brand new data";
String actual = FileUtils.fileRead(file);
- assertThat(actual, is(expected));
- }
-
- @Test(expected = NullPointerException.class)
- public void blowUpOnNull() throws IOException {
- FileUtils.deleteDirectory((File) null);
+ assertThat(actual).isEqualTo(expected);
}
@Test
- public void deleteQuietlyDir() throws IOException {
- File testDirectory = new File(tempFolder.getRoot(), "testDeleteQuietlyDir");
+ void blowUpOnNull() throws IOException {
+ assertThrows(NullPointerException.class, () -> FileUtils.deleteDirectory((File) null));
+ }
+
+ @Test
+ void deleteQuietlyDir() throws IOException {
+ File testDirectory = new File(tempDir, "testDeleteQuietlyDir");
File testFile = new File(testDirectory, "testDeleteQuietlyFile");
testDirectory.mkdirs();
createFile(testFile, 0);
- assertThat(testDirectory.exists(), is(true));
- assertThat(testFile.exists(), is(true));
+ assertThat(testDirectory.exists()).isEqualTo(true);
+ assertThat(testFile.exists()).isEqualTo(true);
FileUtils.deleteDirectory(testDirectory);
- assertThat("Check No Exist", testDirectory.exists(), is(false));
- assertThat("Check No Exist", testFile.exists(), is(false));
+ assertThat(testDirectory.exists()).as("Check No Exist").isEqualTo(false);
+ assertThat(testFile.exists()).as("Check No Exist").isEqualTo(false);
}
@Test
- public void deleteQuietlyFile() throws IOException {
- File testFile = new File(tempFolder.getRoot(), "testDeleteQuietlyFile");
+ void deleteQuietlyFile() throws IOException {
+ File testFile = new File(tempDir, "testDeleteQuietlyFile");
createFile(testFile, 0);
- assertThat(testFile.exists(), is(true));
+ assertThat(testFile.exists()).isEqualTo(true);
FileUtils.deleteDirectory(testFile);
- assertThat("Check No Exist", testFile.exists(), is(false));
+ assertThat(testFile.exists()).as("Check No Exist").isEqualTo(false);
}
@Test
- public void deleteQuietlyNonExistent() throws IOException {
- File testFile = new File(tempFolder.getRoot(), "testDeleteQuietlyNonExistent");
- assertThat(testFile.exists(), is(false));
+ void deleteQuietlyNonExistent() throws IOException {
+ File testFile = new File(tempDir, "testDeleteQuietlyNonExistent");
+ assertThat(testFile.exists()).isEqualTo(false);
FileUtils.deleteDirectory(testFile);
}
@@ -977,260 +928,256 @@
//// getDefaultExcludes
@Test
- public void getDefaultExcludes() throws Exception {
- assertThat(Arrays.asList(FileUtils.getDefaultExcludes()), hasItems(MINIMUM_DEFAULT_EXCLUDES));
+ void getDefaultExcludes() throws Exception {
+ assertThat(Arrays.asList(FileUtils.getDefaultExcludes())).contains(MINIMUM_DEFAULT_EXCLUDES);
}
//// getDefaultExcludesAsList
@Test
- public void getDefaultExcludesAsList() throws Exception {
- assertThat(FileUtils.getDefaultExcludesAsList(), hasItems(MINIMUM_DEFAULT_EXCLUDES));
+ void getDefaultExcludesAsList() throws Exception {
+ assertThat(FileUtils.getDefaultExcludesAsList()).contains(MINIMUM_DEFAULT_EXCLUDES);
}
//// getDefaultExcludesAsString
@Test
- public void getDefaultExcludesAsString() throws Exception {
- assertThat(
- new HashSet<>(
- Arrays.asList(FileUtils.getDefaultExcludesAsString().split(","))),
- hasItems(MINIMUM_DEFAULT_EXCLUDES));
+ void getDefaultExcludesAsString() throws Exception {
+ assertThat(new HashSet<>(
+ Arrays.asList(FileUtils.getDefaultExcludesAsString().split(","))))
+ .contains(MINIMUM_DEFAULT_EXCLUDES);
}
//// dirname(String)
- @Test(expected = NullPointerException.class)
- public void blowUpOnDirnameNull() throws Exception {
- FileUtils.dirname(null);
+ @Test
+ void blowUpOnDirnameNull() throws Exception {
+ assertThrows(NullPointerException.class, () -> FileUtils.dirname(null));
}
@Test
- public void dirnameEmpty() throws Exception {
- assertThat(FileUtils.dirname(""), is(""));
+ void dirnameEmpty() throws Exception {
+ assertThat(FileUtils.dirname("")).isEqualTo("");
}
@Test
- public void dirnameFilename() throws Exception {
- assertThat(FileUtils.dirname("foo.bar.txt"), is(""));
+ void dirnameFilename() throws Exception {
+ assertThat(FileUtils.dirname("foo.bar.txt")).isEqualTo("");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void dirnameWindowsRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.dirname("C:\\foo.bar.txt"), is(""));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void dirnameWindowsRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.dirname("C:\\foo.bar.txt")).isEqualTo("");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void dirnameWindowsNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt"), is(""));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void dirnameWindowsNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt")).isEqualTo("");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void dirnameUnixRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.dirname("/foo.bar.txt"), is(""));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void dirnameUnixRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.dirname("/foo.bar.txt")).isEqualTo("");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void dirnameUnixNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.dirname("/test/foo.bar.txt"), is(""));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void dirnameUnixNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.dirname("/test/foo.bar.txt")).isEqualTo("");
}
@Test
- public void dirnameWindowsRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.dirname("C:\\foo.bar.txt"), is("C:"));
+ @EnabledOnOs(WINDOWS)
+ void dirnameWindowsRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.dirname("C:\\foo.bar.txt")).isEqualTo("C:");
}
@Test
- public void dirnameWindowsNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt"), is("C:\\test"));
+ @EnabledOnOs(WINDOWS)
+ void dirnameWindowsNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt")).isEqualTo("C:\\test");
}
@Test
- public void dirnameUnixRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.dirname("/foo.bar.txt"), is(""));
+ @DisabledOnOs(WINDOWS)
+ void dirnameUnixRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.dirname("/foo.bar.txt")).isEqualTo("");
}
@Test
- public void dirnameUnixNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.dirname("/test/foo.bar.txt"), is("/test"));
+ @DisabledOnOs(WINDOWS)
+ void dirnameUnixNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.dirname("/test/foo.bar.txt")).isEqualTo("/test");
}
//// filename(String)
- @Test(expected = NullPointerException.class)
- public void blowUpOnFilenameNull() throws Exception {
- FileUtils.filename(null);
+ @Test
+ void blowUpOnFilenameNull() throws Exception {
+ assertThrows(NullPointerException.class, () -> FileUtils.filename(null));
}
@Test
- public void filenameEmpty() throws Exception {
- assertThat(FileUtils.filename(""), is(""));
+ void filenameEmpty() throws Exception {
+ assertThat(FileUtils.filename("")).isEqualTo("");
}
@Test
- public void filenameFilename() throws Exception {
- assertThat(FileUtils.filename("foo.bar.txt"), is("foo.bar.txt"));
+ void filenameFilename() throws Exception {
+ assertThat(FileUtils.filename("foo.bar.txt")).isEqualTo("foo.bar.txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void filenameWindowsRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.filename("C:\\foo.bar.txt"), is("C:\\foo.bar.txt"));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void filenameWindowsRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.filename("C:\\foo.bar.txt")).isEqualTo("C:\\foo.bar.txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void filenameWindowsNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.filename("C:\\test\\foo.bar.txt"), is("C:\\test\\foo.bar.txt"));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void filenameWindowsNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.filename("C:\\test\\foo.bar.txt")).isEqualTo("C:\\test\\foo.bar.txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void filenameUnixRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.filename("/foo.bar.txt"), is("/foo.bar.txt"));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void filenameUnixRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.filename("/foo.bar.txt")).isEqualTo("/foo.bar.txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void filenameUnixNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.filename("/test/foo.bar.txt"), is("/test/foo.bar.txt"));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void filenameUnixNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.filename("/test/foo.bar.txt")).isEqualTo("/test/foo.bar.txt");
}
@Test
- public void filenameWindowsRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.filename("C:\\foo.bar.txt"), is("foo.bar.txt"));
+ @EnabledOnOs(WINDOWS)
+ void filenameWindowsRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.filename("C:\\foo.bar.txt")).isEqualTo("foo.bar.txt");
}
@Test
- public void filenameWindowsNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.filename("C:\\test\\foo.bar.txt"), is("foo.bar.txt"));
+ @EnabledOnOs(WINDOWS)
+ void filenameWindowsNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.filename("C:\\test\\foo.bar.txt")).isEqualTo("foo.bar.txt");
}
@Test
- public void filenameUnixRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.filename("/foo.bar.txt"), is("foo.bar.txt"));
+ @DisabledOnOs(WINDOWS)
+ void filenameUnixRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.filename("/foo.bar.txt")).isEqualTo("foo.bar.txt");
}
@Test
- public void filenameUnixNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.filename("/test/foo.bar.txt"), is("foo.bar.txt"));
+ @DisabledOnOs(WINDOWS)
+ void filenameUnixNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.filename("/test/foo.bar.txt")).isEqualTo("foo.bar.txt");
}
//// extension(String)
- @Test(expected = NullPointerException.class)
- public void blowUpOnNullExtension() throws Exception {
- FileUtils.extension(null);
+ @Test
+ void blowUpOnNullExtension() throws Exception {
+ assertThrows(NullPointerException.class, () -> FileUtils.extension(null));
}
@Test
- public void extensionEmpty() throws Exception {
- assertThat(FileUtils.extension(""), is(""));
+ void extensionEmpty() throws Exception {
+ assertThat(FileUtils.extension("")).isEqualTo("");
}
@Test
- public void extensionFileName() throws Exception {
- assertThat(FileUtils.extension("foo.bar.txt"), is("txt"));
+ void extensionFileName() throws Exception {
+ assertThat(FileUtils.extension("foo.bar.txt")).isEqualTo("txt");
}
@Test
- public void extensionFileNameNoExtension() throws Exception {
- assertThat(FileUtils.extension("foo_bar_txt"), is(""));
+ void extensionFileNameNoExtension() throws Exception {
+ assertThat(FileUtils.extension("foo_bar_txt")).isEqualTo("");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void extensionWindowsRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.extension("C:\\foo.bar.txt"), is("txt"));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void extensionWindowsRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.extension("C:\\foo.bar.txt")).isEqualTo("txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void extensionWindowsNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.extension("C:\\test\\foo.bar.txt"), is("txt"));
+ @Test
+ @DisabledOnOs(WINDOWS)
+ void extensionWindowsNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.extension("C:\\test\\foo.bar.txt")).isEqualTo("txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void extensionUnixRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.extension("/foo.bar.txt"), is("txt"));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void extensionUnixRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.extension("/foo.bar.txt")).isEqualTo("txt");
}
- @Test
// X @ReproducesPlexusBug( "assumes that the path is a local path" )
- public void extensionUnixNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.extension("/test/foo.bar.txt"), is("txt"));
+ @Test
+ @EnabledOnOs(WINDOWS)
+ void extensionUnixNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.extension("/test/foo.bar.txt")).isEqualTo("txt");
}
@Test
- public void extensionWindowsRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.extension("C:\\foo.bar.txt"), is("txt"));
+ @EnabledOnOs(WINDOWS)
+ void extensionWindowsRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.extension("C:\\foo.bar.txt")).isEqualTo("txt");
}
@Test
- public void extensionWindowsNonRootPathOnWindows() throws Exception {
- assumeThat(File.separatorChar, is('\\'));
- assertThat(FileUtils.extension("C:\\test\\foo.bar.txt"), is("txt"));
+ @EnabledOnOs(WINDOWS)
+ void extensionWindowsNonRootPathOnWindows() throws Exception {
+ assertThat(FileUtils.extension("C:\\test\\foo.bar.txt")).isEqualTo("txt");
}
@Test
- @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
- public void isASymbolicLink() throws IOException {
- // This testcase will pass when running under java7 or higher
- assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
-
+ @Disabled("Wait until we can run with assembly 2.5 which will support symlinks properly")
+ @DisabledOnOs(WINDOWS)
+ void isASymbolicLink() throws IOException {
File file = new File("src/test/resources/symlinks/src/symDir");
assertTrue(FileUtils.isSymbolicLink(file));
}
@Test
- @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly")
- public void notASymbolicLink() throws IOException {
+ @Disabled("Wait until we can run with assembly 2.5 which will support symlinks properly")
+ void notASymbolicLink() throws IOException {
File file = new File("src/test/resources/symlinks/src/");
assertFalse(FileUtils.isSymbolicLink(file));
}
@Test
- public void extensionUnixRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.extension("/foo.bar.txt"), is("txt"));
+ @DisabledOnOs(WINDOWS)
+ void extensionUnixRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.extension("/foo.bar.txt")).isEqualTo("txt");
}
@Test
- public void extensionUnixNonRootPathOnUnix() throws Exception {
- assumeThat(File.separatorChar, is('/'));
- assertThat(FileUtils.extension("/test/foo.bar.txt"), is("txt"));
+ @DisabledOnOs(WINDOWS)
+ void extensionUnixNonRootPathOnUnix() throws Exception {
+ assertThat(FileUtils.extension("/test/foo.bar.txt")).isEqualTo("txt");
}
@Test
- public void createAndReadSymlink() throws Exception {
- assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
-
+ @DisabledOnOs(WINDOWS)
+ void createAndReadSymlink() throws Exception {
File file = new File("target/fzz");
FileUtils.createSymbolicLink(file, new File("../target"));
@@ -1240,12 +1187,10 @@
}
@Test
- public void createSymbolicLinkWithDifferentTargetOverwritesSymlink() throws Exception {
- assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
-
+ @DisabledOnOs(WINDOWS)
+ void createSymbolicLinkWithDifferentTargetOverwritesSymlink() throws Exception {
// Arrange
-
- final File symlink1 = new File(tempFolder.getRoot(), "symlink");
+ final File symlink1 = new File(tempDir, "symlink");
FileUtils.createSymbolicLink(symlink1, testFile1);
@@ -1255,7 +1200,7 @@
// Assert
- assertThat(Files.readSymbolicLink(symlink2.toPath()).toFile(), CoreMatchers.equalTo(testFile2));
+ assertThat(Files.readSymbolicLink(symlink2.toPath()).toFile()).isEqualTo(testFile2);
}
//// constants for testing
@@ -1317,4 +1262,13 @@
"**/-darcs-backup*",
"**/.darcs-temp-mail"
};
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
diff --git a/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java b/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java
index 06d04d9..6bb1258 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java
@@ -34,38 +34,41 @@
import java.io.Writer;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static java.nio.charset.StandardCharsets.UTF_16;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@SuppressWarnings("deprecation")
-public class IOUtilTest {
+class IOUtilTest {
private static final long INFINITE_LOOP_TIMEOUT = 500;
@Test
- public void closeReaderWithNull() throws Exception {
+ void closeReaderWithNull() throws Exception {
IOUtil.close((Reader) null);
}
@Test
- public void closeWriterWithNull() throws Exception {
+ void closeWriterWithNull() throws Exception {
IOUtil.close((Writer) null);
}
@Test
- public void closeInputStreamWithNull() throws Exception {
+ void closeInputStreamWithNull() throws Exception {
IOUtil.close(nullInputStream());
}
@Test
- public void closeOutputStreamWithNull() throws Exception {
+ void closeOutputStreamWithNull() throws Exception {
IOUtil.close(nullOutputStream());
}
@Test
- public void closeReaderWithIOE() throws Exception {
+ void closeReaderWithIOE() throws Exception {
IOUtil.close(new BufferedReader(new StringReader(emptyString())) {
@Override
public void close() throws IOException {
@@ -76,7 +79,7 @@
}
@Test
- public void closeWriterWithIOE() throws Exception {
+ void closeWriterWithIOE() throws Exception {
IOUtil.close(new BufferedWriter(new StringWriter()) {
@Override
public void close() throws IOException {
@@ -87,7 +90,7 @@
}
@Test
- public void closeInputStreamWithIOE() throws Exception {
+ void closeInputStreamWithIOE() throws Exception {
IOUtil.close(new BufferedInputStream(emptyInputStream()) {
@Override
public void close() throws IOException {
@@ -98,7 +101,7 @@
}
@Test
- public void closeOutputStreamWithIOE() throws Exception {
+ void closeOutputStreamWithIOE() throws Exception {
IOUtil.close(new BufferedOutputStream(new ByteArrayOutputStream()) {
@Override
public void close() throws IOException {
@@ -109,7 +112,7 @@
}
@Test
- public void closeReaderCloses() throws Exception {
+ void closeReaderCloses() throws Exception {
final AtomicBoolean closed = new AtomicBoolean(false);
IOUtil.close(new BufferedReader(new StringReader(emptyString())) {
@Override
@@ -118,11 +121,11 @@
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertThat(closed.get()).isEqualTo(true);
}
@Test
- public void closeWriterCloses() throws Exception {
+ void closeWriterCloses() throws Exception {
final AtomicBoolean closed = new AtomicBoolean(false);
IOUtil.close(new BufferedWriter(new StringWriter()) {
@Override
@@ -131,11 +134,11 @@
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertThat(closed.get()).isEqualTo(true);
}
@Test
- public void closeInputStreamCloses() throws Exception {
+ void closeInputStreamCloses() throws Exception {
final AtomicBoolean closed = new AtomicBoolean(false);
IOUtil.close(new BufferedInputStream(emptyInputStream()) {
@Override
@@ -144,11 +147,11 @@
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertThat(closed.get()).isEqualTo(true);
}
@Test
- public void closeOutputStreamCloses() throws Exception {
+ void closeOutputStreamCloses() throws Exception {
final AtomicBoolean closed = new AtomicBoolean(false);
IOUtil.close(new BufferedOutputStream(new ByteArrayOutputStream()) {
@Override
@@ -157,1655 +160,1881 @@
super.close();
}
});
- assertThat(closed.get(), is(true));
+ assertThat(closed.get()).isEqualTo(true);
}
@Test
- public void toByteArrayFromString() throws Exception {
+ void toByteArrayFromString() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe), is(probe.getBytes()));
+ assertThat(IOUtil.toByteArray(probe)).isEqualTo(probe.getBytes());
}
@Test
- public void toByteArrayFromReader() throws Exception {
+ void toByteArrayFromReader() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new StringReader(probe)), is(probe.getBytes()));
+ assertThat(IOUtil.toByteArray(new StringReader(probe))).isEqualTo(probe.getBytes());
}
@Test
- public void toByteArrayFromInputStream() throws Exception {
+ void toByteArrayFromInputStream() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullString() throws Exception {
- IOUtil.toByteArray((String) null);
- }
-
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullReader() throws Exception {
- IOUtil.toByteArray((Reader) null);
- }
-
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullInputStream() throws Exception {
- IOUtil.toByteArray(nullInputStream());
- }
-
- @Test(expected = IOException.class)
- public void contentEqualNullNull() throws Exception {
- IOUtil.contentEquals(null, null);
- }
-
- @Test(expected = IOException.class)
- public void contentEqualNonNullNull() throws Exception {
- IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null);
- }
-
- @Test(expected = IOException.class)
- public void contentEqualNullNonNull() throws Exception {
- IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null);
+ assertThat(IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))))
+ .isEqualTo(probe.getBytes());
}
@Test
- public void contentEqualEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
+ void toByteArrayNullString() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray((String) null));
+ }
+
+ @Test
+ void toByteArrayNullReader() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray((Reader) null));
+ }
+
+ @Test
+ void toByteArrayNullInputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray(nullInputStream()));
+ }
+
+ @Test
+ void contentEqualNullNull() throws Exception {
+ assertThrows(IOException.class, () -> IOUtil.contentEquals(null, null));
+ }
+
+ @Test
+ void contentEqualNonNullNull() throws Exception {
+ assertThrows(
+ IOException.class,
+ () -> IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null));
+ }
+
+ @Test
+ void contentEqualNullNonNull() throws Exception {
+ assertThrows(
+ IOException.class,
+ () -> IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null));
+ }
+
+ @Test
+ void contentEqualEmptyEmpty() throws Exception {
+ assertThat(IOUtil.contentEquals(
new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(true));
+ new DontCloseByteArrayInputStream(emptyByteArray())))
+ .isEqualTo(true);
}
@Test
- public void contentEqualNonEmptyEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
+ void contentEqualNonEmptyEmpty() throws Exception {
+ assertThat(IOUtil.contentEquals(
new DontCloseByteArrayInputStream(new byte[1]),
- new DontCloseByteArrayInputStream(emptyByteArray())),
- is(false));
+ new DontCloseByteArrayInputStream(emptyByteArray())))
+ .isEqualTo(false);
}
@Test
- public void contentEqualEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
+ void contentEqualEmptyNonEmpty() throws Exception {
+ assertThat(IOUtil.contentEquals(
new DontCloseByteArrayInputStream(emptyByteArray()),
- new DontCloseByteArrayInputStream(new byte[1])),
- is(false));
+ new DontCloseByteArrayInputStream(new byte[1])))
+ .isEqualTo(false);
}
@Test
- public void contentEqualNonEmptyNonEmpty() throws Exception {
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[1]), new DontCloseByteArrayInputStream(new byte[1])),
- is(true));
+ void contentEqualNonEmptyNonEmpty() throws Exception {
+ assertThat(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[1]), new DontCloseByteArrayInputStream(new byte[1])))
+ .isEqualTo(true);
}
@Test
- public void contentEqualMostlySame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
+ void contentEqualMostlySame() throws Exception {
+ assertThat(IOUtil.contentEquals(
new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6}),
- new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 7})),
- is(false));
+ new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 7})))
+ .isEqualTo(false);
}
@Test
- public void contentEqualLargeSame() throws Exception {
- assertThat(
- IOUtil.contentEquals(
+ void contentEqualLargeSame() throws Exception {
+ assertThat(IOUtil.contentEquals(
new DontCloseByteArrayInputStream(new byte[8192]),
- new DontCloseByteArrayInputStream(new byte[8192])),
- is(true));
+ new DontCloseByteArrayInputStream(new byte[8192])))
+ .isEqualTo(true);
}
@Test
- public void contentEqualLargeDifferent() throws Exception {
+ void contentEqualLargeDifferent() throws Exception {
byte[] buf = new byte[8192];
buf[8191] = 1;
- assertThat(
- IOUtil.contentEquals(
- new DontCloseByteArrayInputStream(new byte[8192]), new DontCloseByteArrayInputStream(buf)),
- is(false));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArray() throws Exception {
- IOUtil.toString(nullByteArray());
+ assertThat(IOUtil.contentEquals(
+ new DontCloseByteArrayInputStream(new byte[8192]), new DontCloseByteArrayInputStream(buf)))
+ .isEqualTo(false);
}
@Test
- public void toStringEmptyByteArray() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray()), is(emptyString()));
+ void toStringNullByteArray() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray()));
}
@Test
- public void toStringByteArray() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes()).getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayNegBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toStringEmptyByteArrayNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), -1), is(emptyString()));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toStringByteArrayNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), -1), is(probe));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullByteArrayZeroBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayPosBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), 1);
+ void toStringEmptyByteArray() throws Exception {
+ assertThat(IOUtil.toString(emptyByteArray())).isEqualTo(emptyString());
}
@Test
- public void toStringEmptyByteArrayPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), 1), is(emptyString()));
+ void toStringByteArray() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes()).getBytes()).isEqualTo(probe.getBytes());
}
@Test
- public void toStringByteArrayPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayNullEncoding() throws Exception {
- IOUtil.toString(nullByteArray(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringEmptyByteArrayNullEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), null), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringByteArrayNullEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null).getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayJunkEncoding() throws Exception {
- IOUtil.toString(nullByteArray(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringEmptyByteArrayJunkEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "junk"), is(emptyString()));
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringByteArrayJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), "junk").getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayValidEncoding() throws Exception {
- IOUtil.toString(nullByteArray(), "utf-16");
+ void toStringNullByteArrayNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), -1));
}
@Test
- public void toStringEmptyByteArrayValidEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "utf-16"), is(emptyString()));
+ void toStringEmptyByteArrayNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), -1))
+ .isEqualTo(emptyString()));
}
@Test
- public void toStringByteArrayValidEncoding() throws Exception {
+ void toStringByteArrayNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), -1)).isEqualTo(probe);
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullByteArrayZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), 0));
+ }
+
+ @Test
+ void toStringNullByteArrayPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), 1));
+ }
+
+ @Test
+ void toStringEmptyByteArrayPosBufSz() throws Exception {
+ assertThat(IOUtil.toString(emptyByteArray(), 1)).isEqualTo(emptyString());
+ }
+
+ @Test
+ void toStringByteArrayPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes("utf-16"), "utf-16").getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes()).isEqualTo(probe.getBytes());
}
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayNullEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), null, -1);
+ @Test
+ void toStringNullByteArrayNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), null));
}
- @Test(expected = NullPointerException.class)
- public void toStringEmptyByteArrayNullEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), null, -1), is(emptyString()));
+ @Test
+ void toStringEmptyByteArrayNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), null))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NullPointerException.class)
- public void toStringByteArrayNullEncodingNegBufSz() throws Exception {
+ @Test
+ void toStringByteArrayNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), null).getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void toStringNullByteArrayJunkEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "junk"));
+ }
+
+ @Test
+ void toStringEmptyByteArrayJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), "junk"))
+ .isEqualTo(emptyString()));
+ }
+
+ @Test
+ void toStringByteArrayJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), "junk").getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void toStringNullByteArrayValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "utf-16"));
+ }
+
+ @Test
+ void toStringEmptyByteArrayValidEncoding() throws Exception {
+ assertThat(IOUtil.toString(emptyByteArray(), "utf-16")).isEqualTo(emptyString());
+ }
+
+ @Test
+ void toStringByteArrayValidEncoding() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null, -1).getBytes(), is(probe.getBytes()));
+ assertThat(IOUtil.toString(probe.getBytes(UTF_16), "utf-16").getBytes(UTF_8))
+ .isEqualTo(probe.getBytes(UTF_8));
}
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayJunkEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), "junk", -1);
+ @Test
+ void toStringNullByteArrayNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), null, -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringEmptyByteArrayJunkEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "junk", -1), is(emptyString()));
+ @Test
+ void toStringEmptyByteArrayNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), null, -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringByteArrayJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), "junk", -1).getBytes(), is(probe.getBytes()));
+ @Test
+ void toStringByteArrayNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), null, -1).getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void toStringNullByteArrayValidEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), "utf-16", -1);
+ @Test
+ void toStringNullByteArrayJunkEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "junk", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void toStringEmptyByteArrayValidEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "utf-16", -1), is(emptyString()));
+ @Test
+ void toStringEmptyByteArrayJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), "junk", -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NegativeArraySizeException.class)
- public void toStringByteArrayValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(probe.getBytes("utf-16"), "utf-16", -1).getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ @Test
+ void toStringByteArrayJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), "junk", -1).getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullByteArrayNullEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), null, 0);
+ @Test
+ void toStringNullByteArrayValidEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "utf-16", -1));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringEmptyByteArrayNullEncodingZeroBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), null, 0), is(emptyString()));
+ @Test
+ void toStringEmptyByteArrayValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), "utf-16", -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringByteArrayNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), null, 0).getBytes(), is(probe.getBytes()));
+ @Test
+ void toStringByteArrayValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(UTF_16), "utf-16", -1).getBytes(UTF_8))
+ .isEqualTo(probe.getBytes(UTF_8));
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullByteArrayJunkEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullByteArrayNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), null, 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringEmptyByteArrayJunkEncodingZeroBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyByteArray(), "junk", 0), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringEmptyByteArrayNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), null, 0))
+ .isEqualTo(emptyString()));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringByteArrayJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(probe.getBytes(), "junk", 0).getBytes(), is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringByteArrayNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), null, 0).getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullByteArrayValidEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullByteArray(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullByteArrayJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "junk", 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringEmptyByteArrayJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> assertThat(IOUtil.toString(emptyByteArray(), "junk", 0))
+ .isEqualTo(emptyString()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringByteArrayJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(probe.getBytes(), "junk", 0).getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullByteArrayValidEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullByteArray(), "utf-16", 0));
}
/*
* copy(byte[],OutputStream)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullOutputStream() throws Exception {
- IOUtil.copy(nullByteArray(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidOutputStream() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullOutputStream() throws Exception {
- IOUtil.copy(emptyByteArray(), nullOutputStream());
+ @Test
+ void copyNullByteArrayNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullOutputStream()));
}
@Test
- public void copyEmptyByteArrayValidOutputStream() throws Exception {
+ void copyNullByteArrayValidOutputStream() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidOutputStream() throws Exception {
IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
}
@Test
- public void copyByteArrayValidOutputStream() throws Exception {
+ void copyByteArrayValidOutputStream() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(input, outputStream);
- assertThat(outputStream.toByteArray(), is(input));
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
}
/*
* copy(byte[],OutputStream,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullOutputStream());
+ @Test
+ void copyNullByteArrayNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullOutputStream()));
}
@Test
- public void copyEmptyByteArrayValidOutputStreamNegBufSz() throws Exception {
+ void copyNullByteArrayValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidOutputStreamNegBufSz() throws Exception {
IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
}
@Test
- public void copyByteArrayValidOutputStreamNegBufSz() throws Exception {
+ void copyByteArrayValidOutputStreamNegBufSz() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(input, outputStream);
- assertThat(outputStream.toByteArray(), is(input));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullOutputStream());
- }
-
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayValidOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayValidOutputStreamZeroBufSz() throws Exception {
- ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
- byte[] input = {1, 2, 3, 4, 5, 6};
- IOUtil.copy(input, outputStream);
- assertThat(outputStream.toByteArray(), is(input));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullOutputStream());
- }
-
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayValidOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayValidOutputStreamPosBufSz() throws Exception {
- ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
- byte[] input = {1, 2, 3, 4, 5, 6};
- IOUtil.copy(input, outputStream);
- assertThat(outputStream.toByteArray(), is(input));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullOutputStream() throws Exception {
- IOUtil.copy(nullInputStream(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidOutputStream() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream());
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
}
@Test
- public void copyEmptyInputStreamNullOutputStream() throws Exception {
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidOutputStreamZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayValidOutputStreamZeroBufSz() throws Exception {
+ IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayValidOutputStreamZeroBufSz() throws Exception {
+ ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
+ byte[] input = {1, 2, 3, 4, 5, 6};
+ IOUtil.copy(input, outputStream);
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidOutputStreamPosBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullOutputStream()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayValidOutputStreamPosBufSz() throws Exception {
+ IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream());
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayValidOutputStreamPosBufSz() throws Exception {
+ ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
+ byte[] input = {1, 2, 3, 4, 5, 6};
+ IOUtil.copy(input, outputStream);
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
+ }
+
+ @Test
+ void copyNullInputStreamNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullOutputStream()));
+ }
+
+ @Test
+ void copyNullInputStreamValidOutputStream() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ void copyEmptyInputStreamNullOutputStream() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream());
}
@Test
- public void copyEmptyInputStreamValidOutputStream() throws Exception {
+ void copyEmptyInputStreamValidOutputStream() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream());
}
@Test
- public void copyInputStreamValidOutputStream() throws Exception {
+ void copyInputStreamValidOutputStream() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream);
- assertThat(outputStream.toByteArray(), is(input));
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyNullInputStreamNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullOutputStream(), -1);
+ @Test
+ void copyNullInputStreamNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(nullInputStream(), nullOutputStream(), -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyNullInputStreamValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream(), -1);
+ @Test
+ void copyNullInputStreamValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream(), -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), -1);
+ @Test
+ void copyEmptyInputStreamNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), -1);
+ @Test
+ void copyEmptyInputStreamValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(
+ new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyInputStreamValidOutputStreamNegBufSz() throws Exception {
- ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
- byte[] input = {1, 2, 3, 4, 5, 6};
- IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, -1);
- assertThat(outputStream.toByteArray(), is(input));
+ @Test
+ void copyInputStreamValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
+ byte[] input = {1, 2, 3, 4, 5, 6};
+ IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, -1);
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullOutputStream(), 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullOutputStream(), 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 0));
}
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamNullOutputStreamZeroBufSz() throws Exception {
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamNullOutputStreamZeroBufSz() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), 0);
}
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamValidOutputStreamZeroBufSz() throws Exception {
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamValidOutputStreamZeroBufSz() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), 0);
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullOutputStream(), 1);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullOutputStream(), 1));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 1);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 1));
}
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamNullOutputStreamPosBufSz() throws Exception {
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamNullOutputStreamPosBufSz() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), 1);
}
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamValidOutputStreamPosBufSz() throws Exception {
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamValidOutputStreamPosBufSz() throws Exception {
IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), 1);
}
- @Test(timeout = INFINITE_LOOP_TIMEOUT)
- public void copyInputStreamValidOutputStreamPosBufSz() throws Exception {
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyInputStreamValidOutputStreamPosBufSz() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
byte[] input = {1, 2, 3, 4, 5, 6};
IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, 1);
- assertThat(outputStream.toByteArray(), is(input));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStream() throws Exception {
- IOUtil.toString(nullInputStream());
+ assertThat(outputStream.toByteArray()).isEqualTo(input);
}
@Test
- public void toStringEmptyInputStream() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream()), is(emptyString()));
+ void toStringNullInputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream()));
}
@Test
- public void toStringInputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes())).getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamNegBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toStringEmptyInputStreamNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), -1), is(emptyString()));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toStringInputStreamNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), -1), is(probe));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullInputStreamZeroBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamPosBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), 1);
+ void toStringEmptyInputStream() throws Exception {
+ assertThat(IOUtil.toString(emptyInputStream())).isEqualTo(emptyString());
}
@Test
- public void toStringEmptyInputStreamPosBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), 1), is(emptyString()));
+ void toStringInputStream() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes())).getBytes())
+ .isEqualTo(probe.getBytes());
}
@Test
- public void toStringInputStreamPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), 1).getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamNullEncoding() throws Exception {
- IOUtil.toString(nullInputStream(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringEmptyInputStreamNullEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), null), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringInputStreamNullEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null)
- .getBytes(),
- is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamJunkEncoding() throws Exception {
- IOUtil.toString(nullInputStream(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringEmptyInputStreamJunkEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), "junk"), is(emptyString()));
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringInputStreamJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk")
- .getBytes(),
- is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamValidEncoding() throws Exception {
- IOUtil.toString(nullInputStream(), "utf-16");
+ void toStringNullInputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), -1));
}
@Test
- public void toStringEmptyInputStreamValidEncoding() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), "utf-16"), is(emptyString()));
+ void toStringEmptyInputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), -1))
+ .isEqualTo(emptyString()));
}
@Test
- public void toStringInputStreamValidEncoding() throws Exception {
+ void toStringInputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), -1))
+ .isEqualTo(probe);
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullInputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), 0));
+ }
+
+ @Test
+ void toStringNullInputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), 1));
+ }
+
+ @Test
+ void toStringEmptyInputStreamPosBufSz() throws Exception {
+ assertThat(IOUtil.toString(emptyInputStream(), 1)).isEqualTo(emptyString());
+ }
+
+ @Test
+ void toStringInputStreamPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes("utf-16")), "utf-16")
- .getBytes("utf-8"),
- is(probe.getBytes("utf-8")));
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), 1)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
}
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamNullEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), null, -1);
+ @Test
+ void toStringNullInputStreamNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), null));
}
- @Test(expected = NullPointerException.class)
- public void toStringEmptyInputStreamNullEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), null, -1), is(emptyString()));
+ @Test
+ void toStringEmptyInputStreamNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), null))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NullPointerException.class)
- public void toStringInputStreamNullEncodingNegBufSz() throws Exception {
+ @Test
+ void toStringInputStreamNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void toStringNullInputStreamJunkEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "junk"));
+ }
+
+ @Test
+ void toStringEmptyInputStreamJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), "junk"))
+ .isEqualTo(emptyString()));
+ }
+
+ @Test
+ void toStringInputStreamJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk")
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void toStringNullInputStreamValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "utf-16"));
+ }
+
+ @Test
+ void toStringEmptyInputStreamValidEncoding() throws Exception {
+ assertThat(IOUtil.toString(emptyInputStream(), "utf-16")).isEqualTo(emptyString());
+ }
+
+ @Test
+ void toStringInputStreamValidEncoding() throws Exception {
String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, -1)
- .getBytes(),
- is(probe.getBytes()));
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes(UTF_16)), "utf-16")
+ .getBytes(UTF_8))
+ .isEqualTo(probe.getBytes(UTF_8));
}
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamJunkEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), "junk", -1);
+ @Test
+ void toStringNullInputStreamNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), null, -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringEmptyInputStreamJunkEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), "junk", -1), is(emptyString()));
+ @Test
+ void toStringEmptyInputStreamNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), null, -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void toStringInputStreamJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", -1)
- .getBytes(),
- is(probe.getBytes()));
+ @Test
+ void toStringInputStreamNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, -1)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void toStringNullInputStreamValidEncodingNegBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), "utf-16", -1);
+ @Test
+ void toStringNullInputStreamJunkEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "junk", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void toStringEmptyInputStreamValidEncodingNegBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), "utf-16", -1), is(emptyString()));
+ @Test
+ void toStringEmptyInputStreamJunkEncodingNegBufSz() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), "junk", -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NegativeArraySizeException.class)
- public void toStringInputStreamValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes("utf-16")), "utf-16", -1)
- .getBytes("utf-8"),
- is(probe.getBytes("utf-8")));
+ @Test
+ void toStringInputStreamJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", -1)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullInputStreamNullEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), null, 0);
+ @Test
+ void toStringNullInputStreamValidEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "utf-16", -1));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringEmptyInputStreamNullEncodingZeroBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), null, 0), is(emptyString()));
+ @Test
+ void toStringEmptyInputStreamValidEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), "utf-16", -1))
+ .isEqualTo(emptyString()));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringInputStreamNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, 0)
- .getBytes(),
- is(probe.getBytes()));
+ @Test
+ void toStringInputStreamValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes(UTF_16)), "utf-16", -1)
+ .getBytes(UTF_8))
+ .isEqualTo(probe.getBytes(UTF_8));
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullInputStreamJunkEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullInputStreamNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), null, 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringEmptyInputStreamJunkEncodingZeroBufSz() throws Exception {
- assertThat(IOUtil.toString(emptyInputStream(), "junk", 0), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringEmptyInputStreamNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> assertThat(IOUtil.toString(emptyInputStream(), null, 0))
+ .isEqualTo(emptyString()));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringInputStreamJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", 0)
- .getBytes(),
- is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringInputStreamNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, 0)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void toStringNullInputStreamValidEncodingZeroBufSz() throws Exception {
- IOUtil.toString(nullInputStream(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullInputStreamJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "junk", 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringEmptyInputStreamJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class,
+ () -> assertThat(IOUtil.toString(emptyInputStream(), "junk", 0)).isEqualTo(emptyString()));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringInputStreamJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", 0)
+ .getBytes())
+ .isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void toStringNullInputStreamValidEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullInputStream(), "utf-16", 0));
}
/*
* copy(InputStream,Writer)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriter() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamNullWriter() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter());
+ @Test
+ void copyNullInputStreamNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter()));
}
@Test
- public void copyEmptyInputStreamValidWriter() throws Exception {
+ void copyEmptyInputStreamNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter()));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyInputStreamNullWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter());
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyInputStreamValidWriter() throws Exception {
+ void copyInputStreamNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter());
+ });
+ }
+
+ @Test
+ void copyInputStreamValidWriter() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
}
/*
* copy(InputStream,Writer,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamNullWriterNegBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamValidWriterNegBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyInputStreamNullWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyInputStreamValidWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterPosBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterPosBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamNullWriterPosBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), 1);
+ @Test
+ void copyNullInputStreamNullWriterNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), -1));
}
@Test
- public void copyEmptyInputStreamValidWriterPosBufSz() throws Exception {
+ void copyEmptyInputStreamNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), -1));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriterNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), -1));
+ }
+
+ @Test
+ void copyInputStreamNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), -1);
+ });
+ }
+
+ @Test
+ void copyInputStreamValidWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), 0));
+ }
+
+ @Test
+ void copyNullInputStreamNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyNullInputStreamValidWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyInputStreamNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriterPosBufSz() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, 1);
- assertThat(writer.toString(), is(emptyString()));
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyInputStreamValidWriterPosBufSz() throws Exception {
+ void copyInputStreamValidWriterPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, 1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
}
/*
* copy(InputStream,Writer,String)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterNullEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterNullEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamNullWriterNullEncoding() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamValidWriterNullEncoding() throws Exception {
- IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyInputStreamNullEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterJunkEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "junk");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterJunkEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyInputStreamNullWriterJunkEncoding() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyInputStreamValidWriterJunkEncoding() throws Exception {
- IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyInputStreamNullWriterJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyInputStreamValidWriterJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk");
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterValidEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "utf-16");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamNullWriterValidEncoding() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterValidEncoding() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16");
+ @Test
+ void copyNullInputStreamNullWriterNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), null));
}
@Test
- public void copyEmptyInputStreamValidWriterValidEncoding() throws Exception {
+ void copyNullInputStreamValidWriterNullEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null));
+ }
+
+ @Test
+ void copyEmptyInputStreamNullWriterNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), null));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriterNullEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), null));
+ }
+
+ @Test
+ void copyInputStreamNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void copyNullInputStreamNullWriterJunkEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "junk"));
+ }
+
+ @Test
+ void copyNullInputStreamValidWriterJunkEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk"));
+ }
+
+ @Test
+ void copyEmptyInputStreamNullWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), "junk"));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriterJunkEncoding() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class,
+ () -> IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), "junk"));
+ }
+
+ @Test
+ void copyInputStreamNullWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk");
+ });
+ }
+
+ @Test
+ void copyInputStreamValidWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk");
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void copyNullInputStreamNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyEmptyInputStreamNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyNullInputStreamValidWriterValidEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyEmptyInputStreamValidWriterValidEncoding() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyInputStream(), writer, "utf-16");
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyInputStreamNullWriterValidEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), nullWriter(), "utf-16");
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyInputStreamValidWriterValidEncoding() throws Exception {
+ void copyInputStreamNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), nullWriter(), "utf-16");
+ });
+ }
+
+ @Test
+ void copyInputStreamValidWriterValidEncoding() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), writer, "utf-16");
- assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes(UTF_16)), writer, "utf-16");
+ assertThat(writer.toString().getBytes(UTF_8)).isEqualTo(probe.getBytes(UTF_8));
}
/*
* copy(InputStream,Writer,String,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), null, -1);
+ @Test
+ void copyNullInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, -1);
+ @Test
+ void copyNullInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), null, -1);
+ @Test
+ void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyInputStream(), writer, null, -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyInputStream(), writer, null, -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, -1);
+ @Test
+ void copyInputStreamNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, -1);
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ void copyInputStreamValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "junk", -1);
+ @Test
+ void copyNullInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "junk", -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", -1);
+ @Test
+ void copyNullInputStreamValidWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), "junk", -1);
+ @Test
+ void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), "junk", -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyInputStreamJunkEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyInputStream(), writer, "junk", -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyInputStreamJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyInputStream(), writer, "junk", -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", -1);
+ @Test
+ void copyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", -1);
+ });
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyInputStreamValidWriterJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ void copyInputStreamValidWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", -1);
+ @Test
+ void copyNullInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullInputStreamValidWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", -1);
+ @Test
+ void copyNullInputStreamValidWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16", -1);
+ @Test
+ void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyInputStream(), writer, "utf-16", -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyInputStream(), writer, "utf-16", -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), nullWriter(), -1);
+ @Test
+ void copyInputStreamNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes(UTF_16)), nullWriter(), -1);
+ });
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyInputStreamValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), writer, "utf-16", -1);
- assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ @Test
+ void copyInputStreamValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes(UTF_16)), writer, "utf-16", -1);
+ assertThat(writer.toString().getBytes(UTF_8)).isEqualTo(probe.getBytes(UTF_8));
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyInputStream(), writer, null, 0);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyInputStream(), writer, null, 0);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, 0);
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, 0);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, 0);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "junk", 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(emptyInputStream(), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class, () -> IOUtil.copy(emptyInputStream(), nullWriter(), "junk", 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyInputStream(), writer, "junk", 0);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyInputStream(), writer, "junk", 0);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", 0);
+ });
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", 0);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", 0);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamNullWriterValidEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamNullWriterValidEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullInputStreamValidWriterValidEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullInputStreamValidWriterValidEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", 0));
}
/*
* copy(String,Writer)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullStringNullWriter() throws Exception {
- IOUtil.copy(nullString(), nullWriter());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyStringNullWriter() throws Exception {
- IOUtil.copy(emptyString(), nullWriter());
+ @Test
+ void copyNullStringNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), nullWriter()));
}
@Test
- public void copyNullStringValidWriter() throws Exception {
+ void copyEmptyStringNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyString(), nullWriter()));
+ }
+
+ @Test
+ void copyNullStringValidWriter() throws Exception {
IOUtil.copy(nullString(), new DontCloseStringWriter());
}
@Test
- public void copyEmptyStringValidWriter() throws Exception {
+ void copyEmptyStringValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyString(), writer);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyStringNullWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe, nullWriter());
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyStringValidWriter() throws Exception {
+ void copyStringNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe, nullWriter());
+ });
+ }
+
+ @Test
+ void copyStringValidWriter() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe, writer);
- assertThat(writer.toString(), is(probe));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringNullOutputStream() throws Exception {
- IOUtil.copy(nullString(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyStringNullOutputStream() throws Exception {
- IOUtil.copy(emptyString(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringValidOutputStream() throws Exception {
- IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream());
+ assertThat(writer.toString()).isEqualTo(probe);
}
@Test
- public void copyEmptyStringValidOutputStream() throws Exception {
+ void copyNullStringNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), nullOutputStream()));
+ }
+
+ @Test
+ void copyEmptyStringNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyString(), nullOutputStream()));
+ }
+
+ @Test
+ void copyNullStringValidOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ void copyEmptyStringValidOutputStream() throws Exception {
ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
IOUtil.copy(emptyString(), OutputStream);
- assertThat(OutputStream.toByteArray(), is(emptyString().getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyStringNullOutputStream() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe, nullOutputStream());
+ assertThat(OutputStream.toByteArray()).isEqualTo(emptyString().getBytes());
}
@Test
- public void copyStringValidOutputStream() throws Exception {
+ void copyStringNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe, nullOutputStream());
+ });
+ }
+
+ @Test
+ void copyStringValidOutputStream() throws Exception {
String probe = "A string \u2345\u00ef";
ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
IOUtil.copy(probe, OutputStream);
- assertThat(OutputStream.toByteArray(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullString(), nullOutputStream(), -1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyStringNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(emptyString(), nullOutputStream(), -1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyStringValidOutputStreamNegBufSz() throws Exception {
- ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
- IOUtil.copy(emptyString(), OutputStream, -1);
- assertThat(OutputStream.toByteArray(), is(emptyString().getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyStringNullOutputStreamNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe, nullOutputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyStringValidOutputStreamNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
- IOUtil.copy(probe, OutputStream, -1);
- assertThat(OutputStream.toByteArray(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullStringNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullString(), nullOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyStringNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(emptyString(), nullOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullStringValidOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullString(), nullOutputStream(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyStringNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(emptyString(), nullOutputStream(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullStringValidOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 1);
+ assertThat(OutputStream.toByteArray()).isEqualTo(probe.getBytes());
}
@Test
- public void copyEmptyStringValidOutputStreamPosBufSz() throws Exception {
+ void copyNullStringNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), nullOutputStream(), -1));
+ }
+
+ @Test
+ void copyEmptyStringNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyString(), nullOutputStream(), -1));
+ }
+
+ @Test
+ void copyNullStringValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), -1));
+ }
+
+ @Test
+ void copyEmptyStringValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+ IOUtil.copy(emptyString(), OutputStream, -1);
+ assertThat(OutputStream.toByteArray()).isEqualTo(emptyString().getBytes());
+ });
+ }
+
+ @Test
+ void copyStringNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe, nullOutputStream(), -1);
+ });
+ }
+
+ @Test
+ void copyStringValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+ IOUtil.copy(probe, OutputStream, -1);
+ assertThat(OutputStream.toByteArray()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullStringNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), nullOutputStream(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyStringNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyString(), nullOutputStream(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullStringValidOutputStreamZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 0));
+ }
+
+ @Test
+ void copyNullStringNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullString(), nullOutputStream(), 1));
+ }
+
+ @Test
+ void copyEmptyStringNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyString(), nullOutputStream(), 1));
+ }
+
+ @Test
+ void copyNullStringValidOutputStreamPosBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 1));
+ }
+
+ @Test
+ void copyEmptyStringValidOutputStreamPosBufSz() throws Exception {
ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
IOUtil.copy(emptyString(), OutputStream, 1);
- assertThat(OutputStream.toByteArray(), is(emptyString().getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyStringNullOutputStreamPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe, nullOutputStream(), 1);
+ assertThat(OutputStream.toByteArray()).isEqualTo(emptyString().getBytes());
}
@Test
- public void copyStringValidOutputStreamPosBufSz() throws Exception {
+ void copyStringNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe, nullOutputStream(), 1);
+ });
+ }
+
+ @Test
+ void copyStringValidOutputStreamPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
IOUtil.copy(probe, OutputStream, 1);
- assertThat(OutputStream.toByteArray(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderNullWriter() throws Exception {
- IOUtil.copy(nullReader(), nullWriter());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyReaderNullWriter() throws Exception {
- IOUtil.copy(emptyReader(), nullWriter());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderValidWriter() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseStringWriter());
+ assertThat(OutputStream.toByteArray()).isEqualTo(probe.getBytes());
}
@Test
- public void copyEmptyReaderValidWriter() throws Exception {
+ void copyNullReaderNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullWriter()));
+ }
+
+ @Test
+ void copyEmptyReaderNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullWriter()));
+ }
+
+ @Test
+ void copyNullReaderValidWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseStringWriter()));
+ }
+
+ @Test
+ void copyEmptyReaderValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyReader(), writer);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyReaderNullWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new StringReader(probe), nullWriter());
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyReaderValidWriter() throws Exception {
+ void copyReaderNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new StringReader(probe), nullWriter());
+ });
+ }
+
+ @Test
+ void copyReaderValidWriter() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new StringReader(probe), writer);
- assertThat(writer.toString(), is(probe));
+ assertThat(writer.toString()).isEqualTo(probe);
}
/*
* copy(Reader,Writer,int)
*/
- @Test(expected = NegativeArraySizeException.class)
- public void copyNullReaderNullWriterNegBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyReaderNullWriterNegBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyNullReaderValidWriterNegBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseStringWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyReaderValidWriterNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyReader(), writer, -1);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyReaderNullWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new StringReader(probe), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyReaderValidWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(new StringReader(probe), writer, -1);
- assertThat(writer.toString(), is(probe));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullReaderNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyReaderNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullReaderValidWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseStringWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderNullWriterPosBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyReaderNullWriterPosBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderValidWriterPosBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseStringWriter(), 1);
+ @Test
+ void copyNullReaderNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(nullReader(), nullWriter(), -1));
}
@Test
- public void copyEmptyReaderValidWriterPosBufSz() throws Exception {
+ void copyEmptyReaderNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(emptyReader(), nullWriter(), -1));
+ }
+
+ @Test
+ void copyNullReaderValidWriterNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class, () -> IOUtil.copy(nullReader(), new DontCloseStringWriter(), -1));
+ }
+
+ @Test
+ void copyEmptyReaderValidWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyReader(), writer, -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
+ }
+
+ @Test
+ void copyReaderNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new StringReader(probe), nullWriter(), -1);
+ });
+ }
+
+ @Test
+ void copyReaderValidWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(new StringReader(probe), writer, -1);
+ assertThat(writer.toString()).isEqualTo(probe);
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullReaderNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyReaderNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullReaderValidWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseStringWriter(), 0));
+ }
+
+ @Test
+ void copyNullReaderNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyReaderNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyNullReaderValidWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseStringWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyReaderValidWriterPosBufSz() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyReader(), writer, 1);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyReaderNullWriterPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new StringReader(probe), nullWriter(), 1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyReaderValidWriterPosBufSz() throws Exception {
+ void copyReaderNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new StringReader(probe), nullWriter(), 1);
+ });
+ }
+
+ @Test
+ void copyReaderValidWriterPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(new StringReader(probe), writer, 1);
- assertThat(writer.toString(), is(probe));
+ assertThat(writer.toString()).isEqualTo(probe);
}
/*
* toByteArray(InputStream,int)
*/
- @Test(expected = NegativeArraySizeException.class)
- public void toByteArrayFromInputStreamNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), -1),
- is(probe.getBytes()));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toByteArrayNullInputStreamNegBufSz() throws Exception {
- IOUtil.toByteArray(nullInputStream(), -1);
+ @Test
+ void toByteArrayFromInputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), -1))
+ .isEqualTo(probe.getBytes());
+ });
}
@Test
- public void toByteArrayFromInputStreamPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(
- IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), +1),
- is(probe.getBytes()));
+ void toByteArrayNullInputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.toByteArray(nullInputStream(), -1));
}
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullInputStreamPosBufSz() throws Exception {
- IOUtil.toByteArray(nullInputStream(), +1);
+ @Test
+ void toByteArrayFromInputStreamPosBufSz() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), +1))
+ .isEqualTo(probe.getBytes());
+ }
+
+ @Test
+ void toByteArrayNullInputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray(nullInputStream(), +1));
}
/*
* toByteArray(Reader,int)
*/
- @Test(expected = NegativeArraySizeException.class)
- public void toByteArrayFromReaderNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), -1), is(probe.getBytes()));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toByteArrayNullReaderNegBufSz() throws Exception {
- IOUtil.toByteArray(nullReader(), -1);
+ @Test
+ void toByteArrayFromReaderNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), -1)).isEqualTo(probe.getBytes());
+ });
}
@Test
- public void toByteArrayFromReaderPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), +1), is(probe.getBytes()));
+ void toByteArrayNullReaderNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.toByteArray(nullReader(), -1));
}
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullReaderPosBufSz() throws Exception {
- IOUtil.toByteArray(nullReader(), +1);
+ @Test
+ void toByteArrayFromReaderPosBufSz() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), +1)).isEqualTo(probe.getBytes());
+ }
+
+ @Test
+ void toByteArrayNullReaderPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray(nullReader(), +1));
}
/*
* toByteArray(String,int)
*/
- @Test(expected = NegativeArraySizeException.class)
- public void toByteArrayFromStringNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe, -1), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullStringNegBufSz() throws Exception {
- IOUtil.toByteArray(nullString(), -1);
+ @Test
+ void toByteArrayFromStringNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(probe, -1)).isEqualTo(probe.getBytes());
+ });
}
@Test
- public void toByteArrayFromStringPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toByteArray(probe, +1), is(probe.getBytes()));
+ void toByteArrayNullStringNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray(nullString(), -1));
}
- @Test(expected = NullPointerException.class)
- public void toByteArrayNullStringPosBufSz() throws Exception {
- IOUtil.toByteArray(nullString(), +1);
+ @Test
+ void toByteArrayFromStringPosBufSz() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toByteArray(probe, +1)).isEqualTo(probe.getBytes());
+ }
+
+ @Test
+ void toByteArrayNullStringPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toByteArray(nullString(), +1));
}
/*
* toString(Reader,int)
*/
- @Test(expected = NegativeArraySizeException.class)
- public void toStringFromReaderNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new DontCloseStringReader(probe), -1), is(probe));
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void toStringNullReaderNegBufSz() throws Exception {
- IOUtil.toString(nullReader(), -1);
+ @Test
+ void toStringFromReaderNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new DontCloseStringReader(probe), -1)).isEqualTo(probe);
+ });
}
@Test
- public void toStringFromReaderPosBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- assertThat(IOUtil.toString(new DontCloseStringReader(probe), +1), is(probe));
+ void toStringNullReaderNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.toString(nullReader(), -1));
}
- @Test(expected = NullPointerException.class)
- public void toStringNullReaderPosBufSz() throws Exception {
- IOUtil.toString(nullReader(), +1);
+ @Test
+ void toStringFromReaderPosBufSz() throws Exception {
+ String probe = "A string \u2345\u00ef";
+ assertThat(IOUtil.toString(new DontCloseStringReader(probe), +1)).isEqualTo(probe);
+ }
+
+ @Test
+ void toStringNullReaderPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.toString(nullReader(), +1));
}
/*
* copy(Reader,OutputStream)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullReaderNullOutputStream() throws Exception {
- IOUtil.copy(nullReader(), nullOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderValidOutputStream() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyReaderNullOutputStream() throws Exception {
- IOUtil.copy(emptyReader(), nullOutputStream());
+ @Test
+ void copyNullReaderNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullOutputStream()));
}
@Test
- public void copyEmptyReaderValidOutputStream() throws Exception {
+ void copyNullReaderValidOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream()));
+ }
+
+ @Test
+ void copyEmptyReaderNullOutputStream() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullOutputStream()));
+ }
+
+ @Test
+ void copyEmptyReaderValidOutputStream() throws Exception {
IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream());
}
@Test
- public void copyReaderValidOutputStream() throws Exception {
+ void copyReaderValidOutputStream() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
String probe = "A string \u2345\u00ef";
IOUtil.copy(new DontCloseStringReader(probe), outputStream);
- assertThat(outputStream.toByteArray(), is(probe.getBytes()));
+ assertThat(outputStream.toByteArray()).isEqualTo(probe.getBytes());
}
/*
* copy(Reader,OutputStream,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullReaderNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullOutputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyNullReaderValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), -1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyReaderNullOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullOutputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyReaderValidOutputStreamNegBufSz() throws Exception {
- IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyReaderValidOutputStreamNegBufSz() throws Exception {
- ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(new DontCloseStringReader(probe), outputStream, -1);
- assertThat(outputStream.toByteArray(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullReaderNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullReaderValidOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyReaderNullOutputStreamZeroBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullOutputStream(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullReader(), nullOutputStream(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullReaderValidOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyReaderNullOutputStreamPosBufSz() throws Exception {
- IOUtil.copy(emptyReader(), nullOutputStream(), 1);
+ @Test
+ void copyNullReaderNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullOutputStream(), -1));
}
@Test
- public void copyEmptyReaderValidOutputStreamPosBufSz() throws Exception {
+ void copyNullReaderValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), -1));
+ }
+
+ @Test
+ void copyEmptyReaderNullOutputStreamNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullOutputStream(), -1));
+ }
+
+ @Test
+ void copyEmptyReaderValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class,
+ () -> IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream(), -1));
+ }
+
+ @Test
+ void copyReaderValidOutputStreamNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(new DontCloseStringReader(probe), outputStream, -1);
+ assertThat(outputStream.toByteArray()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullReaderNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullOutputStream(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullReaderValidOutputStreamZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyReaderNullOutputStreamZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullOutputStream(), 0));
+ }
+
+ @Test
+ void copyNullReaderNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullReader(), nullOutputStream(), 1));
+ }
+
+ @Test
+ void copyNullReaderValidOutputStreamPosBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 1));
+ }
+
+ @Test
+ void copyEmptyReaderNullOutputStreamPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyReader(), nullOutputStream(), 1));
+ }
+
+ @Test
+ void copyEmptyReaderValidOutputStreamPosBufSz() throws Exception {
IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream(), 1);
}
@Test
- public void copyReaderValidOutputStreamPosBufSz() throws Exception {
+ void copyReaderValidOutputStreamPosBufSz() throws Exception {
ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
String probe = "A string \u2345\u00ef";
IOUtil.copy(new DontCloseStringReader(probe), outputStream, 1);
- assertThat(outputStream.toByteArray(), is(probe.getBytes()));
+ assertThat(outputStream.toByteArray()).isEqualTo(probe.getBytes());
}
/*
@@ -1827,409 +2056,485 @@
* copy(byte[],Writer)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriter() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter());
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullWriter() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter());
+ @Test
+ void copyNullByteArrayNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter()));
}
@Test
- public void copyEmptyByteArrayValidWriter() throws Exception {
+ void copyEmptyByteArrayNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter()));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriter() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer);
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyByteArrayNullWriter() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter());
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyByteArrayValidWriter() throws Exception {
+ void copyByteArrayNullWriter() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter());
+ });
+ }
+
+ @Test
+ void copyByteArrayValidWriter() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe.getBytes(), writer);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
}
/*
* copy(byte[],Writer,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyByteArrayNullWriterNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyByteArrayValidWriterNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyByteArrayNullWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), -1);
- }
-
- @Test(expected = NegativeArraySizeException.class)
- public void copyByteArrayValidWriterNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidWriterZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayNullWriterZeroBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), 0);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterPosBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterPosBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 1);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullWriterPosBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), 1);
+ @Test
+ void copyNullByteArrayNullWriterNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), -1));
}
@Test
- public void copyEmptyByteArrayValidWriterPosBufSz() throws Exception {
+ void copyEmptyByteArrayNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), -1));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriterNegBufSz() throws Exception {
+ assertThrows(
+ NegativeArraySizeException.class, () -> IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), -1));
+ }
+
+ @Test
+ void copyByteArrayNullWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), -1);
+ });
+ }
+
+ @Test
+ void copyByteArrayValidWriterNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 0));
+ }
+
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayNullWriterZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), 0));
+ }
+
+ @Test
+ void copyNullByteArrayNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyNullByteArrayValidWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullWriterPosBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), 1));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriterPosBufSz() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, 1);
- assertThat(writer.toString(), is(emptyString()));
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyByteArrayValidWriterPosBufSz() throws Exception {
+ void copyByteArrayValidWriterPosBufSz() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(probe.getBytes(), writer, 1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
}
/*
* copy(byte[],Writer,String)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterNullEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterNullEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullWriterNullEncoding() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayValidWriterNullEncoding() throws Exception {
- IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), null);
- }
-
- @Test(expected = NullPointerException.class)
- public void copyByteArrayNullEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, null);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterJunkEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "junk");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterJunkEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyByteArrayNullWriterJunkEncoding() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyByteArrayValidWriterJunkEncoding() throws Exception {
- IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyByteArrayNullWriterJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), "junk");
- }
-
- @Test(expected = UnsupportedEncodingException.class)
- public void copyByteArrayValidWriterJunkEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, "junk");
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterValidEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "utf-16");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullWriterValidEncoding() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16");
- }
-
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterValidEncoding() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16");
+ @Test
+ void copyNullByteArrayNullWriterNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), null));
}
@Test
- public void copyEmptyByteArrayValidWriterValidEncoding() throws Exception {
+ void copyNullByteArrayValidWriterNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullWriterNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), null));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriterNullEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), null));
+ }
+
+ @Test
+ void copyByteArrayNullEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, null);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void copyNullByteArrayNullWriterJunkEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "junk"));
+ }
+
+ @Test
+ void copyNullByteArrayValidWriterJunkEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk"));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), "junk"));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriterJunkEncoding() throws Exception {
+ assertThrows(
+ UnsupportedEncodingException.class,
+ () -> IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), "junk"));
+ }
+
+ @Test
+ void copyByteArrayNullWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), "junk");
+ });
+ }
+
+ @Test
+ void copyByteArrayValidWriterJunkEncoding() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, "junk");
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
+ }
+
+ @Test
+ void copyNullByteArrayNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyEmptyByteArrayNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyNullByteArrayValidWriterValidEncoding() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16"));
+ }
+
+ @Test
+ void copyEmptyByteArrayValidWriterValidEncoding() throws Exception {
StringWriter writer = new DontCloseStringWriter();
IOUtil.copy(emptyByteArray(), writer, "utf-16");
- assertThat(writer.toString(), is(emptyString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void copyByteArrayNullWriterValidEncoding() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), "utf-16");
+ assertThat(writer.toString()).isEqualTo(emptyString());
}
@Test
- public void copyByteArrayValidWriterValidEncoding() throws Exception {
+ void copyByteArrayNullWriterValidEncoding() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(UTF_16), nullWriter(), "utf-16");
+ });
+ }
+
+ @Test
+ void copyByteArrayValidWriterValidEncoding() throws Exception {
String probe = "A string \u2345\u00ef";
StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16");
- assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ IOUtil.copy(probe.getBytes(UTF_16), writer, "utf-16");
+ assertThat(writer.toString().getBytes(UTF_8)).isEqualTo(probe.getBytes(UTF_8));
}
/*
* copy(byte[],Writer,String,int)
*/
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), null, -1);
+ @Test
+ void copyNullByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, -1);
+ @Test
+ void copyNullByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), null, -1);
+ @Test
+ void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), null, -1));
}
- @Test(expected = NullPointerException.class)
- public void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyByteArray(), writer, null, -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyByteArray(), writer, null, -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), null, -1);
+ @Test
+ void copyByteArrayNullWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), null, -1);
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, null, -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ void copyByteArrayValidWriterNullEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, null, -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "junk", -1);
+ @Test
+ void copyNullByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "junk", -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", -1);
+ @Test
+ void copyNullByteArrayValidWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), "junk", -1);
+ @Test
+ void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), "junk", -1));
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyEmptyByteArrayJunkEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyByteArray(), writer, "junk", -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyByteArrayJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyByteArray(), writer, "junk", -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), "junk", -1);
+ @Test
+ void copyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), "junk", -1);
+ });
}
- @Test(expected = UnsupportedEncodingException.class)
- public void copyByteArrayValidWriterJunkEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, "junk", -1);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ void copyByteArrayValidWriterJunkEncodingNegBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, "junk", -1);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", -1);
+ @Test
+ void copyNullByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", -1));
}
- @Test(expected = NullPointerException.class)
- public void copyNullByteArrayValidWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", -1);
+ @Test
+ void copyNullByteArrayValidWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16", -1);
+ @Test
+ void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16", -1));
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyByteArray(), writer, "utf-16", -1);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyByteArray(), writer, "utf-16", -1);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), -1);
+ @Test
+ void copyByteArrayNullWriterValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(UTF_16), nullWriter(), -1);
+ });
}
- @Test(expected = NegativeArraySizeException.class)
- public void copyByteArrayValidEncodingNegBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16", -1);
- assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8")));
+ @Test
+ void copyByteArrayValidEncodingNegBufSz() throws Exception {
+ assertThrows(NegativeArraySizeException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(UTF_16), writer, "utf-16", -1);
+ assertThat(writer.toString().getBytes(UTF_8)).isEqualTo(probe.getBytes(UTF_8));
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), null, 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyByteArray(), writer, null, 0);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyByteArray(), writer, null, 0);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), null, 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), null, 0);
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, null, 0);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, null, 0);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "junk", 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class, () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
- IOUtil.copy(emptyByteArray(), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> IOUtil.copy(emptyByteArray(), nullWriter(), "junk", 0));
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyEmptyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(emptyByteArray(), writer, "junk", 0);
- assertThat(writer.toString(), is(emptyString()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyEmptyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(emptyByteArray(), writer, "junk", 0);
+ assertThat(writer.toString()).isEqualTo(emptyString());
+ });
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- IOUtil.copy(probe.getBytes(), nullWriter(), "junk", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ IOUtil.copy(probe.getBytes(), nullWriter(), "junk", 0);
+ });
}
- @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
- String probe = "A string \u2345\u00ef";
- StringWriter writer = new DontCloseStringWriter();
- IOUtil.copy(probe.getBytes(), writer, "junk", 0);
- assertThat(writer.toString().getBytes(), is(probe.getBytes()));
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception {
+ assertThrows(UnsupportedEncodingException.class, () -> {
+ String probe = "A string \u2345\u00ef";
+ StringWriter writer = new DontCloseStringWriter();
+ IOUtil.copy(probe.getBytes(), writer, "junk", 0);
+ assertThat(writer.toString().getBytes()).isEqualTo(probe.getBytes());
+ });
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayNullWriterValidEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayNullWriterValidEncodingZeroBufSz() throws Exception {
+ assertThrows(NullPointerException.class, () -> IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", 0));
}
- @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT)
- public void copyNullByteArrayValidWriterValidEncodingZeroBufSz() throws Exception {
- IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", 0);
+ @Test
+ @Timeout(INFINITE_LOOP_TIMEOUT)
+ void copyNullByteArrayValidWriterValidEncodingZeroBufSz() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", 0));
}
/*
diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
index 5715787..112c473 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java
@@ -18,17 +18,17 @@
*/
package org.apache.maven.shared.utils.io;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Kristian Rosenvold
*/
@SuppressWarnings("deprecation")
-public class MatchPatternTest {
+class MatchPatternTest {
@Test
- public void matchPath() {
+ void matchPath() {
MatchPattern mp = MatchPattern.fromString("ABC*");
assertTrue(mp.matchPath("ABCD", true));
}
diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
index 8919d06..97e8c1a 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java
@@ -18,17 +18,17 @@
*/
package org.apache.maven.shared.utils.io;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Kristian Rosenvold
*/
@SuppressWarnings("deprecation")
-public class MatchPatternsTest {
+class MatchPatternsTest {
@Test
- public void matches() {
+ void matches() {
MatchPatterns from = MatchPatterns.from("ABC**", "CDE**");
assertTrue(from.matches("ABCDE", true));
assertTrue(from.matches("CDEF", true));
diff --git a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
index 3b24636..14aa9d6 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java
@@ -20,38 +20,35 @@
import java.io.File;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Test the {@link SelectorUtils} class.
*/
@SuppressWarnings("deprecation")
-public class SelectorUtilsTest {
+class SelectorUtilsTest {
- @Test(expected = NullPointerException.class)
- public void testMatchPatternStart() {
- SelectorUtils.matchPatternStart(null, null);
+ @Test
+ void matchPatternStart() {
+ assertThrows(NullPointerException.class, () -> SelectorUtils.matchPatternStart(null, null));
}
@Test
- public void testEmptyStrings() {
+ void emptyStrings() {
assertTrue(SelectorUtils.matchPatternStart("", ""));
}
@Test
- public void testRegexPrefix() throws Exception {
- assertEquals(
- true,
- SelectorUtils.matchPatternStart(
- SelectorUtils.REGEX_HANDLER_PREFIX + File.separator + "aaa"
- + SelectorUtils.PATTERN_HANDLER_SUFFIX,
- ""));
+ void regexPrefix() throws Exception {
+ assertTrue(SelectorUtils.matchPatternStart(
+ SelectorUtils.REGEX_HANDLER_PREFIX + File.separator + "aaa" + SelectorUtils.PATTERN_HANDLER_SUFFIX,
+ ""));
}
@Test
- public void testAntPatternStrings() {
+ void antPatternStrings() {
assertAntDoesNotMatch("/aaa", "");
assertAntDoesNotMatch("\\aaa", "");
assertAntMatch("aaa", "");
@@ -64,11 +61,11 @@
}
private void assertAntDoesNotMatch(String pattern, String target) {
- assertEquals(false, SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
+ assertFalse(SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
}
private void assertAntMatch(String pattern, String target) {
- assertEquals(true, SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
+ assertTrue(SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
}
private String wrapWithAntHandler(String val) {
diff --git a/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java
index f48de3f..994e32c 100644
--- a/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java
@@ -18,81 +18,80 @@
*/
package org.apache.maven.shared.utils.logging;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
-public class AnsiMessageBuilderTest {
+class AnsiMessageBuilderTest {
private AnsiMessageBuilder ansiMessageBuilder;
- @Before
- public void initializeAnsiMessageBuffer() {
+ @BeforeEach
+ void initializeAnsiMessageBuffer() {
this.ansiMessageBuilder = new AnsiMessageBuilder();
}
@Test
- public void should_color_debug() {
+ void should_color_debug() {
ansiMessageBuilder.debug("DEBUG");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;36mDEBUG\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;36mDEBUG\u001B[m");
}
@Test
- public void should_color_info() {
+ void should_color_info() {
ansiMessageBuilder.info("INFO");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;34mINFO\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;34mINFO\u001B[m");
}
@Test
- public void should_color_warning_and_reset() {
+ void should_color_warning_and_reset() {
ansiMessageBuilder.warning("WARNING");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;33mWARNING\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;33mWARNING\u001B[m");
}
@Test
- public void should_color_error() {
+ void should_color_error() {
ansiMessageBuilder.error("ERROR");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31mERROR\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;31mERROR\u001B[m");
}
@Test
- public void should_color_success_with_message() {
+ void should_color_success_with_message() {
ansiMessageBuilder.success("a success message");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;32ma success message\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;32ma success message\u001B[m");
}
@Test
- public void should_color_failure_and_reset() {
+ void should_color_failure_and_reset() {
ansiMessageBuilder.failure("a failure message");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31ma failure message\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1;31ma failure message\u001B[m");
}
@Test
- public void should_color_strong_and_reset() {
+ void should_color_strong_and_reset() {
ansiMessageBuilder.strong("a strong message");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1ma strong message\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[1ma strong message\u001B[m");
}
@Test
- public void should_color_mojo_and_reset() {
+ void should_color_mojo_and_reset() {
ansiMessageBuilder.mojo("a mojo");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[32ma mojo\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[32ma mojo\u001B[m");
}
@Test
- public void should_color_project_and_reset() {
+ void should_color_project_and_reset() {
ansiMessageBuilder.project("a project");
- assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[36ma project\u001B[m"));
+ assertThat(ansiMessageBuilder.toString()).isEqualTo("\u001B[36ma project\u001B[m");
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java
index b95936f..6347ba3 100644
--- a/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java
@@ -28,23 +28,20 @@
import org.fusesource.jansi.AnsiPrintStream;
import org.fusesource.jansi.AnsiType;
import org.fusesource.jansi.io.AnsiOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeNoException;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class MessageUtilsTest {
+class MessageUtilsTest {
@Test
- public void testSystem() {
+ void system() {
PrintStream currentOut = System.out;
try {
MessageUtils.systemInstall();
- assertThat(System.out, not(sameInstance(currentOut)));
+ assertThat(System.out).isNotSameAs(currentOut);
} catch (LinkageError e) {
- assumeNoException("JAnsi not supported for this platform", e);
+ // assumeNoException("JAnsi not supported for this platform", e);
} finally {
try {
// uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
@@ -54,20 +51,14 @@
// ignore any thrown exception like NPE here
}
}
- assertThat(System.out, sameInstance(currentOut));
+ assertThat(System.out).isSameAs(currentOut);
}
@Test
- public void testTerminalWidth() {
- AnsiOutputStream.WidthSupplier width = new AnsiOutputStream.WidthSupplier() {
- @Override
- public int getTerminalWidth() {
- return 33;
- }
- };
+ void terminalWidth() {
AnsiOutputStream aos = new AnsiOutputStream(
new ByteArrayOutputStream(),
- width,
+ () -> 33,
AnsiMode.Default,
null,
AnsiType.Emulation,
@@ -81,7 +72,7 @@
AnsiConsole.out = new AnsiPrintStream(aos, true);
assertEquals(33, MessageUtils.getTerminalWidth());
} catch (LinkageError e) {
- assumeNoException("JAnsi not supported for this platform", e);
+ // assumeNoException("JAnsi not supported for this platform", e);
} finally {
try {
// uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
diff --git a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
index 4787469..68db6d9 100644
--- a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
+++ b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
@@ -26,7 +26,6 @@
import java.io.Writer;
import org.apache.commons.io.FileUtils;
-import org.junit.rules.TemporaryFolder;
/**
* A few utility methods for file based tests.
@@ -75,8 +74,8 @@
* @return the File object for a new file
* @throws IOException
*/
- public static File newFile(TemporaryFolder folder, String filename) throws IOException {
- File destination = folder.newFile(filename);
+ public static File newFile(File folder, String filename) throws IOException {
+ File destination = File.createTempFile(filename, null, folder);
if (destination.exists()) {
FileUtils.deleteQuietly(destination);
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
index 41dee5f..9b40a5f 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java
@@ -24,31 +24,33 @@
import java.io.StringWriter;
import org.apache.maven.shared.utils.StringUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test of {@link PrettyPrintXMLWriter}
*
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
*/
-public class PrettyPrintXmlWriterTest {
+class PrettyPrintXmlWriterTest {
private StringWriter w = new StringWriter();
private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(w);
@Test
- public void testNoStartTag() throws IOException {
+ void noStartTag() throws IOException {
try {
writer.startElement("");
- Assert.fail("allowed empty name");
+ fail("allowed empty name");
} catch (IllegalArgumentException ex) {
- Assert.assertEquals("Element name cannot be empty", ex.getMessage());
+ assertEquals("Element name cannot be empty", ex.getMessage());
}
}
@Test
- public void testDefaultPrettyPrintXMLWriter() throws IOException {
+ void defaultPrettyPrintXMLWriter() throws IOException {
writer.startElement(HTML.Tag.HTML.toString());
writeXhtmlHead(writer);
@@ -57,11 +59,11 @@
writer.endElement(); // Tag.HTML
- Assert.assertEquals(expectedResult(), w.toString());
+ assertEquals(expectedResult(), w.toString());
}
@Test
- public void testPrettyPrintXMLWriterWithGivenLineSeparator() throws IOException {
+ void prettyPrintXMLWriterWithGivenLineSeparator() throws IOException {
writer.setLineSeparator("\n");
writer.startElement(HTML.Tag.HTML.toString());
@@ -72,11 +74,11 @@
writer.endElement(); // Tag.HTML
- Assert.assertEquals(expectedResult(), w.toString());
+ assertEquals(expectedResult(), w.toString());
}
@Test
- public void testPrettyPrintXMLWriterWithGivenLineIndenter() throws IOException {
+ void prettyPrintXMLWriterWithGivenLineIndenter() throws IOException {
writer.setLineIndenter(" ");
writer.startElement(HTML.Tag.HTML.toString());
@@ -87,43 +89,43 @@
writer.endElement(); // Tag.HTML
- Assert.assertEquals(expectedResult(" "), w.toString());
+ assertEquals(expectedResult(" "), w.toString());
}
@Test
- public void testEscapeXmlAttributeWindows() throws IOException {
+ void escapeXmlAttributeWindows() throws IOException {
// Windows
writer.startElement(HTML.Tag.DIV.toString());
writer.addAttribute("class", "sect\r\nion");
writer.endElement(); // Tag.DIV
- Assert.assertEquals("<div class=\"sect ion\"/>", w.toString());
+ assertEquals("<div class=\"sect ion\"/>", w.toString());
}
@Test
- public void testEscapeXmlAttributeMac() throws IOException {
+ void escapeXmlAttributeMac() throws IOException {
// Mac
writer.startElement(HTML.Tag.DIV.toString());
writer.addAttribute("class", "sect\rion");
writer.endElement(); // Tag.DIV
- Assert.assertEquals("<div class=\"sect ion\"/>", w.toString());
+ assertEquals("<div class=\"sect ion\"/>", w.toString());
}
@Test
- public void testEscapeXmlAttributeTrailingCR() throws IOException {
+ void escapeXmlAttributeTrailingCR() throws IOException {
// Mac
writer.startElement(HTML.Tag.DIV.toString());
writer.addAttribute("class", "section\r");
writer.endElement(); // Tag.DIV
- Assert.assertEquals("<div class=\"section \"/>", w.toString());
+ assertEquals("<div class=\"section \"/>", w.toString());
}
@Test
- public void testEscapeXmlAttributeUnix() throws IOException {
+ void escapeXmlAttributeUnix() throws IOException {
// Unix
writer.startElement(HTML.Tag.DIV.toString());
writer.addAttribute("class", "sect\nion");
writer.endElement(); // Tag.DIV
- Assert.assertEquals("<div class=\"sect ion\"/>", w.toString());
+ assertEquals("<div class=\"sect ion\"/>", w.toString());
}
private void writeXhtmlHead(XMLWriter writer) throws IOException {
@@ -161,36 +163,30 @@
}
private static String expectedResult(String lineIndenter) {
-
String lineSeparator = "\n";
- StringBuilder expected = new StringBuilder();
-
- expected.append("<html>").append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 1)).append("<head>").append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2))
- .append("<title>title</title>")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2))
- .append("<meta name=\"author\" content=\"Author\"/>")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2))
- .append("<meta name=\"date\" content=\"Date\"/>")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 1)).append("</head>").append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 1)).append("<body>").append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2))
- .append("<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2))
- .append("<div class=\"section\">")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 3))
- .append("<h2>Section title</h2>")
- .append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 2)).append("</div>").append(lineSeparator);
- expected.append(StringUtils.repeat(lineIndenter, 1)).append("</body>").append(lineSeparator);
- expected.append("</html>");
-
- return expected.toString();
+ return "<html>" + lineSeparator + StringUtils.repeat(lineIndenter, 1)
+ + "<head>" + lineSeparator + StringUtils.repeat(lineIndenter, 2)
+ + "<title>title</title>"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 2)
+ + "<meta name=\"author\" content=\"Author\"/>"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 2)
+ + "<meta name=\"date\" content=\"Date\"/>"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 1)
+ + "</head>" + lineSeparator + StringUtils.repeat(lineIndenter, 1)
+ + "<body>" + lineSeparator + StringUtils.repeat(lineIndenter, 2)
+ + "<p>Paragraph 1, line 1. Paragraph 1, line 2.</p>"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 2)
+ + "<div class=\"section\">"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 3)
+ + "<h2>Section title</h2>"
+ + lineSeparator
+ + StringUtils.repeat(lineIndenter, 2)
+ + "</div>" + lineSeparator + StringUtils.repeat(lineIndenter, 1)
+ + "</body>" + lineSeparator + "</html>";
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
index 5566ef9..d72f533 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java
@@ -23,15 +23,19 @@
import java.io.OutputStream;
import java.io.Writer;
-import junit.framework.TestCase;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.WriterFactory;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
*
*/
-public class XmlWriterUtilTest extends TestCase {
+class XmlWriterUtilTest {
private OutputStream output;
private Writer writer;
@@ -39,8 +43,8 @@
private XMLWriter xmlWriter;
/** {@inheritDoc} */
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ void setUp() throws Exception {
output = new ByteArrayOutputStream();
writer = WriterFactory.newXmlWriter(output);
@@ -52,7 +56,8 @@
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriter() throws Exception {
+ @Test
+ void writeLineBreakXMLWriter() throws Exception {
XmlWriterUtil.writeLineBreak(xmlWriter);
writer.close();
assertEquals(1, StringUtils.countMatches(output.toString(), "\r\n"));
@@ -63,7 +68,8 @@
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterInt() throws Exception {
+ @Test
+ void writeLineBreakXMLWriterInt() throws Exception {
XmlWriterUtil.writeLineBreak(xmlWriter, 10);
writer.close();
assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
@@ -74,7 +80,8 @@
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterIntInt() throws Exception {
+ @Test
+ void writeLineBreakXMLWriterIntInt() throws Exception {
XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2);
writer.close();
assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
@@ -89,7 +96,8 @@
*
* @throws Exception if any
*/
- public void testWriteLineBreakXMLWriterIntIntInt() throws Exception {
+ @Test
+ void writeLineBreakXMLWriterIntIntInt() throws Exception {
XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4);
writer.close();
assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n"));
@@ -101,13 +109,12 @@
*
* @throws Exception if any
*/
- public void testWriteCommentLineBreakXMLWriter() throws Exception {
+ @Test
+ void writeCommentLineBreakXMLWriter() throws Exception {
XmlWriterUtil.writeCommentLineBreak(xmlWriter);
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("<!-- ====================================================================== -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- ====================================================================== -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length());
}
@@ -116,16 +123,18 @@
*
* @throws Exception if any
*/
- public void testWriteCommentLineBreakXMLWriterInt() throws Exception {
+ @Test
+ void writeCommentLineBreakXMLWriterInt() throws Exception {
XmlWriterUtil.writeCommentLineBreak(xmlWriter, 20);
writer.close();
assertEquals(output.toString(), "<!-- ========== -->" + "\r\n");
}
- public void testWriteCommentLineBreak() throws IOException {
+ @Test
+ void writeCommentLineBreak() throws IOException {
XmlWriterUtil.writeCommentLineBreak(xmlWriter, 10);
writer.close();
- assertEquals(output.toString(), output.toString(), "<!-- -->" + "\r\n");
+ assertEquals(output.toString(), "<!-- -->" + "\r\n", output.toString());
}
/**
@@ -133,36 +142,33 @@
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterString() throws Exception {
+ @Test
+ void writeCommentXMLWriterString() throws Exception {
XmlWriterUtil.writeComment(xmlWriter, "hello");
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append("<!-- hello -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- hello -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length());
}
- public void testWriteComment() throws IOException {
+ @Test
+ void writeComment() throws IOException {
XmlWriterUtil.writeComment(
xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append("<!-- hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertTrue(output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE);
}
- public void testWriteComment_2() throws IOException {
+ @Test
+ void writeComment_2() throws IOException {
XmlWriterUtil.writeComment(xmlWriter, "hello\nworld");
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append("<!-- hello -->")
- .append("\r\n");
- sb.append("<!-- world -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- hello -->" + "\r\n"
+ + "<!-- world -->"
+ + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()));
}
@@ -171,33 +177,30 @@
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringInt() throws Exception {
+ @Test
+ void writeCommentXMLWriterStringInt() throws Exception {
String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
XmlWriterUtil.writeComment(xmlWriter, "hello", 2);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(indent);
- sb.append("<!-- hello -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = indent + "<!-- hello -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(
output.toString().length(),
XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
}
- public void testWriteComment_3() throws IOException {
+ @Test
+ void writeComment_3() throws IOException {
String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE);
XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(indent);
- sb.append("<!-- hello -->")
- .append("\r\n");
- sb.append(indent);
- sb.append("<!-- world -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = indent + "<!-- hello -->"
+ + "\r\n"
+ + indent
+ + "<!-- world -->"
+ + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(
output.toString().length(),
2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * indent.length());
@@ -208,33 +211,31 @@
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringIntInt() throws Exception {
+ @Test
+ void writeCommentXMLWriterStringIntInt() throws Exception {
String repeat = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(repeat);
- sb.append("<!-- hello -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = repeat + "<!-- hello -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * 4);
}
- public void testWriteCommentXMLWriterStringIntInt_2() throws IOException {
+ @Test
+ void writeCommentXMLWriterStringIntInt_2() throws IOException {
String repeat = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(repeat);
- sb.append("<!-- hello -->")
- .append("\r\n");
- sb.append(repeat);
- sb.append("<!-- world -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
- assertTrue(output.toString().length()
- == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * repeat.length());
+ String sb = repeat + "<!-- hello -->"
+ + "\r\n"
+ + repeat
+ + "<!-- world -->"
+ + "\r\n";
+ assertEquals(output.toString(), sb);
+ assertEquals(
+ output.toString().length(),
+ 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * repeat.length());
}
/**
@@ -242,26 +243,24 @@
*
* @throws Exception if any
*/
- public void testWriteCommentXMLWriterStringIntIntInt() throws Exception {
+ @Test
+ void writeCommentXMLWriterStringIntIntInt() throws Exception {
String indent = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(indent);
- sb.append("<!-- hello -->").append("\r\n");
- assertEquals(output.toString(), sb.toString());
- assertTrue(output.toString().length() == 50 - 1 + "\r\n".length() + 2 * 4);
+ String sb = indent + "<!-- hello -->" + "\r\n";
+ assertEquals(output.toString(), sb);
+ assertEquals(output.toString().length(), 50 - 1 + "\r\n".length() + 2 * 4);
}
- public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException {
+ @Test
+ void writeCommentXMLWriterStringIntIntInt_2() throws IOException {
String indent = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 10);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append(indent);
- sb.append("<!-- hello -->").append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = indent + "<!-- hello -->" + "\r\n";
+ assertEquals(output.toString(), sb);
assertTrue(output.toString().length() >= 10 + 2 * 4);
}
@@ -270,23 +269,23 @@
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringInt() throws Exception {
+ @Test
+ void writeCommentTextXMLWriterStringInt() throws Exception {
XmlWriterUtil.writeCommentText(xmlWriter, "hello", 0);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append("\r\n");
- sb.append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append("<!-- hello -->")
- .append("\r\n");
- sb.append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "\r\n" + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + "<!-- hello -->"
+ + "\r\n"
+ + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + "\r\n";
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 2 * "\r\n".length());
}
- public void testWriteCommentTextXMLWriterStringInt_2() throws IOException {
+ @Test
+ void writeCommentTextXMLWriterStringInt_2() throws IOException {
String indent = StringUtils.repeat(" ", 2 * 2);
XmlWriterUtil.writeCommentText(
@@ -295,29 +294,27 @@
+ "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line",
2);
writer.close();
- StringBuffer sb = new StringBuffer();
- sb.append("\r\n");
- sb.append(indent)
- .append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- hello world with end of line -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- and -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- line -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append("\r\n");
- sb.append(indent);
- assertEquals(output.toString(), sb.toString());
+ String sb = "\r\n" + indent
+ + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + indent
+ + "<!-- hello world with end of line -->"
+ + "\r\n"
+ + indent
+ + "<!-- and -->"
+ + "\r\n"
+ + indent
+ + "<!-- loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong -->"
+ + "\r\n"
+ + indent
+ + "<!-- line -->"
+ + "\r\n"
+ + indent
+ + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + "\r\n"
+ + indent;
+ assertEquals(output.toString(), sb);
}
/**
@@ -325,25 +322,24 @@
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringIntInt() throws Exception {
+ @Test
+ void writeCommentTextXMLWriterStringIntInt() throws Exception {
String indent = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4);
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("\r\n");
- sb.append(indent)
- .append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- hello -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- ====================================================================== -->")
- .append("\r\n");
- sb.append("\r\n");
- sb.append(indent);
- assertEquals(output.toString(), sb.toString());
+ String sb = "\r\n" + indent
+ + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + indent
+ + "<!-- hello -->"
+ + "\r\n"
+ + indent
+ + "<!-- ====================================================================== -->"
+ + "\r\n"
+ + "\r\n"
+ + indent;
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length());
}
@@ -352,25 +348,24 @@
*
* @throws Exception if any
*/
- public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception {
+ @Test
+ void writeCommentTextXMLWriterStringIntIntInt() throws Exception {
String indent = StringUtils.repeat(" ", 2 * 4);
XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50);
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("\r\n");
- sb.append(indent)
- .append("<!-- ======================================== -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- hello -->")
- .append("\r\n");
- sb.append(indent)
- .append("<!-- ======================================== -->")
- .append("\r\n");
- sb.append("\r\n");
- sb.append(indent);
- assertEquals(output.toString(), sb.toString());
+ String sb = "\r\n" + indent
+ + "<!-- ======================================== -->"
+ + "\r\n"
+ + indent
+ + "<!-- hello -->"
+ + "\r\n"
+ + indent
+ + "<!-- ======================================== -->"
+ + "\r\n"
+ + "\r\n"
+ + indent;
+ assertEquals(output.toString(), sb);
assertEquals(output.toString().length(), 3 * (50 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length());
}
@@ -379,13 +374,12 @@
*
* @throws Exception if any
*/
- public void testWriteCommentNull() throws Exception {
+ @Test
+ void writeCommentNull() throws Exception {
XmlWriterUtil.writeComment(xmlWriter, null);
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("<!-- null -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- null -->" + "\r\n";
+ assertEquals(output.toString(), sb);
}
/**
@@ -393,13 +387,12 @@
*
* @throws Exception if any
*/
- public void testWriteCommentShort() throws Exception {
+ @Test
+ void writeCommentShort() throws Exception {
XmlWriterUtil.writeComment(xmlWriter, "This is a short text");
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("<!-- This is a short text -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- This is a short text -->" + "\r\n";
+ assertEquals(output.toString(), sb);
}
/**
@@ -407,22 +400,21 @@
*
* @throws Exception if any
*/
- public void testWriteCommentLong() throws Exception {
+ @Test
+ void writeCommentLong() throws Exception {
XmlWriterUtil.writeComment(
xmlWriter,
"Maven is a software project management and comprehension tool. "
+ "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting "
+ "and documentation from a central piece of information.");
writer.close();
- StringBuilder sb = new StringBuilder();
- sb.append("<!-- Maven is a software project management and comprehension tool. Based -->")
- .append("\r\n");
- sb.append("<!-- on the concept of a project object model (POM), Maven can manage a -->")
- .append("\r\n");
- sb.append("<!-- project's build, reporting and documentation from a central piece of -->")
- .append("\r\n");
- sb.append("<!-- information. -->")
- .append("\r\n");
- assertEquals(output.toString(), sb.toString());
+ String sb = "<!-- Maven is a software project management and comprehension tool. Based -->" + "\r\n"
+ + "<!-- on the concept of a project object model (POM), Maven can manage a -->"
+ + "\r\n"
+ + "<!-- project's build, reporting and documentation from a central piece of -->"
+ + "\r\n"
+ + "<!-- information. -->"
+ + "\r\n";
+ assertEquals(output.toString(), sb);
}
}
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
index f532432..753441c 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
@@ -27,22 +27,20 @@
import java.nio.charset.StandardCharsets;
import org.apache.maven.shared.utils.xml.pull.XmlPullParserException;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Kristian Rosenvold
*/
-public class Xpp3DomBuilderTest {
+class Xpp3DomBuilderTest {
private static final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
@Test
- public void selfClosingTag() throws Exception {
+ void selfClosingTag() throws Exception {
String domString = selfClosingTagSource();
@@ -50,24 +48,20 @@
String expected = expectedSelfClosingTag();
String dom1Str = dom.toString();
- assertEquals("check DOMs match", expected, dom1Str);
+ assertEquals(expected, dom1Str, "check DOMs match");
}
@Test
- public void testUnrecognizedEncoding() {
+ void unrecognizedEncoding() {
+ InputStream in = new ByteArrayInputStream("<foo/>".getBytes(StandardCharsets.UTF_8));
- byte[] data = "<foo/>".getBytes(StandardCharsets.UTF_8);
- InputStream in = new ByteArrayInputStream(data);
- try {
- Xpp3DomBuilder.build(in, "nosuch encoding");
- fail();
- } catch (XmlPullParserException expected) {
- assertTrue(expected.getCause() instanceof UnsupportedEncodingException);
- }
+ XmlPullParserException e =
+ assertThrows(XmlPullParserException.class, () -> Xpp3DomBuilder.build(in, "nosuch encoding"));
+ assertInstanceOf(UnsupportedEncodingException.class, e.getCause());
}
@Test
- public void trimming() throws Exception {
+ void trimming() throws Exception {
String domString = createDomString();
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);
@@ -79,17 +73,17 @@
}
@Test
- public void testMalformedXml() {
+ void malformedXml() {
try {
Xpp3DomBuilder.build(new StringReader("<newRoot>" + createDomString()));
fail("We're supposed to fail");
} catch (XmlPullParserException ex) {
- Assert.assertNotNull(ex.getMessage());
+ Assertions.assertNotNull(ex.getMessage());
}
}
@Test
- public void attributeEscaping() throws IOException, XmlPullParserException {
+ void attributeEscaping() throws IOException, XmlPullParserException {
String s = getAttributeEncodedString();
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));
@@ -101,7 +95,7 @@
}
@Test
- public void contentEscaping() throws IOException, XmlPullParserException {
+ void contentEscaping() throws IOException, XmlPullParserException {
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));
assertEquals("\"msg\"", dom.getChild("a1").getValue());
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
index fb8315d..21d8f26 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
@@ -23,15 +23,15 @@
import org.apache.maven.shared.utils.xml.Xpp3Dom;
import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.apache.maven.shared.utils.xml.Xpp3Dom.mergeXpp3Dom;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Kristian Rosenvold
*/
-public class Xpp3DomTest {
+class Xpp3DomTest {
private Xpp3Dom createElement(String element, String value) {
Xpp3Dom t1s1 = new Xpp3Dom(element);
@@ -40,7 +40,7 @@
}
@Test
- public void mergePrecedenceSelfClosed() throws XmlPullParserException, IOException {
+ void mergePrecedenceSelfClosed() throws XmlPullParserException, IOException {
Xpp3Dom parentConfig = build("<configuration><items><item/></items></configuration>");
Xpp3Dom childConfig = build("<configuration><items><item>ooopise</item></items></configuration>");
@@ -53,7 +53,7 @@
}
@Test
- public void mergePrecedenceOpenClose() throws XmlPullParserException, IOException {
+ void mergePrecedenceOpenClose() throws XmlPullParserException, IOException {
Xpp3Dom parentConfig = build("<configuration><items><item></item></items></configuration>");
Xpp3Dom childConfig = build("<configuration><items><item>ooopise</item></items></configuration>");
@@ -66,7 +66,7 @@
}
@Test
- public void selfOverrideOnRootNode() {
+ void selfOverrideOnRootNode() {
// Todo: This does not work when loaded. Probably a bug related to null vs "" handling
// Xpp3Dom t1 = build( "<top combine.self='override' attr='value'></top>" );
@@ -83,7 +83,7 @@
}
@Test
- public void mergeValuesOnRootNode() {
+ void mergeValuesOnRootNode() {
Xpp3Dom t1 = build("<root attr='value'/>");
Xpp3Dom t2 = build("<root attr2='value2'>t2Val</root>");
Xpp3Dom result = mergeXpp3Dom(t1, t2);
@@ -92,7 +92,7 @@
}
@Test
- public void mergeAttributesOnRootNode() {
+ void mergeAttributesOnRootNode() {
Xpp3Dom t1 = build("<root combine.self='merge' attr='value'/>");
Xpp3Dom t2 = build("<root attr2='value2'/>");
@@ -101,7 +101,7 @@
}
@Test
- public void combineAppend() {
+ void combineAppend() {
Xpp3Dom t1 = new Xpp3Dom("root");
t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND);
t1.addChild(createElement("sub", "s1Value"));
@@ -115,7 +115,7 @@
}
@Test
- public void mergeOverride() {
+ void mergeOverride() {
Xpp3Dom t1 = new Xpp3Dom("root");
t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND);
t1.addChild(createElement("sub", "s1Value"));
@@ -128,20 +128,24 @@
assertEquals(1, result.getChildren("sub").length);
}
- @Test(expected = NullPointerException.class)
- public void nullValue() {
- //noinspection ConstantConditions
- new Xpp3Dom("top").setAttribute(null, "value");
- }
-
- @Test(expected = NullPointerException.class)
- public void nullAttribute() {
- //noinspection ConstantConditions
- new Xpp3Dom("root").setAttribute("attr", null);
+ @Test
+ void nullValue() {
+ assertThrows(NullPointerException.class, () -> {
+ //noinspection ConstantConditions
+ new Xpp3Dom("top").setAttribute(null, "value");
+ });
}
@Test
- public void testEquals() {
+ void nullAttribute() {
+ assertThrows(NullPointerException.class, () -> {
+ //noinspection ConstantConditions
+ new Xpp3Dom("root").setAttribute("attr", null);
+ });
+ }
+
+ @Test
+ void equals() {
Xpp3Dom dom = new Xpp3Dom("single");
dom.addChild(new Xpp3Dom("kid"));
@@ -150,13 +154,13 @@
assertEquals(dom, dom);
//noinspection ObjectEqualsNull
- assertFalse(dom.equals(null));
- assertFalse(dom.equals(new Xpp3Dom((String) null)));
- assertFalse(dom.equals(other));
+ assertNotEquals(null, dom);
+ assertNotEquals(dom, new Xpp3Dom((String) null));
+ assertNotEquals(dom, other);
}
@Test
- public void dominantWinsCollections() throws XmlPullParserException {
+ void dominantWinsCollections() throws XmlPullParserException {
Xpp3Dom parent = build("<root><entries><entry>uno</entry><entry>dos</entry></entries></root>");
Xpp3Dom dominant = build("<root><entries><entry>tres</entry></entries></root>");
@@ -169,7 +173,7 @@
}
@Test
- public void combineChildrenAppendTest() throws XmlPullParserException {
+ void combineChildrenAppendTest() throws XmlPullParserException {
Xpp3Dom parent =
build("<root><entries><entry>uno</entry><entry>dos</entry><entry>tres</entry></entries></root>");
Xpp3Dom child = build("<root><entries combine.children=\"append\"><entry>quatro</entry></entries></root>");
@@ -188,7 +192,7 @@
}
@Test
- public void unchangedWithFirstOrLastEmpty() throws Exception {
+ void unchangedWithFirstOrLastEmpty() throws Exception {
String configStr = "<root><entries><entry/><entry>test</entry><entry/></entries></root>";
Xpp3Dom dominant = build(configStr);
Xpp3Dom duplicatedDominant = build(configStr);
@@ -215,7 +219,7 @@
}
@Test
- public void recessiveChildrenIncludedWhenDominantEmpty() throws Exception {
+ void recessiveChildrenIncludedWhenDominantEmpty() throws Exception {
String dominant = "<root><baz>bazzy</baz></root>";
String recessive = "<root><bar>barry</bar></root>";
@@ -231,7 +235,7 @@
}
@Test
- public void duplicatedChildren() throws IOException, XmlPullParserException {
+ void duplicatedChildren() throws IOException, XmlPullParserException {
String dupes = "<root><baz>x</baz><baz>y</baz></root>";
assertEquals("y", build(dupes).getChild("baz").getValue());
}