This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 501240a  Tests.
501240a is described below

commit 501240a025fb03a99a585713159b5c1c0936eb71
Author: JamesBognar <[email protected]>
AuthorDate: Fri Jun 26 12:18:38 2020 -0400

    Tests.
---
 .../juneau/assertions/ThrowableAssertion.java      |  4 +-
 .../rest/test/client/ThirdPartyProxyTest.java      | 15 ++------
 .../apache/juneau/rest/StaticFilesMappingTest.java | 43 +++-------------------
 .../org/apache/juneau/rest/util/RestUtilsTest.java | 21 +++--------
 4 files changed, 16 insertions(+), 67 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ThrowableAssertion.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ThrowableAssertion.java
index 080cc8f..ce4203c 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ThrowableAssertion.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ThrowableAssertion.java
@@ -55,10 +55,10 @@ public class ThrowableAssertion extends 
FluentThrowableAssertion<ThrowableAssert
        public static ThrowableAssertion assertThrown(Callable<Object> 
callable) {
                try {
                        callable.call();
-                       throw new BasicAssertionError("Exception not thrown.");
-               } catch (Exception e) {
+               } catch (Throwable e) {
                        return assertThrowable(e);
                }
+               throw new BasicAssertionError("Exception not thrown.");
        }
 
        /**
diff --git 
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/ThirdPartyProxyTest.java
 
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/ThirdPartyProxyTest.java
index 7ecf185..e28eb22 100644
--- 
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/ThirdPartyProxyTest.java
+++ 
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/ThirdPartyProxyTest.java
@@ -13,6 +13,7 @@
 package org.apache.juneau.rest.test.client;
 
 import static org.apache.juneau.assertions.ObjectAssertion.*;
+import static org.apache.juneau.assertions.ThrowableAssertion.*;
 import static org.apache.juneau.rest.testutils.Constants.*;
 import static org.junit.Assert.*;
 import static org.junit.Assert.assertEquals;
@@ -861,12 +862,7 @@ public class ThirdPartyProxyTest extends RestTestcase {
 
        @Test
        public void ea02_setWrongInt() {
-               try {
-                       proxy.setInt(2);
-                       fail();
-               } catch (AssertionError e) { // AssertionError thrown on server 
side.
-                       assertEquals("expected:<1> but was:<2>", 
e.getMessage());
-               }
+               assertThrown(()->{proxy.setInt(2); return 
null;}).contains("expected:<1> but was:<2>");
        }
 
        @Test
@@ -901,12 +897,7 @@ public class ThirdPartyProxyTest extends RestTestcase {
 
        @Test
        public void ea09_setNullStringBad() {
-               try {
-                       proxy.setNullString("foo");
-                       fail();
-               } catch (AssertionError e) { // AssertionError thrown on server 
side.
-                       assertEquals("expected null, but was:<foo>", 
e.getLocalizedMessage());
-               }
+               assertThrown(()->{proxy.setNullString("foo");return 
null;}).contains("expected null, but was:<foo>");
        }
 
        @Test
diff --git 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/StaticFilesMappingTest.java
 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/StaticFilesMappingTest.java
index b26cd1e..13956c4 100644
--- 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/StaticFilesMappingTest.java
+++ 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/StaticFilesMappingTest.java
@@ -14,7 +14,6 @@ package org.apache.juneau.rest;
 
 import static org.apache.juneau.assertions.ObjectAssertion.*;
 import static org.apache.juneau.assertions.ThrowableAssertion.*;
-import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
 
 import java.util.*;
@@ -142,61 +141,31 @@ public class StaticFilesMappingTest {
 
        @Test
        public void d01_error_malformedJson() {
-               try {
-                       parse("foo:bar:xxx");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Expected { at beginning of 
headers.");
-               }
+               assertThrown(()->{return 
parse("foo:bar:xxx");}).contains("Expected { at beginning of headers.");
        }
 
        @Test
        public void d02_error_textFollowingJson() {
-               try {
-                       parse("foo:bar:{a:'b'}x");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Invalid text following 
headers.");
-               }
+               assertThrown(()->{return 
parse("foo:bar:{a:'b'}x");}).contains("Invalid text following headers.");
        }
 
        @Test
        public void d03_error_missingLocation() {
-               try {
-                       parse("foo");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Couldn't find ':' 
following path.");
-               }
+               assertThrown(()->{return parse("foo");}).contains("Couldn't 
find ':' following path.");
        }
 
        @Test
        public void d04_error_danglingColonAfterLocation() {
-               try {
-                       parse("foo:bar:");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Found extra ':' following 
location.");
-               }
+               assertThrown(()->{return parse("foo:bar:");}).contains("Found 
extra ':' following location.");
        }
 
        @Test
        public void d05_error_malformedHeaders_openEnded() {
-               try {
-                       parse("foo:bar:{");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Malformed headers.");
-               }
+               assertThrown(()->{return 
parse("foo:bar:{");}).contains("Malformed headers.");
        }
 
        @Test
        public void d06_error_malformedHeaders_mismatchedBrackets() {
-               try {
-                       parse("foo:bar:{{}");
-                       fail();
-               } catch (ParseException e) {
-                       assertThrowable(e).contains("Malformed headers.");
-               }
+               assertThrown(()->{return 
parse("foo:bar:{{}");}).contains("Malformed headers.");
        }
 }
diff --git 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/util/RestUtilsTest.java
 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/util/RestUtilsTest.java
index 673890a..583c36e 100644
--- 
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/util/RestUtilsTest.java
+++ 
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/util/RestUtilsTest.java
@@ -13,6 +13,7 @@
 package org.apache.juneau.rest.util;
 
 import static org.apache.juneau.assertions.ObjectAssertion.*;
+import static org.apache.juneau.assertions.ThrowableAssertion.*;
 import static org.apache.juneau.internal.StringUtils.*;
 import static org.apache.juneau.rest.util.RestUtils.*;
 import static org.junit.Assert.*;
@@ -70,10 +71,7 @@ public class RestUtilsTest {
 
                for (String s : new String[]{
                                "http:/hostname?foo"}) {
-                       try {
-                               trimPathInfo(new StringBuffer(s), cp, sp);
-                               fail("Exception expected - " + s);
-                       } catch (RuntimeException ex) {}
+                       assertThrown(()->{return trimPathInfo(new 
StringBuffer(s), "", "");});
                }
 
                e = "http://hostname";;
@@ -103,10 +101,7 @@ public class RestUtilsTest {
                                "http://hostname?foo";,
                                "http://hostname/fo?bar";,
                                "http:/hostname/foo"}) {
-                       try {
-                               trimPathInfo(new StringBuffer(s), cp, sp);
-                               fail("Exception expected - " + s);
-                       } catch (RuntimeException ex) {}
+                       assertThrown(()->{return trimPathInfo(new 
StringBuffer(s), "/", "/foo");});
                }
 
                e = "http://hostname/foo/bar";;
@@ -123,10 +118,7 @@ public class RestUtilsTest {
                                "http://hostname/foo2/bar";,
                                "http://hostname/foo/bar2";
                        }) {
-                       try {
-                               trimPathInfo(new StringBuffer(s), cp, sp);
-                               fail("Exception expected - " + s);
-                       } catch (RuntimeException ex) {}
+                       assertThrown(()->{return trimPathInfo(new 
StringBuffer(s), "/foo/bar", "/foo/bar");});
                }
 
                e = "http://hostname/foo/bar";;
@@ -143,10 +135,7 @@ public class RestUtilsTest {
                                "http://hostname/foo2/bar";,
                                "http://hostname/foo/bar2";
                        }) {
-                       try {
-                               trimPathInfo(new StringBuffer(s), cp, sp);
-                               fail("Exception expected - " + s);
-                       } catch (RuntimeException ex) {}
+                       assertThrown(()->{return trimPathInfo(new 
StringBuffer(s), "/foo", "/bar");});
                }
        }
 

Reply via email to