use `assertThrows` instead of `ExpectedException` rule
diff --git a/test/java/org/apache/ivy/MainTest.java b/test/java/org/apache/ivy/MainTest.java
index 994afb2..ba207a5 100644
--- a/test/java/org/apache/ivy/MainTest.java
+++ b/test/java/org/apache/ivy/MainTest.java
@@ -17,17 +17,6 @@
*/
package org.apache.ivy;
-import org.apache.ivy.core.retrieve.RetrieveOptions;
-import org.apache.ivy.util.CacheCleaner;
-import org.apache.ivy.util.cli.CommandLine;
-import org.apache.ivy.util.cli.ParseException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
@@ -37,9 +26,21 @@
import java.util.HashSet;
import java.util.Set;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
+import org.apache.ivy.util.CacheCleaner;
+import org.apache.ivy.util.cli.CommandLine;
+import org.apache.ivy.util.cli.ParseException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class MainTest {
@@ -47,9 +48,6 @@
private File cache;
@Rule
- public ExpectedException expExc = ExpectedException.none();
-
- @Rule
public TemporaryFolder tempDir = new TemporaryFolder();
@Before
@@ -65,51 +63,47 @@
@Test
public void testHelp() throws Exception {
- run(new String[] {"-?"});
+ run("-?");
}
@Test
- public void testBadOption() throws Exception {
- expExc.expect(ParseException.class);
- expExc.expectMessage("Unrecognized option: -bad");
-
- run(new String[] {"-bad"});
+ public void testBadOption() {
+ Exception exception = assertThrows(ParseException.class, () -> run("-bad"));
+ assertEquals("Unrecognized option: -bad", exception.getMessage());
}
@Test
- public void testMissingParameter() throws Exception {
- expExc.expect(ParseException.class);
- expExc.expectMessage("no argument for: ivy");
-
- run(new String[] {"-ivy"});
+ public void testMissingParameter() {
+ Exception exception = assertThrows(ParseException.class, () -> run("-ivy"));
+ assertEquals("no argument for: ivy", exception.getMessage());
}
@Test
public void testResolveSimple() throws Exception {
- run(new String[] {"-settings", "test/repositories/ivysettings.xml", "-ivy",
- "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"});
+ run("-settings", "test/repositories/ivysettings.xml", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml");
assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
}
@Test
public void testResolveSimpleWithConfs() throws Exception {
- run(new String[] {"-settings", "test/repositories/ivysettings.xml", "-ivy",
- "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "-confs", "default"});
+ run("-settings", "test/repositories/ivysettings.xml", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "-confs", "default");
assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
}
@Test
public void testResolveSimpleWithConfs2() throws Exception {
- run(new String[] {"-settings", "test/repositories/ivysettings.xml", "-confs", "default",
- "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"});
+ run("-settings", "test/repositories/ivysettings.xml", "-confs", "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml");
assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
}
@Test
public void testExtraParams1() throws Exception {
- String[] params = new String[] {"-settings", "test/repositories/ivysettings.xml", "-confs",
- "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "foo1",
- "foo2"};
+ String[] params = {
+ "-settings", "test/repositories/ivysettings.xml",
+ "-confs", "default",
+ "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml",
+ "foo1", "foo2"
+ };
CommandLine line = Main.getParser().parse(params);
String[] leftOver = line.getLeftOverArgs();
assertNotNull(leftOver);
@@ -120,9 +114,12 @@
@Test
public void testExtraParams2() throws Exception {
- String[] params = new String[] {"-settings", "test/repositories/ivysettings.xml", "-confs",
- "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml", "--",
- "foo1", "foo2"};
+ String[] params = {
+ "-settings", "test/repositories/ivysettings.xml",
+ "-confs", "default",
+ "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml",
+ "--", "foo1", "foo2"
+ };
CommandLine line = Main.getParser().parse(params);
String[] leftOver = line.getLeftOverArgs();
assertNotNull(leftOver);
@@ -133,8 +130,11 @@
@Test
public void testExtraParams3() throws Exception {
- String[] params = new String[] {"-settings", "test/repositories/ivysettings.xml", "-confs",
- "default", "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"};
+ String[] params = {
+ "-settings", "test/repositories/ivysettings.xml",
+ "-confs", "default",
+ "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"
+ };
CommandLine line = Main.getParser().parse(params);
String[] leftOver = line.getLeftOverArgs();
assertNotNull(leftOver);
@@ -146,7 +146,6 @@
* {@code types} argument to the command line must be parsed correctly when it's passed
* more than one value for the argument.
*
- * @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1355">IVY-1355</a>
*/
@Test
@@ -165,8 +164,6 @@
/**
* Tests that the {@code overwriteMode} passed for the retrieve command works as expected
- *
- * @throws Exception if something goes wrong
*/
@Test
public void testRetrieveOverwriteMode() throws Exception {
@@ -190,8 +187,6 @@
/**
* Tests that the {@code makepom} option works as expected
- *
- * @throws Exception if something goes wrong
*/
@Test
public void testMakePom() throws Exception {
@@ -212,14 +207,12 @@
*/
@Test
public void testSettingsURL() throws Exception {
- final URL settingsURL = new File("test/repositories/ivysettings.xml").toURI().toURL();
- run(new String[] {"-settings", settingsURL.toString(), "-ivy",
- "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"});
-
+ URL settingsURL = new File("test/repositories/ivysettings.xml").toURI().toURL();
+ run("-settings", settingsURL.toString(), "-ivy", "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml");
assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
}
- private void run(String[] args) throws Exception {
+ private void run(String... args) throws Exception {
Main.run(Main.getParser(), args);
}
}
diff --git a/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java b/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
index 4cb5e48..782d9ac 100644
--- a/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
+++ b/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
@@ -17,11 +17,6 @@
*/
package org.apache.ivy.ant;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
@@ -29,16 +24,22 @@
import org.apache.ivy.TestHelper;
import org.apache.ivy.core.report.ArtifactDownloadReport;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Delete;
import org.apache.tools.ant.types.FileSet;
+
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class IvyCacheFilesetTest {
@@ -46,9 +47,6 @@
private Project project;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
TestHelper.createCache();
@@ -227,11 +225,10 @@
@Test
public void requireCommonBaseDirEmptyList() {
+ List<ArtifactDownloadReport> reports = Collections.emptyList();
// we expect a BuildException when we try to find a (non-existent) common base dir
// across file system roots
- expExc.expect(BuildException.class);
- List<ArtifactDownloadReport> reports = Collections.emptyList();
- fileset.requireCommonBaseDir(reports);
+ assertThrows(BuildException.class, () -> fileset.requireCommonBaseDir(reports));
}
@Test
@@ -241,14 +238,13 @@
// single file system root isn't what we are interested in, in this test method
return;
}
- // we expect a BuildException when we try to find a (non-existent) common base dir
- // across file system roots
- expExc.expect(BuildException.class);
List<ArtifactDownloadReport> reports = Arrays.asList(
artifactDownloadReport(new File(fileSystemRoots[0], "a/b/c/d")),
artifactDownloadReport(new File(fileSystemRoots[1], "a/b/e/f"))
- );
- fileset.requireCommonBaseDir(reports);
+ );
+ // we expect a BuildException when we try to find a (non-existent) common base dir
+ // across file system roots
+ assertThrows(BuildException.class, () -> fileset.requireCommonBaseDir(reports));
}
@Test
diff --git a/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java b/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
index 1d19088..90a07d3 100644
--- a/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
+++ b/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
@@ -17,20 +17,23 @@
*/
package org.apache.ivy.ant;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import org.apache.ivy.TestHelper;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
+
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class IvyCleanCacheTest {
+
private IvyCleanCache cleanCache;
private File cacheDir;
@@ -41,9 +44,6 @@
private File resolutionCache;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() throws Exception {
Project p = TestHelper.newProject();
@@ -106,10 +106,9 @@
*/
@Test
public void testUnknownCache() {
- expExc.expect(BuildException.class);
- expExc.expectMessage("unknown cache 'yourcache'");
cleanCache.setResolution(false);
cleanCache.setCache("yourcache");
- cleanCache.perform();
+ Exception exception = assertThrows(BuildException.class, () -> cleanCache.perform());
+ assertEquals("unknown cache 'yourcache'", exception.getMessage());
}
}
diff --git a/test/java/org/apache/ivy/ant/IvyConfigureTest.java b/test/java/org/apache/ivy/ant/IvyConfigureTest.java
index 97b3437..5b4c875 100644
--- a/test/java/org/apache/ivy/ant/IvyConfigureTest.java
+++ b/test/java/org/apache/ivy/ant/IvyConfigureTest.java
@@ -17,12 +17,6 @@
*/
package org.apache.ivy.ant;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.util.List;
@@ -33,22 +27,27 @@
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.plugins.resolver.IBiblioResolver;
import org.apache.ivy.plugins.resolver.IvyRepResolver;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Reference;
+
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class IvyConfigureTest {
+
private IvyConfigure configure;
private Project project;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
project = TestHelper.newProject();
@@ -278,10 +277,6 @@
*/
@Test
public void testOverrideNotAllowed() {
- expExc.expect(BuildException.class);
- expExc.expectMessage("Overriding a previous definition of ivy:settings with the id '"
- + configure.getSettingsId() + "' is not allowed when using override='notallowed'.");
-
configure.setFile(new File("test/repositories/ivysettings.xml"));
configure.execute();
@@ -293,7 +288,9 @@
configure.setOverride("notallowed");
configure.setFile(new File("test/repositories/ivysettings.xml"));
- configure.execute();
+ Exception exception = assertThrows(BuildException.class, () -> configure.execute());
+ assertEquals("Overriding a previous definition of ivy:settings with the id '"
+ + configure.getSettingsId() + "' is not allowed when using override='notallowed'.", exception.getMessage());
}
/**
@@ -301,18 +298,13 @@
*/
@Test
public void testInvalidOverride() {
- expExc.expect(IllegalArgumentException.class);
- expExc.expectMessage("invalid override value 'unknown'. Valid values are "
- + "[true, false, notallowed]");
-
- configure.setOverride("unknown");
+ Exception exception = assertThrows(IllegalArgumentException.class, () -> configure.setOverride("unknown"));
+ assertEquals("invalid override value 'unknown'. Valid values are [true, false, notallowed]", exception.getMessage());
}
/**
* Tests that if the Ivy settings file <code>include</code>s another file as
* <code>optional</code>, then the absence of that file doesn't lead to failures
- *
- * @throws Exception if something goes wrong
*/
@Test
public void testOptionalFileInclude() throws Exception {
diff --git a/test/java/org/apache/ivy/ant/IvyDependencyUpdateCheckerTest.java b/test/java/org/apache/ivy/ant/IvyDependencyUpdateCheckerTest.java
index 4fa9606..26f14e8 100644
--- a/test/java/org/apache/ivy/ant/IvyDependencyUpdateCheckerTest.java
+++ b/test/java/org/apache/ivy/ant/IvyDependencyUpdateCheckerTest.java
@@ -28,21 +28,17 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
public class IvyDependencyUpdateCheckerTest extends AntTaskTestCase {
private IvyDependencyUpdateChecker dependencyUpdateChecker;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
TestHelper.createCache();
@@ -146,12 +142,10 @@
*/
@Test
public void testFailureWithMissingConfigurations() {
- expExc.expect(BuildException.class);
- expExc.expectMessage("unknown");
-
dependencyUpdateChecker.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
dependencyUpdateChecker.setConf("default,unknown");
- dependencyUpdateChecker.execute();
+ Exception exception = assertThrows(BuildException.class, () -> dependencyUpdateChecker.execute());
+ assertEquals("requested configuration not found in apache#resolve-simple;1.0: [ 'unknown' ]", exception.getCause().getMessage());
}
/**
diff --git a/test/java/org/apache/ivy/ant/IvyPublishTest.java b/test/java/org/apache/ivy/ant/IvyPublishTest.java
index 01e6dd5..430d77d 100644
--- a/test/java/org/apache/ivy/ant/IvyPublishTest.java
+++ b/test/java/org/apache/ivy/ant/IvyPublishTest.java
@@ -39,23 +39,20 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class IvyPublishTest {
- private File cache;
private IvyPublish publish;
private Project project;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
+ private File cache;
@Before
public void setUp() {
@@ -405,8 +402,6 @@
*/
@Test
public void testHaltOnMissing() {
- expExc.expect(BuildException.class);
- expExc.expectMessage("missing artifact apache#resolve-simple;1.2!resolve-simple.jar");
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml");
IvyResolve res = new IvyResolve();
res.setProject(project);
@@ -415,19 +410,16 @@
publish.setPubrevision("1.2");
publish.setResolver("1");
publish.setHaltonmissing(true);
- try {
- publish.execute();
- } finally {
- // should have delivered the ivy file
- assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
- // should not have published the files with "1" resolver
- assertFalse(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml")
- .exists());
- assertFalse(new File(
- "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar")
- .exists());
- }
+ Exception exception = assertThrows(BuildException.class, () -> publish.execute());
+ assertEquals("missing artifact apache#resolve-simple;1.2!resolve-simple.jar", exception.getCause().getMessage());
+
+ // should have delivered the ivy file
+ assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
+
+ // should not have published the files with "1" resolver
+ assertFalse(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").exists());
+ assertFalse(new File("test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar").exists());
}
/**
@@ -437,8 +429,6 @@
*/
@Test
public void testHaltOnMissing2() throws IOException {
- expExc.expect(BuildException.class);
- expExc.expectMessage("missing artifact apache#multi;1.2!multi2.jar");
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-publish-multi.xml");
IvyResolve res = new IvyResolve();
res.setProject(project);
@@ -451,15 +441,15 @@
publish.setPubrevision("1.2");
publish.setResolver("transactional");
publish.setHaltonmissing(true);
- try {
- publish.execute();
- } finally {
- // should have delivered the ivy file
- assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
- // should not have published the files with "transactional" resolver
- assertFalse(new File("build/test/transactional/apache/multi/1.2").exists());
- }
+ Exception exception = assertThrows(BuildException.class, () -> publish.execute());
+ assertEquals("missing artifact apache#multi;1.2!multi2.jar", exception.getCause().getMessage());
+
+ // should have delivered the ivy file
+ assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
+
+ // should not have published the files with "transactional" resolver
+ assertFalse(new File("build/test/transactional/apache/multi/1.2").exists());
}
/**
@@ -469,8 +459,6 @@
*/
@Test
public void testHaltOnMissing3() throws IOException {
- expExc.expect(BuildException.class);
- expExc.expectMessage("missing artifact apache#multi;1.2!multi2.jar");
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-publish-multi.xml");
IvyResolve res = new IvyResolve();
res.setProject(project);
@@ -483,15 +471,15 @@
publish.setPubrevision("1.2");
publish.setResolver("1");
publish.setHaltonmissing(true);
- try {
- publish.execute();
- } finally {
- // should have delivered the ivy file
- assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
- // should not have published the files with "transactional" resolver
- assertFalse(new File("test/repositories/1/apache/multi").exists());
- }
+ Exception exception = assertThrows(BuildException.class, () -> publish.execute());
+ assertEquals("missing artifact apache#multi;1.2!multi2.jar", exception.getCause().getMessage());
+
+ // should have delivered the ivy file
+ assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
+
+ // should not have published the files with "transactional" resolver
+ assertFalse(new File("test/repositories/1/apache/multi").exists());
}
@Test
diff --git a/test/java/org/apache/ivy/ant/IvyResolveTest.java b/test/java/org/apache/ivy/ant/IvyResolveTest.java
index d69a831..088968e 100644
--- a/test/java/org/apache/ivy/ant/IvyResolveTest.java
+++ b/test/java/org/apache/ivy/ant/IvyResolveTest.java
@@ -31,24 +31,20 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class IvyResolveTest {
- private Project project;
-
private IvyResolve resolve;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
+ private Project project;
@Before
public void setUp() {
@@ -324,12 +320,10 @@
@Test
public void testFailureWithMissingConfigurations() {
- expExc.expect(BuildException.class);
- expExc.expectMessage("unknown");
-
resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
resolve.setConf("default,unknown");
- resolve.execute();
+ Exception exception = assertThrows(BuildException.class, () -> resolve.execute());
+ assertEquals("requested configuration not found in apache#resolve-simple;1.0: [ 'unknown' ]", exception.getCause().getMessage());
}
@Test(expected = BuildException.class)
diff --git a/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java b/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java
index 0c8fc3c..9a7667e 100644
--- a/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java
+++ b/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java
@@ -17,20 +17,17 @@
*/
package org.apache.ivy.core.module.id;
-import static org.junit.Assert.assertEquals;
-
import java.util.HashMap;
import java.util.Map;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
public class ModuleRevisionIdTest {
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Test
public void testParse() {
testParse("#A;1.0");
@@ -67,10 +64,8 @@
}
private void testParseFailure(String mrid) {
- expExc.expect(IllegalArgumentException.class);
- expExc.expectMessage(mrid);
-
- ModuleRevisionId.parse(mrid);
+ Exception exception = assertThrows(IllegalArgumentException.class, () -> ModuleRevisionId.parse(mrid));
+ assertTrue(exception.getMessage().contains(mrid));
}
@Test
@@ -90,11 +85,9 @@
extraAttributes.put("nullatt", null);
testEncodeDecodeToString(
ModuleRevisionId.newInstance("org/apache", "pre/name", "1.0-dev8/2", extraAttributes));
-
}
private void testEncodeDecodeToString(ModuleRevisionId mrid) {
assertEquals(mrid, ModuleRevisionId.decode(mrid.encodeToString()));
}
-
}
diff --git a/test/java/org/apache/ivy/core/resolve/ResolveTest.java b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
index 53631de..a18816d 100644
--- a/test/java/org/apache/ivy/core/resolve/ResolveTest.java
+++ b/test/java/org/apache/ivy/core/resolve/ResolveTest.java
@@ -17,6 +17,26 @@
*/
package org.apache.ivy.core.resolve;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.ivy.Ivy;
import org.apache.ivy.TestHelper;
import org.apache.ivy.core.cache.ArtifactOrigin;
@@ -52,56 +72,28 @@
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.MockMessageLogger;
import org.apache.ivy.util.XMLHelper;
+
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
import static org.apache.ivy.util.StringUtils.joinArray;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-/**
- *
- */
-public class ResolveTest {
+public final class ResolveTest {
+
private Ivy ivy;
- private File cache;
-
- private File deliverDir;
-
- private File workDir;
-
- @Rule
- public ExpectedException expExc = ExpectedException.none();
+ private File cache, workDir, deliverDir;
@Before
public void setUp() throws Exception {
@@ -746,29 +738,22 @@
// set up repository
FileUtil.forceDelete(new File("build/testCache2"));
- FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File(
- "build/testCache2/mod1.2-1.5.jar"), null);
+ FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File("build/testCache2/mod1.2-1.5.jar"), null);
// we first do a simple resolve so that module is in cache
- ResolveReport report = ivy.resolve(new File(
- "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"),
- getResolveOptions(new String[] {"*"}));
+ ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] {"*"}));
assertFalse(report.hasError());
- assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")),
- report.getConfigurationReport("default").getModuleRevisionIds());
+ assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")), report.getConfigurationReport("default").getModuleRevisionIds());
// now we update the repository
- FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File(
- "build/testCache2/mod1.2-1.6.jar"), null);
+ FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File("build/testCache2/mod1.2-1.6.jar"), null);
// now do a new resolve: it should not use cached data
- report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"),
- getResolveOptions(new String[] {"*"}));
+ report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] {"*"}));
assertFalse(report.hasError());
- assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.6")),
- report.getConfigurationReport("default").getModuleRevisionIds());
+ assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.6")), report.getConfigurationReport("default").getModuleRevisionIds());
}
@Test
@@ -3479,34 +3464,24 @@
/**
* Circular dependency: mod6.3 depends on mod6.2, which itself depends on mod6.3;
* circular dependency strategy set to error.
- *
- * @throws Exception if something goes wrong
*/
@Test
public void testCircular() throws Exception {
- expExc.expect(CircularDependencyException.class);
- expExc.expectMessage("org6#mod6.3;1.0->org6#mod6.2;1.0->org6#mod6.3;latest.integration");
-
- ResolveReport report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"),
- getResolveOptions(new String[] {"default"}));
+ ResolveReport report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"), getResolveOptions(new String[] {"default"}));
assertFalse(report.hasError());
- ivy.getSettings().setCircularDependencyStrategy(
- IgnoreCircularDependencyStrategy.getInstance());
- report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"),
- getResolveOptions(new String[] {"default"}));
+ ivy.getSettings().setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance());
+ report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"), getResolveOptions(new String[] {"default"}));
assertFalse(report.hasError());
- ivy.getSettings().setCircularDependencyStrategy(
- WarnCircularDependencyStrategy.getInstance());
- report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"),
- getResolveOptions(new String[] {"default"}));
+ ivy.getSettings().setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance());
+ report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"), getResolveOptions(new String[] {"default"}));
assertFalse(report.hasError());
- ivy.getSettings().setCircularDependencyStrategy(
- ErrorCircularDependencyStrategy.getInstance());
- ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"),
- getResolveOptions(new String[] {"default"}));
+ ivy.getSettings().setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
+ Exception e = assertThrows(CircularDependencyException.class, () ->
+ ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml"), getResolveOptions(new String[] {"default"})));
+ assertEquals("org6#mod6.3;1.0->org6#mod6.2;1.0->org6#mod6.3;latest.integration", e.getMessage());
}
/**
@@ -3517,17 +3492,13 @@
*/
@Test
public void testCircular2() throws Exception {
- expExc.expect(CircularDependencyException.class);
- expExc.expectMessage("org8#mod8.5;NONE->org8#mod8.6;2.+->org8#mod8.5;2.+");
-
- ResolveReport report = ivy.resolve(new File("test/repositories/circular/ivy.xml"),
- getResolveOptions(new String[] {"*"}));
+ ResolveReport report = ivy.resolve(new File("test/repositories/circular/ivy.xml"), getResolveOptions(new String[] {"*"}));
assertFalse(report.hasError());
- ivy.getSettings().setCircularDependencyStrategy(
- ErrorCircularDependencyStrategy.getInstance());
- ivy.resolve(new File("test/repositories/circular/ivy.xml"),
- getResolveOptions(new String[] {"*"}));
+ ivy.getSettings().setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
+ Exception e = assertThrows(CircularDependencyException.class, () ->
+ ivy.resolve(new File("test/repositories/circular/ivy.xml"), getResolveOptions(new String[] {"*"})));
+ assertEquals("org8#mod8.5;NONE->org8#mod8.6;2.+->org8#mod8.5;2.+", e.getMessage());
}
/**
@@ -3540,36 +3511,28 @@
*/
@Test
public void testCircular3() throws Exception {
- expExc.expect(CircularDependencyException.class);
- expExc.expectMessage("org6#mod6.3;1.2->org6#mod6.2;1.1->...");
-
- ResolveReport report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"),
- getResolveOptions(new String[] {"default", "test"}));
+ ResolveReport report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"), getResolveOptions(new String[] {"default", "test"}));
assertFalse(report.hasError());
// we should have mod 6.2 artifact in both configurations
assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber());
assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber());
- ivy.getSettings().setCircularDependencyStrategy(
- IgnoreCircularDependencyStrategy.getInstance());
- report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"),
- getResolveOptions(new String[] {"default", "test"}));
+ ivy.getSettings().setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance());
+ report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"), getResolveOptions(new String[] {"default", "test"}));
assertFalse(report.hasError());
assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber());
assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber());
- ivy.getSettings().setCircularDependencyStrategy(
- WarnCircularDependencyStrategy.getInstance());
- report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"),
- getResolveOptions(new String[] {"default", "test"}));
+ ivy.getSettings().setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance());
+ report = ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"), getResolveOptions(new String[] {"default", "test"}));
assertFalse(report.hasError());
assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber());
assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber());
- ivy.getSettings().setCircularDependencyStrategy(
- ErrorCircularDependencyStrategy.getInstance());
- ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"),
- getResolveOptions(new String[] {"default", "test"}));
+ ivy.getSettings().setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
+ Exception e = assertThrows(CircularDependencyException.class, () ->
+ ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml"), getResolveOptions(new String[] {"default", "test"})));
+ assertEquals("org6#mod6.3;1.2->org6#mod6.2;1.1->...", e.getMessage());
}
@Test
@@ -4421,13 +4384,11 @@
assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists());
}
-
/**
* Test for issues IVY-982 and IVY-1547,
* which have to do with resolve engine ignoring negated configurations
* on the left side of the maps-to operator.
*/
-
@Test
public void testResolveWithNegation() throws Exception {
ConfigurationResolveReport crp;
@@ -5107,8 +5068,8 @@
ivy.getSettings().setDefaultResolver("parentChain");
final File pom = new File("test/repositories/parentPom/org/apache/dm/sibling1/1.0/sibling1-1.0.pom");
final ResolveReport report = ivy.resolve(pom, getResolveOptions(new String[]{"*"}));
- Assert.assertNotNull("Resolve report is null", report);
- Assert.assertFalse("Resolve report has errors", report.hasError());
+ assertNotNull("Resolve report is null", report);
+ assertFalse("Resolve report has errors", report.hasError());
}
@Test
diff --git a/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java b/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
index 4ba4387..92499da 100644
--- a/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
+++ b/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
@@ -17,6 +17,11 @@
*/
package org.apache.ivy.core.settings;
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.List;
+
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.cache.ResolutionCacheManager;
import org.apache.ivy.core.module.descriptor.Artifact;
@@ -43,27 +48,20 @@
import org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher;
import org.apache.ivy.plugins.version.MockVersionMatcher;
import org.apache.ivy.plugins.version.VersionMatcher;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.List;
+import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
/**
* Test the parsing of Ivy settings file through the {@link XmlSettingsParser}
*/
public class XmlSettingsParserTest {
- @Rule
- public ExpectedException expExc = ExpectedException.none();
@Test
public void test() throws Exception {
@@ -261,18 +259,15 @@
/**
* Test of resolver referencing a non existent cache.
- *
- * @throws Exception if something goes wrong
*/
@Test
- public void testInvalidCache() throws Exception {
- expExc.expect(ParseException.class);
- expExc.expectMessage("mycache");
-
+ public void testInvalidCache() {
IvySettings settings = new IvySettings();
XmlSettingsParser parser = new XmlSettingsParser(settings);
- parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-cache-invalid.xml"));
+ Exception exception = assertThrows(ParseException.class, () ->
+ parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-cache-invalid.xml")));
+ assertTrue(exception.getMessage().endsWith("unknown cache manager 'mycache'. Available caches are [mycache2]"));
}
@Test
diff --git a/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java b/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java
index 745c9eb..20f3310 100644
--- a/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java
+++ b/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java
@@ -17,20 +17,17 @@
*/
package org.apache.ivy.osgi.core;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collection;
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
@RunWith(Enclosed.class)
public class ManifestHeaderTest {
@@ -92,15 +89,11 @@
ManifestHeaderValue value = new ManifestHeaderValue("glassfish javax.servlet.3.1.0.b33");
assertEquals("glassfish javax.servlet.3.1.0.b33", value.getSingleValue());
}
-
}
@RunWith(Parameterized.class)
public static class IllegalOptionTests {
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Parameterized.Parameters(name = "Illegal token at {1} in {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{"value1=", 6},
@@ -119,12 +112,10 @@
* Expected failure when the parameter is illegal
*/
@Test
- public void testSyntaxError() throws ParseException {
- expExc.expect(ParseException.class);
- expExc.expect(hasProperty("errorOffset", is(offset)));
- new ManifestHeaderValue(value);
+ public void testSyntaxError() {
+ ParseException exception = assertThrows(ParseException.class, () -> new ManifestHeaderValue(value));
+ assertEquals(offset, exception.getErrorOffset());
}
-
}
@RunWith(Parameterized.class)
@@ -155,7 +146,5 @@
public void testNormalisation() throws Exception {
assertEquals(new ManifestHeaderValue(normalised), new ManifestHeaderValue(value));
}
-
}
-
}
diff --git a/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java
index 46c313c..aac42bb 100644
--- a/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java
+++ b/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java
@@ -22,24 +22,25 @@
import org.apache.ivy.Ivy;
import org.apache.ivy.core.resolve.ResolveOptions;
import org.apache.ivy.util.FileUtil;
+
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
public class RegexpConflictManagerTest {
+
private Ivy ivy;
private File cache;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() throws Exception {
ivy = new Ivy();
ivy.configure(RegexpConflictManagerTest.class.getResource("ivysettings-regexp-test.xml"));
+
cache = new File("build/cache");
cache.mkdirs();
}
@@ -51,17 +52,13 @@
@Test
public void testNoApiConflictResolve() throws Exception {
- ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-no-regexp-conflict.xml"),
- getResolveOptions());
+ ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-no-regexp-conflict.xml"), getResolveOptions());
}
@Test
- public void testConflictResolve() throws Exception {
- expExc.expect(StrictConflictException.class);
- expExc.expectMessage("org1#mod1.2;2.0.0:2.0 (needed by [apache#resolve-noconflict;1.0]) conflicts with org1#mod1.2;2.1.0:2.1 (needed by [apache#resolve-noconflict;1.0])");
-
- ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-conflict.xml"),
- getResolveOptions());
+ public void testConflictResolve() {
+ Exception exception = assertThrows(StrictConflictException.class, () -> ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-conflict.xml"), getResolveOptions()));
+ assertEquals("org1#mod1.2;2.0.0:2.0 (needed by [apache#resolve-noconflict;1.0]) conflicts with org1#mod1.2;2.1.0:2.1 (needed by [apache#resolve-noconflict;1.0])", exception.getMessage());
}
private ResolveOptions getResolveOptions() {
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
index 58f6f47..e933bde 100644
--- a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
+++ b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
@@ -17,13 +17,6 @@
*/
package org.apache.ivy.plugins.parser.m2;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -58,13 +51,21 @@
import org.apache.ivy.plugins.repository.url.URLResource;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.plugins.resolver.MockResolver;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester {
private IvySettings settings = new IvySettings();
@@ -87,9 +88,6 @@
private MockResolver mockedResolver = new MockedDependencyResolver();
@Rule
- public ExpectedException expExc = ExpectedException.none();
-
- @Rule
public TemporaryFolder workDir = new TemporaryFolder();
@Before
@@ -220,12 +218,10 @@
}
@Test
- public void testParentNotFound() throws Exception {
- expExc.expect(IOException.class);
- expExc.expectMessage("Impossible to load parent");
-
- PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(),
- getClass().getResource("test-parent-not-found.pom"), false);
+ public void testParentNotFound() {
+ Exception exception = assertThrows(IOException.class, () ->
+ PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), getClass().getResource("test-parent-not-found.pom"), false));
+ assertTrue(exception.getMessage().startsWith("Impossible to load parent"));
}
@Test
@@ -427,7 +423,7 @@
assertEquals(5, dds.length);
for (int i = 0; i < dds.length; i++) {
assertEquals(2, dds[i].getAllDependencyArtifacts().length);
- int withExt = i == 0 || i == 3 ? 1: 0;
+ int withExt = i == 0 || i == 3 ? 1 : 0;
assertEquals(extraAtt, dds[i].getAllDependencyArtifacts()[withExt].getExtraAttributes());
}
}
@@ -1285,17 +1281,14 @@
for (final String expectedPackagingType : packagingTypesToTest) {
String sysPropToSet = null;
switch (expectedPackagingType) {
- case "bundle": {
+ case "bundle":
sysPropToSet = "PomModuleDescriptorParserTest.some-other-test-prop";
break;
- }
- case "jar": {
+ case "jar":
sysPropToSet = "PomModuleDescriptorParserTest.some-test-prop";
break;
- }
- default: {
+ default:
fail("Unexpected packaging type");
- }
}
// activate the relevant profile, based on a system property
System.setProperty(sysPropToSet, "foo");
diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
index 119f355..1e55218 100644
--- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
+++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
@@ -17,6 +17,22 @@
*/
package org.apache.ivy.plugins.parser.xml;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.ivy.Ivy;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.Configuration;
@@ -41,40 +57,23 @@
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.XMLHelper;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashSet;
-import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
import static org.apache.ivy.core.module.descriptor.Configuration.Visibility.PRIVATE;
import static org.apache.ivy.core.module.descriptor.Configuration.Visibility.PUBLIC;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class XmlModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester {
- private IvySettings settings = null;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
+ private IvySettings settings;
@Before
public void setUp() {
@@ -148,52 +147,42 @@
}
@Test
- public void testBad() throws IOException, ParseException {
- expExc.expect(ParseException.class);
- expExc.expectMessage("'modul'");
-
+ public void testBad() {
assertTrue(XMLHelper.canUseSchemaValidation());
- XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
- getClass().getResource("test-bad.xml"), true);
+ Exception exception = assertThrows(ParseException.class, () ->
+ XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-bad.xml"), true));
+ assertTrue(exception.getMessage().contains("'modul'"));
}
@Test
- public void testBadOrg() throws IOException, ParseException {
- expExc.expect(ParseException.class);
- expExc.expectMessage("organization");
-
+ public void testBadOrg() {
assertTrue(XMLHelper.canUseSchemaValidation());
- XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
- getClass().getResource("test-bad-org.xml"), true);
+ Exception exception = assertThrows(ParseException.class, () ->
+ XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-bad-org.xml"), true));
+ assertTrue(exception.getMessage().contains("organization"));
}
@Test
- public void testBadConfs() throws IOException, ParseException {
- expExc.expect(ParseException.class);
- expExc.expectMessage("invalidConf");
-
- XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
- getClass().getResource("test-bad-confs.xml"), true);
+ public void testBadConfs() {
+ Exception exception = assertThrows(ParseException.class, () ->
+ XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-bad-confs.xml"), true));
+ assertTrue(exception.getMessage().contains("invalidConf"));
}
@Test
- public void testCyclicConfs2() throws IOException, ParseException {
- expExc.expect(ParseException.class);
- expExc.expectMessage("A => B => A");
-
- XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
- getClass().getResource("test-cyclic-confs1.xml"), true);
+ public void testCyclicConfs2() {
+ Exception exception = assertThrows(ParseException.class, () ->
+ XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-cyclic-confs1.xml"), true));
+ assertTrue(exception.getMessage().contains("A => B => A"));
}
@Test
- public void testCyclicConfs3() throws IOException, ParseException {
- expExc.expect(ParseException.class);
- expExc.expectMessage("A => C => B => A");
-
- XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
- getClass().getResource("test-cyclic-confs2.xml"), true);
+ public void testCyclicConfs3() {
+ Exception exception = assertThrows(ParseException.class, () ->
+ XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-cyclic-confs2.xml"), true));
+ assertTrue(exception.getMessage().contains("A => C => B => A"));
}
@Test
@@ -1474,7 +1463,7 @@
final Path targetDir = Paths.get(System.getProperty("java.io.tmpdir"), "foo%2Fbar");
Files.createDirectories(targetDir);
final Path parentIvyXMLPath = Paths.get(targetDir.toString(), "parent-ivy.xml");
- try (final InputStream is = parentIvyXML.openStream()) {
+ try (InputStream is = parentIvyXML.openStream()) {
Files.copy(is, parentIvyXMLPath, StandardCopyOption.REPLACE_EXISTING);
}
assertTrue("Parent ivy xml file wasn't copied", Files.isRegularFile(parentIvyXMLPath));
diff --git a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
index a8b412f..1cc3abe 100644
--- a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
+++ b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
@@ -51,21 +51,16 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-/**
- *
- */
public class FileSystemResolverTest extends AbstractDependencyResolverTest {
- // CheckStyle:MagicNumberCheck OFF
private static final String FS = File.separator;
@@ -89,9 +84,6 @@
setupLastModified();
}
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
settings = new IvySettings();
@@ -889,21 +881,14 @@
resolver.abortPublishTransaction();
assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
- assertFalse(new File(
- "test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
- .exists());
+ assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext").exists());
}
/**
* Publishing with transaction=true and an unsupported pattern must fail.
- *
- * @throws Exception if something goes wrong
*/
@Test
- public void testUnsupportedTransaction() throws Exception {
- expExc.expect(IllegalStateException.class);
- expExc.expectMessage("transactional");
-
+ public void testUnsupportedTransaction() {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
@@ -919,20 +904,18 @@
"myext");
File src = new File("test/repositories/ivysettings.xml");
- resolver.beginPublishTransaction(mrid, false);
- resolver.publish(artifact, src, false);
+ Exception exception = assertThrows(IllegalStateException.class, () -> {
+ resolver.beginPublishTransaction(mrid, false);
+ resolver.publish(artifact, src, false);
+ });
+ assertTrue(exception.getMessage().contains("transactional"));
}
/**
* Publishing with transaction=true and an unsupported combination of patterns must fail.
- *
- * @throws Exception if something goes wrong
*/
@Test
- public void testUnsupportedTransaction2() throws Exception {
- expExc.expect(IllegalStateException.class);
- expExc.expectMessage("transactional");
-
+ public void testUnsupportedTransaction2() {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
@@ -950,21 +933,19 @@
"myext");
File src = new File("test/repositories/ivysettings.xml");
- resolver.beginPublishTransaction(mrid, false);
- resolver.publish(ivyArtifact, src, false);
- resolver.publish(artifact, src, false);
+ Exception exception = assertThrows(IllegalStateException.class, () -> {
+ resolver.beginPublishTransaction(mrid, false);
+ resolver.publish(ivyArtifact, src, false);
+ resolver.publish(artifact, src, false);
+ });
+ assertTrue(exception.getMessage().contains("transactional"));
}
/**
* Publishing with transaction=true and overwrite mode must fail.
- *
- * @throws Exception if something goes wrong
*/
@Test
- public void testUnsupportedTransaction3() throws Exception {
- expExc.expect(IllegalStateException.class);
- expExc.expectMessage("transactional");
-
+ public void testUnsupportedTransaction3() {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
@@ -978,9 +959,12 @@
"myext");
File src = new File("test/repositories/ivysettings.xml");
- // overwrite transaction not supported
- resolver.beginPublishTransaction(mrid, true);
- resolver.publish(artifact, src, true);
+ Exception exception = assertThrows(IllegalStateException.class, () -> {
+ // overwrite transaction not supported
+ resolver.beginPublishTransaction(mrid, true);
+ resolver.publish(artifact, src, true);
+ });
+ assertTrue(exception.getMessage().contains("transactional"));
}
@Test
diff --git a/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java
index d862501..de98312 100644
--- a/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java
+++ b/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java
@@ -17,9 +17,6 @@
*/
package org.apache.ivy.plugins.resolver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
import java.io.File;
import java.util.List;
@@ -38,25 +35,24 @@
import org.apache.ivy.core.resolve.ResolvedModuleRevision;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.core.sort.SortEngine;
+
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-/**
- *
- */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
public class IvyRepResolverTest extends AbstractDependencyResolverTest {
+
private IvySettings settings;
private ResolveEngine engine;
private ResolveData data;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
settings = new IvySettings();
@@ -97,21 +93,19 @@
/**
* Test case for IVY-625. Must fail if no ivyroot specified.
*
- * @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-625">IVY-625</a>
*/
@Test
- public void testMandatoryRoot() throws Exception {
- expExc.expect(IllegalStateException.class);
- expExc.expectMessage("ivyroot");
-
+ public void testMandatoryRoot() {
IvyRepResolver resolver = new IvyRepResolver();
resolver.setName("test");
resolver.setSettings(settings);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-cli", "1.0");
- resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
+ Exception exception = assertThrows(IllegalStateException.class, () ->
+ resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data));
+ assertTrue(exception.getMessage().contains("ivyroot"));
}
@Test
diff --git a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java b/test/java/org/apache/ivy/util/url/HttpClientHandlerTest.java
similarity index 85%
rename from test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
rename to test/java/org/apache/ivy/util/url/HttpClientHandlerTest.java
index 113655d..06dd7f0 100644
--- a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
+++ b/test/java/org/apache/ivy/util/url/HttpClientHandlerTest.java
@@ -17,17 +17,6 @@
*/
package org.apache.ivy.util.url;
-import org.apache.ivy.TestHelper;
-import org.apache.ivy.core.settings.NamedTimeoutConstraint;
-import org.apache.ivy.core.settings.TimeoutConstraint;
-import org.apache.ivy.util.FileUtil;
-import org.apache.ivy.util.url.URLHandler.URLInfo;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -37,30 +26,31 @@
import java.util.Collections;
import java.util.Random;
+import org.apache.ivy.TestHelper;
+import org.apache.ivy.core.settings.NamedTimeoutConstraint;
+import org.apache.ivy.core.settings.TimeoutConstraint;
+import org.apache.ivy.util.FileUtil;
+import org.apache.ivy.util.url.URLHandler.URLInfo;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import static org.apache.ivy.plugins.resolver.IBiblioResolver.DEFAULT_M2_ROOT;
-import static org.hamcrest.Matchers.endsWith;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-/**
- * Test {@link HttpClientHandler}
- */
-public class HttpclientURLHandlerTest {
+public class HttpClientHandlerTest {
+
// remote.test
private File testDir;
private HttpClientHandler handler;
- private final TimeoutConstraint defaultTimeoutConstraint;
-
- {
- defaultTimeoutConstraint = new NamedTimeoutConstraint("default-http-client-handler-timeout");
- ((NamedTimeoutConstraint) defaultTimeoutConstraint).setConnectionTimeout(5000);
- }
-
- @Rule
- public ExpectedException expExc = ExpectedException.none();
+ private TimeoutConstraint defaultTimeoutConstraint;
@Before
public void setUp() {
@@ -68,14 +58,16 @@
testDir.mkdirs();
handler = new HttpClientHandler();
+
+ defaultTimeoutConstraint = new NamedTimeoutConstraint("default-http-client-handler-timeout");
+ ((NamedTimeoutConstraint) defaultTimeoutConstraint).setConnectionTimeout(5000);
}
@After
public void tearDown() {
try {
handler.close();
- } catch (Exception e) {
- // ignore
+ } catch (Exception ignore) {
}
FileUtil.forceDelete(testDir);
}
@@ -91,7 +83,6 @@
/**
* Test case for IVY-390.
*
- * @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-390">IVY-390</a>
*/
@SuppressWarnings({"resource", "deprecation"})
@@ -129,18 +120,10 @@
* {@link CredentialsStore Ivy credentials store} works as expected when it interacts
* with a HTTP server which requires authentication for accessing resources.
*
- * @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1336">IVY-1336</a>
*/
@Test
public void testCredentials() throws Exception {
- // we catch it and check for presence of 401 in the exception message.
- // It's not exactly an contract that the IOException will have the 401 message
- // but for now that's how it's implemented and it's fine to check for the presence
- // of that message at the moment
- expExc.expect(IOException.class);
- expExc.expectMessage(endsWith("ivysettings.xml' 401 - 'Unauthorized"));
-
final CredentialsStore credentialsStore = CredentialsStore.INSTANCE;
final String realm = "test-http-client-handler-realm";
final String host = "localhost";
@@ -153,7 +136,7 @@
final Path repoRoot = new File("test/repositories").toPath();
assertTrue(repoRoot + " is not a directory", Files.isDirectory(repoRoot));
// create a server backed by BASIC auth with the set of "allowed" credentials
- try (final AutoCloseable server = TestHelper.createBasicAuthHttpServerBackedRepo(serverBindAddr,
+ try (AutoCloseable server = TestHelper.createBasicAuthHttpServerBackedRepo(serverBindAddr,
contextRoot, repoRoot, realm, Collections.singletonMap(userName, password))) {
final File target = new File(testDir, "downloaded.xml");
@@ -167,7 +150,7 @@
// now create a server backed by BASIC auth with a set of credentials that do *not* match
// with what the Ivy credentials store will return for a given realm+host combination, i.e.
// Ivy credential store will return back invalid credentials and the server will reject them
- try (final AutoCloseable server = TestHelper.createBasicAuthHttpServerBackedRepo(serverBindAddr,
+ try (AutoCloseable server = TestHelper.createBasicAuthHttpServerBackedRepo(serverBindAddr,
contextRoot, repoRoot, realm, Collections.singletonMap("other-" + userName, "other-" + password))) {
final File target = new File(testDir, "should-not-have-been-downloaded.xml");
@@ -175,7 +158,12 @@
final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/"
+ contextRoot + "/ivysettings.xml");
// download it (expected to fail)
- handler.download(src, target, null, defaultTimeoutConstraint);
+ Exception exception = assertThrows(IOException.class, () -> handler.download(src, target, null, defaultTimeoutConstraint));
+ // we catch it and check for presence of 401 in the exception message.
+ // It's not exactly an contract that the IOException will have the 401 message
+ // but for now that's how it's implemented and it's fine to check for the presence
+ // of that message at the moment
+ assertTrue(exception.getMessage().endsWith("ivysettings.xml' 401 - 'Unauthorized"));
}
}