Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-07-24 05:36:31+0000
Modified:
   dba/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java

Log:
 #i76128# +verifyExpectedException

File Changes:

Directory: /dba/dbaccess/qa/complex/dbaccess/
=============================================

File [changed]: CRMBasedTestCase.java
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java?r1=1.1.6.2&r2=1.1.6.3
Delta lines:  +44 -1
--------------------
--- CRMBasedTestCase.java       2008-07-23 13:07:41+0000        1.1.6.2
+++ CRMBasedTestCase.java       2008-07-24 05:36:29+0000        1.1.6.3
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: CRMBasedTestCase.java,v $
- * $Revision: 1.1.6.2 $
+ * $Revision: 1.1.6.3 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -32,6 +32,8 @@
 import com.sun.star.lang.XMultiServiceFactory;
 import com.sun.star.sdb.XSingleSelectQueryComposer;
 import com.sun.star.uno.UnoRuntime;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -79,6 +81,47 @@
         }
     }
 
+    // 
--------------------------------------------------------------------------------------------------------
+    protected void verifyExpectedException( Object _object, Class 
_unoInterfaceClass, String _methodName, Object[] _methodArgs,
+        Class _expectedExceptionClass )
+    {
+        verifyExpectedException( UnoRuntime.queryInterface( 
_unoInterfaceClass, _object ), _methodName,
+            _methodArgs, _expectedExceptionClass );
+    }
+
+    // 
--------------------------------------------------------------------------------------------------------
+    protected void verifyExpectedException( Object _object, String 
_methodName, Object[] _methodArgs,
+        Class _expectedExceptionClass )
+    {
+        Class objectClass = _object.getClass();
+        Class[] methodArgsClasses = new Class[ _methodArgs.length ];
+        for ( int i=0; i<_methodArgs.length; ++i )
+            methodArgsClasses[i] = _methodArgs[i].getClass();
+
+        boolean noExceptionAllowed = _expectedExceptionClass == null;
+
+        boolean caughtExpected = noExceptionAllowed ? true : false;
+        try
+        {
+            Method method = objectClass.getMethod( _methodName, 
methodArgsClasses );
+            method.invoke(_object, _methodArgs );
+        }
+        catch ( InvocationTargetException e )
+        {
+            caughtExpected =    noExceptionAllowed
+                            ?   false
+                            :   ( e.getTargetException().getClass().equals( 
_expectedExceptionClass ) );
+        }
+        catch( Exception e )
+        {
+            caughtExpected = false;
+        }
+        assure( "did not catch the expected exception (" +
+                ( noExceptionAllowed ? "none" : 
_expectedExceptionClass.getName() ) +
+                ") while calling " + _object.getClass().getName() + "." + 
_methodName, caughtExpected );
+    }
+
+    // 
--------------------------------------------------------------------------------------------------------
     /** creates a SingleSelectQueryComposer for our connection
      */
     protected final XSingleSelectQueryComposer createQueryComposer() throws 
com.sun.star.uno.Exception




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to