From d7ab9b548039d0ae1a8ddeaad403b561a8c8072a Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 8 Apr 2015 10:32:40 +0000 Subject: [PATCH] Rename ExceptionUtils.intercept to expectedException. +review RM-10 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@101338 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../test/util/ExceptionUtils.java | 12 ++++++------ .../util/ExceptionUtilsUsageExamplesTest.java | 16 ++++++++-------- .../util/RMParameterCheckTest.java | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtils.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtils.java index 7a0ea4041a..5cbbf524e1 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtils.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtils.java @@ -81,13 +81,13 @@ public class ExceptionUtils *
  • * Calling a local method which throws a {@code RuntimeException}. (An expression lambda) *
    -     * intercept(RuntimeException.class, () -> badMethod() );
    +     * expectedException(RuntimeException.class, () -> badMethod() );
          *         
    *
  • *
  • * Executing a block of code. (Requires return statement) *
    -     * intercept(RuntimeException.class, () -> {
    +     * expectedException(RuntimeException.class, () -> {
          *   for (int i = 0; i < 10; i++) {
          *     goodMethod();
          *   }
    @@ -99,7 +99,7 @@ public class ExceptionUtils
          *     
  • * Examining the expected exception e.g. to assert the root cause is correct. *
    -     * UnsupportedOperationException e = intercept(UnsupportedOperationException.class, () -> badMethod2() );
    +     * UnsupportedOperationException e = expectedException(UnsupportedOperationException.class, () -> badMethod2() );
          * assertEquals(RuntimeException.class, e.getCause().getClass());
          *         
    *
  • @@ -107,8 +107,8 @@ public class ExceptionUtils * Note that if your lambda expression returns 'void' then you cannot use an expression * and must explicitly return null from a lambda block. *
    -     * intercept(Exception.class, () -> { methodReturningVoid(); return null; } );
    -     * intercept(Exception.class, () -> { methodReturningVoid("parameter"); return null; } );
    +     * expectedException(Exception.class, () -> { methodReturningVoid(); return null; } );
    +     * expectedException(Exception.class, () -> { methodReturningVoid("parameter"); return null; } );
          *         
    *
  • * @@ -121,7 +121,7 @@ public class ExceptionUtils * @throws UnexpectedThrowableException if a non-matching throwable was thrown out of the code block. * @throws MissingThrowableException if the expected throwable was not thrown out of the code block. */ - public static T intercept(final Class expected, final Supplier code) + public static T expectedException(final Class expected, final Supplier code) { // The code block may throw an exception or it may not. Optional maybeThrownByCode; diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtilsUsageExamplesTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtilsUsageExamplesTest.java index e69a07431a..a7f4592a4a 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtilsUsageExamplesTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExceptionUtilsUsageExamplesTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import java.io.IOException; -import static org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils.intercept; +import static org.alfresco.module.org_alfresco_module_rm.test.util.ExceptionUtils.expectedException; import static org.junit.Assert.*; /** @@ -44,10 +44,10 @@ public class ExceptionUtilsUsageExamplesTest @Test public void swallowExpectedExceptions() { // Calling a local method. (An expression lambda) - intercept(RuntimeException.class, () -> badMethod1() ); + expectedException(RuntimeException.class, () -> badMethod1() ); // Executing a block of code. (Requires return statement) - intercept(RuntimeException.class, () -> + expectedException(RuntimeException.class, () -> { for (int i = 0; i < 10; i++) { goodMethod(); @@ -60,14 +60,14 @@ public class ExceptionUtilsUsageExamplesTest @Test public void examineTheExpectedException() { - UnsupportedOperationException e = intercept(UnsupportedOperationException.class, () -> badMethod2() ); + UnsupportedOperationException e = expectedException(UnsupportedOperationException.class, () -> badMethod2() ); assertEquals(RuntimeException.class, e.getCause().getClass()); } @Test(expected=MissingThrowableException.class) public void expectedExceptionNotThrown() { - intercept(IOException.class, () -> + expectedException(IOException.class, () -> { // Do nothing return null; @@ -77,7 +77,7 @@ public class ExceptionUtilsUsageExamplesTest @Test(expected=UnexpectedThrowableException.class) public void unexpectedExceptionThrown() { - intercept(IOException.class, () -> + expectedException(IOException.class, () -> { throw new UnsupportedOperationException(); }); @@ -90,12 +90,12 @@ public class ExceptionUtilsUsageExamplesTest // If you use lambdas that return void, then they cannot be lambda expressions. They must be blocks. @Test public void usingVoidLambdas() { - intercept(IllegalStateException.class, () -> { + expectedException(IllegalStateException.class, () -> { onlySideEffectsHere(); return null; }); - intercept(IllegalStateException.class, () -> { + expectedException(IllegalStateException.class, () -> { onlySideEffectsHere("hello"); return null; }); diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMParameterCheckTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMParameterCheckTest.java index 3db859b19c..bf5e872939 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMParameterCheckTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/RMParameterCheckTest.java @@ -33,19 +33,19 @@ public class RMParameterCheckTest public void checkNotBlank() { // Check that supplying null causes an exception. - ExceptionUtils.intercept(IllegalArgumentException.class, () -> { + ExceptionUtils.expectedException(IllegalArgumentException.class, () -> { RMParameterCheck.checkNotBlank("name", null); return null; }); // Check that supplying an empty string causes an exception. - ExceptionUtils.intercept(IllegalArgumentException.class, () -> { + ExceptionUtils.expectedException(IllegalArgumentException.class, () -> { RMParameterCheck.checkNotBlank("name", ""); return null; }); // Check that supplying a whitespace only string causes an exception. - ExceptionUtils.intercept(IllegalArgumentException.class, () -> { + ExceptionUtils.expectedException(IllegalArgumentException.class, () -> { RMParameterCheck.checkNotBlank("name", "\n\r \t"); return null; });