You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2017/12/05 10:48:29 UTC

ant-ivy git commit: use expected exception and try-finally for post-mortem (until JUnit 5 ; -)

Repository: ant-ivy
Updated Branches:
  refs/heads/master 5d7896111 -> 4a8068579


use expected exception and try-finally for post-mortem
(until JUnit 5 ;-)

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/4a806857
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/4a806857
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/4a806857

Branch: refs/heads/master
Commit: 4a8068579ea5bf1e637f8bed09a203508abde315
Parents: 5d78961
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Tue Dec 5 11:47:56 2017 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Tue Dec 5 11:47:56 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/ivy/ant/IvyPublishTest.java | 55 ++++++++++++--------
 .../apache/ivy/core/retrieve/RetrieveTest.java  |  9 ++--
 2 files changed, 36 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4a806857/test/java/org/apache/ivy/ant/IvyPublishTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/ant/IvyPublishTest.java b/test/java/org/apache/ivy/ant/IvyPublishTest.java
index b7696e9..4cdc3e2 100644
--- a/test/java/org/apache/ivy/ant/IvyPublishTest.java
+++ b/test/java/org/apache/ivy/ant/IvyPublishTest.java
@@ -39,12 +39,13 @@ 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.fail;
 
 public class IvyPublishTest {
     private File cache;
@@ -53,6 +54,9 @@ public class IvyPublishTest {
 
     private Project project;
 
+    @Rule
+    public ExpectedException expExc = ExpectedException.none();
+
     @Before
     public void setUp() {
         cleanTestDir();
@@ -399,8 +403,13 @@ public class IvyPublishTest {
         assertEquals("1.2", md.getModuleRevisionId().getRevision());
     }
 
+    /**
+     * Expected failure: publish with haltonmissing and a missing artifact
+     */
     @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);
@@ -411,11 +420,8 @@ public class IvyPublishTest {
         publish.setHaltonmissing(true);
         try {
             publish.execute();
-            fail("publish with haltonmissing and a missing artifact should raise an exception");
-        } catch (BuildException ex) {
-            assertTrue(ex.getMessage().contains("missing"));
-            assertTrue(ex.getMessage().contains("resolve-simple.jar"));
-            // should have do the ivy delivering
+        } 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
@@ -427,8 +433,15 @@ public class IvyPublishTest {
         }
     }
 
+    /**
+     * Expected failure: publish with haltonmissing and a missing artifact
+     *
+     * @throws IOException when copy fails
+     */
     @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);
@@ -443,12 +456,8 @@ public class IvyPublishTest {
         publish.setHaltonmissing(true);
         try {
             publish.execute();
-            fail("publish with haltonmissing and a missing artifact should raise an exception");
-        } catch (BuildException ex) {
-            assertTrue(ex.getMessage().contains("missing"));
-            assertTrue(ex.getMessage().contains("multi2.jar"));
-
-            // should have do the ivy delivering
+        } 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
@@ -456,8 +465,15 @@ public class IvyPublishTest {
         }
     }
 
+    /**
+     * Expected failure: publish with haltonmissing and a missing artifact
+     *
+     * @throws IOException when copy fails
+     */
     @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);
@@ -472,12 +488,8 @@ public class IvyPublishTest {
         publish.setHaltonmissing(true);
         try {
             publish.execute();
-            fail("publish with haltonmissing and a missing artifact should raise an exception");
-        } catch (BuildException ex) {
-            assertTrue(ex.getMessage().contains("missing"));
-            assertTrue(ex.getMessage().contains("multi2.jar"));
-
-            // should have do the ivy delivering
+        } 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
@@ -744,8 +756,8 @@ public class IvyPublishTest {
         publish.execute();
     }
 
-    @Test
-    public void testReadonly() throws Exception {
+    @Test(expected = BuildException.class)
+    public void testReadonly() throws IOException {
         project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml");
         IvyResolve res = new IvyResolve();
         res.setProject(project);
@@ -776,8 +788,7 @@ public class IvyPublishTest {
 
         try {
             publish.execute();
-            fail("by default, publish should fail when a readonly artifact already exist");
-        } catch (Exception ex) {
+        } finally {
             assertTrue(dest.exists());
             BufferedReader reader = new BufferedReader(new FileReader(dest));
             assertEquals("old version", reader.readLine());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4a806857/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java b/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
index 237f10d..f5b18af 100644
--- a/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
+++ b/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
@@ -58,7 +58,6 @@ 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.fail;
 
 public class RetrieveTest {
 
@@ -153,7 +152,7 @@ public class RetrieveTest {
         mockLogger.assertLogDoesntContain("conflict on");
     }
 
-    @Test
+    @Test(expected = RuntimeException.class)
     public void testRetrieveDifferentArtifactsOfSameModuleToSameFile() throws Exception {
         ResolveReport report = ivy.resolve(new File(
                 "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURI().toURL(),
@@ -168,11 +167,9 @@ public class RetrieveTest {
         try {
             ivy.retrieve(md.getModuleRevisionId(),
                 getRetrieveOptions().setDestArtifactPattern(pattern));
-            fail("Exception should have been thrown!");
-        } catch (RuntimeException e) {
-            // expected!
+        } finally {
+            mockLogger.assertLogDoesntContain("multiple artifacts");
         }
-        mockLogger.assertLogDoesntContain("multiple artifacts");
     }
 
     @Test