|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectpatterntesting.exception.ExceptionFactory
public final class ExceptionFactory
This class can create for testing purpose any desired checked exception.
Implemented with the help of Thomas.Darimont@web.de (via mailing list of
aspectj-users@eclipse.org).
It is realized as Singleton to be able to extract an MBean interface for the
use via JMX.
The exceptions are controlled by AbstractTestExceptionFactory.
You will see the ExceptionFactory not before the first
method marked as @TestException has finished (because it is realized as
after advice). If you want to see it before
call ExceptionFactory.getInstance() (with the creation of
the instance it is also registered as MBean).
| Field Summary |
|---|
| Fields inherited from interface patterntesting.exception.ExceptionFactoryMBean |
|---|
ALL_CLASSES |
| Method Summary | |
|---|---|
void |
activate()
Activate. |
void |
activateOnce()
Activate once. |
void |
deactivate()
Deactivate. |
String |
getFire()
Only exceptions of this returned type will be fired. |
static ExceptionFactory |
getInstance()
It is realized as singleton because of the MBean interface. |
Throwable |
getLastProvoked()
Gets the last provoked exception. |
String |
getLimitedTo()
Deprecated. replaced by getFire() (will be removed with 1.2) |
long |
getMaxNumberOfProvoked()
Gets the maximal number of provoked exceptions (default is Long.MAX_VALUE). |
long |
getNumberOfProvoked()
Gets the number of provoked exceptions. |
String |
getScope()
Returns the scope for which the exceptions will be thrown. |
boolean |
isActive()
Checks if is active. |
boolean |
isAssertsEnabled()
To see if the (Sun) Java-VM was called with the option "-ea" ("enable asserts") this getter shows it. |
void |
provoke(Class<? extends Throwable> type)
Be careful - you can provoke any Exception with the method without the need to declare it with a throws statement. |
void |
provokeFor(JoinPoint jp)
This methods throws one of the exception which is possible for the given joinpoint. |
protected void |
provokeOneOf(Class<? extends Throwable>[] types)
This method throws the first given Throwable type. |
static void |
registerAsMBean()
Normally the ExceptionFactory register itself at JMX. |
void |
reset()
Resets all preferences and deactivates ExceptionFactory. |
void |
resetFire()
Allows again that all exceptions would be fired. |
void |
resetScope()
To set the scope back to "all classes" use this method here. |
void |
setActive(boolean active)
You can only provoke Exceptions if the active flag is set. |
void |
setFire(Class<? extends Throwable> fire)
You want to provoked an SocketException whenever it is possible? |
void |
setFire(String classname)
You want to provoked an SocketException whenever it is possible? |
void |
setLimitedTo(Class<? extends Throwable> limitedTo)
Deprecated. replaced by setFire(String) (will be removed with 1.2) |
void |
setLimitedTo(String limitedTo)
Deprecated. replaced by setFire(String) (will be removed with 1.2) |
void |
setMaxNumberOfProvoked(long n)
Limit the number of provoked maximal total number of provoked exceptions to n (default is Long.MAX_VALUE). |
void |
setScope(Class<?> target)
To limit the exception to be thrown for a given class you can use this method here. |
void |
setScope(String classname)
To limit the exception to be thrown for a given class you can use this method here. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void registerAsMBean()
throws JMException
JMException - if it can't be registerd at JMXpublic static ExceptionFactory getInstance()
public long getMaxNumberOfProvoked()
getMaxNumberOfProvoked in interface ExceptionFactoryMBeanExceptionFactoryMBean.getMaxNumberOfProvoked()public long getNumberOfProvoked()
getNumberOfProvoked in interface ExceptionFactoryMBeanExceptionFactoryMBean.getNumberOfProvoked()public void setMaxNumberOfProvoked(long n)
setMaxNumberOfProvoked in interface ExceptionFactoryMBeann - the maximal number of provoked exceptionsExceptionFactoryMBean.setMaxNumberOfProvoked(long)public boolean isActive()
isActive in interface ExceptionFactoryMBeanExceptionFactoryMBean.isActive()public void setActive(boolean active)
setActive in interface ExceptionFactoryMBeanactive - true or falseExceptionFactoryMBean.setActive(boolean)public void activate()
activate in interface ExceptionFactoryMBeanExceptionFactoryMBean.activate()public void activateOnce()
activateOnce in interface ExceptionFactoryMBeanExceptionFactoryMBean.activateOnce()public void deactivate()
deactivate in interface ExceptionFactoryMBeanExceptionFactoryMBean.deactivate()public boolean isAssertsEnabled()
isAssertsEnabled in interface ExceptionFactoryMBeanExceptionFactoryMBean.isAssertsEnabled()public Throwable getLastProvoked()
getLastProvoked in interface ExceptionFactoryMBeanExceptionFactoryMBean.getLastProvoked()public String getLimitedTo()
getFire() (will be removed with 1.2)
getLimitedTo in interface ExceptionFactoryMBeanpublic void setLimitedTo(Class<? extends Throwable> limitedTo)
setFire(String) (will be removed with 1.2)
limitedTo - the limitedTo to set (e.g. IOException.class)
public void setLimitedTo(String limitedTo)
throws ClassNotFoundException
setFire(String) (will be removed with 1.2)
setLimitedTo in interface ExceptionFactoryMBeanlimitedTo - e.g. "java.io.IOException"
ClassNotFoundException - the class not found exceptionpublic void provoke(Class<? extends Throwable> type)
provoke(IOException.class)would throw an IOException.
type - e.g. IOException.classExceptionThrower.provoke(Class)public void provokeFor(JoinPoint jp)
jp - the joinpoint for which an exception should be provokedprotected void provokeOneOf(Class<? extends Throwable>[] types)
types - a class array with exception typespublic void setScope(Class<?> target)
target - the targetExceptionFactoryMBean.setScope(java.lang.String)public void setScope(String classname)
setScope in interface ExceptionFactoryMBeanclassname - for which an exception should be thrownExceptionFactoryMBean.setScope(java.lang.String)public void resetScope()
resetScope in interface ExceptionFactoryMBeanpublic String getScope()
getScope in interface ExceptionFactoryMBeanExceptionFactoryMBean.getScope()public String getFire()
getFire in interface ExceptionFactoryMBeanExceptionFactoryMBean.getFire()
public void setFire(String classname)
throws ClassNotFoundException
setFire in interface ExceptionFactoryMBeanclassname - e.g. "java.net.SocketException"
ClassNotFoundException - if parameter is not a class nameExceptionFactoryMBean.setFire(java.lang.String)public void setFire(Class<? extends Throwable> fire)
fire - e.g. SocketException.classpublic void resetFire()
resetFire in interface ExceptionFactoryMBeanExceptionFactoryMBean.resetFire()public void reset()
reset in interface ExceptionFactoryMBeanExceptionFactoryMBean.reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||