ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gin...@apache.org
Subject ant-ivy git commit: another fail() that should be an expected exception; import assertions statically, too
Date Thu, 07 Dec 2017 11:26:14 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master e43138b0b -> 1b84f2ee7


another fail() that should be an expected exception;
import assertions statically, too

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

Branch: refs/heads/master
Commit: 1b84f2ee7a41e8ab12faa73130187763ee5858ea
Parents: e43138b
Author: Gintas Grigelionis <gintas@apache.org>
Authored: Thu Dec 7 12:25:55 2017 +0100
Committer: Gintas Grigelionis <gintas@apache.org>
Committed: Thu Dec 7 12:25:55 2017 +0100

----------------------------------------------------------------------
 .../IBiblioMavenSnapshotsResolutionTest.java    |  3 +-
 .../MavenTimedSnapshotVersionMatcherTest.java   | 24 +++++-----
 .../ivy/util/url/HttpclientURLHandlerTest.java  | 46 ++++++++++++--------
 3 files changed, 42 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1b84f2ee/test/java/org/apache/ivy/plugins/resolver/IBiblioMavenSnapshotsResolutionTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/resolver/IBiblioMavenSnapshotsResolutionTest.java
b/test/java/org/apache/ivy/plugins/resolver/IBiblioMavenSnapshotsResolutionTest.java
index e5374df..1917792 100644
--- a/test/java/org/apache/ivy/plugins/resolver/IBiblioMavenSnapshotsResolutionTest.java
+++ b/test/java/org/apache/ivy/plugins/resolver/IBiblioMavenSnapshotsResolutionTest.java
@@ -30,7 +30,6 @@ import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -75,7 +74,7 @@ public class IBiblioMavenSnapshotsResolutionTest {
     @Test
     public void testSnapshotResolution() throws Exception {
         final IvySettings settings = this.ivy.getSettings();
-        Assert.assertNotNull("Maven timestamped snapshot revision version matcher is absent",
+        assertNotNull("Maven timestamped snapshot revision version matcher is absent",
             settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
         final ResolveOptions resolveOptions = new ResolveOptions();
         resolveOptions.setConfs(new String[]{"default"});

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1b84f2ee/test/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcherTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcherTest.java
b/test/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcherTest.java
index 29f42a1..88b1a5e 100644
--- a/test/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcherTest.java
+++ b/test/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcherTest.java
@@ -19,9 +19,13 @@
 package org.apache.ivy.plugins.version;
 
 import org.apache.ivy.core.module.id.ModuleRevisionId;
-import org.junit.Assert;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Tests {@link MavenTimedSnapshotVersionMatcher}
  */
@@ -34,11 +38,11 @@ public class MavenTimedSnapshotVersionMatcherTest {
     public void testIsDynamic() {
         final MavenTimedSnapshotVersionMatcher versionMatcher = new MavenTimedSnapshotVersionMatcher();
         final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache",
"ant-ivy", "1.0.2-SNAPSHOT");
-        Assert.assertFalse(regularSnapshot + " wasn't expected to be a dynamic revision",
versionMatcher.isDynamic(regularSnapshot));
+        assertFalse(regularSnapshot + " wasn't expected to be a dynamic revision", versionMatcher.isDynamic(regularSnapshot));
         final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache",
"ant-ivy", "1.0.2-20100925.223013-19");
-        Assert.assertTrue(timestampedSnapshot + " was expected to be a dynamic revision",
versionMatcher.isDynamic(timestampedSnapshot));
+        assertTrue(timestampedSnapshot + " was expected to be a dynamic revision", versionMatcher.isDynamic(timestampedSnapshot));
         final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache",
"ant-ivy", "2.4.0");
-        Assert.assertFalse(exactRevision + " wasn't expected to be a dynamic revision", versionMatcher.isDynamic(exactRevision));
+        assertFalse(exactRevision + " wasn't expected to be a dynamic revision", versionMatcher.isDynamic(exactRevision));
 
     }
 
@@ -47,22 +51,22 @@ public class MavenTimedSnapshotVersionMatcherTest {
      */
     @Test
     public void testSnapshotParsing() {
-        Assert.assertNull("Revision wasn't expected to be a snapshot",
+        assertNull("Revision wasn't expected to be a snapshot",
             MavenTimedSnapshotVersionMatcher.computeIfSnapshot("1.9.9"));
 
         final String regularSnapshot = "1.9.9-SNAPSHOT";
         final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision snapshotRevision = MavenTimedSnapshotVersionMatcher.computeIfSnapshot(regularSnapshot);
-        Assert.assertNotNull(regularSnapshot + " was expected to be a snapshot", snapshotRevision);
-        Assert.assertFalse(regularSnapshot + " wasn't expected to be a timestamped snapshot",
+        assertNotNull(regularSnapshot + " was expected to be a snapshot", snapshotRevision);
+        assertFalse(regularSnapshot + " wasn't expected to be a timestamped snapshot",
             snapshotRevision.isTimestampedSnapshot());
 
         final String timestampedRev = "21.03.22-20150925.223013-232";
         final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision timestampedSnapshot
= MavenTimedSnapshotVersionMatcher.computeIfSnapshot(timestampedRev);
-        Assert.assertNotNull(timestampedRev + " was expected to be a snapshot", timestampedSnapshot);
-        Assert.assertTrue(timestampedRev + " was expected to be a timestamped snapshot",
timestampedSnapshot.isTimestampedSnapshot());
+        assertNotNull(timestampedRev + " was expected to be a snapshot", timestampedSnapshot);
+        assertTrue(timestampedRev + " was expected to be a timestamped snapshot", timestampedSnapshot.isTimestampedSnapshot());
 
         final String exactRevision = "21.2.2-a20140204.232421-2";
-        Assert.assertNull(exactRevision + " wasn't expected to be a snapshot",
+        assertNull(exactRevision + " wasn't expected to be a snapshot",
             MavenTimedSnapshotVersionMatcher.computeIfSnapshot(exactRevision));
     }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1b84f2ee/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
index b15092e..cc406dd 100644
--- a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
+++ b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java
@@ -23,9 +23,10 @@ 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.Assert;
 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;
@@ -37,9 +38,11 @@ import java.util.Collections;
 import java.util.Random;
 
 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.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * Test {@link HttpClientHandler}
@@ -57,6 +60,9 @@ public class HttpclientURLHandlerTest {
         ((NamedTimeoutConstraint) defaultTimeoutConstraint).setConnectionTimeout(5000);
     }
 
+    @Rule
+    public ExpectedException expExc = ExpectedException.none();
+
     @Before
     public void setUp() {
         testDir = new File("build/HttpclientURLHandlerTest");
@@ -77,8 +83,10 @@ public class HttpclientURLHandlerTest {
 
     @Test
     public void testIsReachable() throws Exception {
-        assertTrue("URL resource was expected to be reachable", handler.isReachable(new URL("http://www.google.fr/"),
defaultTimeoutConstraint));
-        assertFalse("URL resource was expected to be unreachable", handler.isReachable(new
URL("http://www.google.fr/unknownpage.html"), defaultTimeoutConstraint));
+        assertTrue("URL resource was expected to be reachable",
+                handler.isReachable(new URL("http://www.google.fr/"), defaultTimeoutConstraint));
+        assertFalse("URL resource was expected to be unreachable",
+                handler.isReachable(new URL("http://www.google.fr/unknownpage.html"), defaultTimeoutConstraint));
     }
 
     /**
@@ -91,8 +99,9 @@ public class HttpclientURLHandlerTest {
     @Test
     public void testGetURLInfo() throws Exception {
         URLHandler handler = new HttpClientHandler();
+        assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
         URLInfo info = handler.getURLInfo(new URL(DEFAULT_M2_ROOT
-                + "/commons-lang/commons-lang/[1.0,3.0[/commons-lang-[1.0,3.0[.pom"), defaultTimeoutConstraint);
+                + "commons-lang/commons-lang/[1.0,3.0[/commons-lang-[1.0,3.0[.pom"), defaultTimeoutConstraint);
 
         assertEquals(URLHandler.UNAVAILABLE, info);
     }
@@ -126,6 +135,13 @@ public class HttpclientURLHandlerTest {
      */
     @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";
@@ -138,8 +154,8 @@ public class HttpclientURLHandlerTest {
         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,
contextRoot,
-                repoRoot, realm, Collections.singletonMap(userName, password))) {
+        try (final AutoCloseable server = TestHelper.createBasicAuthHttpServerBackedRepo(serverBindAddr,
+                contextRoot, repoRoot, realm, Collections.singletonMap(userName, password)))
{
 
             final File target = new File(testDir, "downloaded.xml");
             assertFalse("File " + target + " already exists", target.exists());
@@ -152,30 +168,22 @@ public class HttpclientURLHandlerTest {
         // 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,
contextRoot,
-                repoRoot, realm, Collections.singletonMap("other-" + userName, "other-" +
password))) {
+        try (final 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");
             assertFalse("File " + target + " already exists", target.exists());
             final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/"
                     + contextRoot + "/ivysettings.xml");
             // download it (expected to fail)
-            try {
-                handler.download(src, target, null, defaultTimeoutConstraint);
-                Assert.fail("Download from " + src + " was expected to fail due to invalid
credentials");
-            } catch (IOException ioe) {
-                // 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("Expected to find 401 error message in exception", ioe.getMessage().contains("401"));
-            }
+            handler.download(src, target, null, defaultTimeoutConstraint);
         }
     }
 
     private void assertDownloadOK(final URL url, final File file) throws Exception {
         handler.download(url, file, null, defaultTimeoutConstraint);
         assertTrue("Content from " + url + " wasn't downloaded to " + file, file.exists());
-        assertTrue("Unexpected content at " + file + " for resource that was downloaded from
" + url, file.isFile() && file.length() > 0);
+        assertTrue("Unexpected content at " + file + " for resource that was downloaded from
"
+                + url, file.isFile() && file.length() > 0);
     }
 }


Mime
View raw message