diff --git a/test/java/org/apache/ivy/MainTest.java b/test/java/org/apache/ivy/MainTest.java
index 994afb27..ba207a59 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,18 +26,27 @@ import java.util.Arrays;
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 {
private File cache;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();
@@ -65,51 +63,47 @@ public class MainTest {
@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 @@ public class MainTest {
@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 @@ public class MainTest {
@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 @@ public class MainTest {
* {@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 IVY-1355
*/
@Test
@@ -165,8 +164,6 @@ public class MainTest {
/**
* 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 @@ public class MainTest {
/**
* 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 @@ public class MainTest {
*/
@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 4cb5e48a..782d9ac5 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 java.util.List;
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 @@ public class IvyCacheFilesetTest {
private Project project;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() {
TestHelper.createCache();
@@ -227,11 +225,10 @@ public class IvyCacheFilesetTest {
@Test
public void requireCommonBaseDirEmptyList() {
+ List 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 reports = Collections.emptyList();
- fileset.requireCommonBaseDir(reports);
+ assertThrows(BuildException.class, () -> fileset.requireCommonBaseDir(reports));
}
@Test
@@ -241,14 +238,13 @@ public class IvyCacheFilesetTest {
// 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 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 1d19088f..90a07d39 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 @@ public class IvyCleanCacheTest {
private File resolutionCache;
- @Rule
- public ExpectedException expExc = ExpectedException.none();
-
@Before
public void setUp() throws Exception {
Project p = TestHelper.newProject();
@@ -106,10 +106,9 @@ public class IvyCleanCacheTest {
*/
@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 97b34371..5b4c8751 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.core.settings.IvySettings;
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 @@ public class IvyConfigureTest {
*/
@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 @@ public class IvyConfigureTest {
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 @@ public class IvyConfigureTest {
*/
@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 includes another file as
* optional, 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 4fa96065..26f14e84 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.apache.tools.ant.Project;
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 @@ public class IvyDependencyUpdateCheckerTest extends AntTaskTestCase {
*/
@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 01e6dd5a..430d77df 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.apache.tools.ant.taskdefs.Echo;
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 @@ public class IvyPublishTest {
*/
@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 @@ public class IvyPublishTest {
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 @@ public class IvyPublishTest {
*/
@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 @@ public class IvyPublishTest {
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 @@ public class IvyPublishTest {
*/
@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 @@ public class IvyPublishTest {
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 d69a8317..088968e7 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.apache.tools.ant.taskdefs.Parallel;
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 @@ public class IvyResolveTest {
@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 0c8fc3c9..9a7667e6 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 @@ public class ModuleRevisionIdTest {
}
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 @@ public class ModuleRevisionIdTest {
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 53631de8..a18816de 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.CacheCleaner;
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 @@ public class ResolveTest {
// 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 @@ public class ResolveTest {
/**
* 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 @@ public class ResolveTest {
*/
@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 @@ public class ResolveTest {
*/
@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 @@ public class ResolveTest {
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 @@ public class ResolveTest {
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 4ba4387e..92499da5 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.ChainVersionMatcher;
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 @@ public class XmlSettingsParserTest {
/**
* 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 745c9eb9..20f33100 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 @@ public class ManifestHeaderTest {
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