T
- type of the subject or delegate to create a proxy forpublic final class ThrowableRecorderProxy<T> extends Object implements Proxy<T>
errors
are thrown in the context
of a different thread.
Note: This proxy does not hide problems, the errors are recorded but they still are thrown.
One application if this class is in unit test in multi-threading environments:
If expectations (like listener notifications) are carried out in a different thread then mocking has the following implications:
This class is used to to solve the first problem: "The test does not fail if an exception happens in a different thread".
Note that if the thread scheduling is controlled (A thread pool is used to
submit or schedule a thread) then a Future
could be used to get the
exception in the context of the calling thread. This class should be used
in integration test where threads cannot be controlled: For example when a
framework is used and such framework notifies listener in a different
thread and the notifications need to be asserted in the test.
Another application of this class could be logging the errors if the thread were this are thrown does not catch them. Otherwise they will just appear in the console.
DynamicProxy
Constructor and Description |
---|
ThrowableRecorderProxy() |
Modifier and Type | Method and Description |
---|---|
List<Throwable> |
getRecords()
Returns the
throwables that has been thrown. |
Object |
invoke(T subject,
Method method,
Object[] args)
Processes a method invocation on a proxy instance and returns the
result.
|
List<Throwable> |
popRecords()
Clears and returns the
throwables that has been
thrown. |
void |
verify()
Verifies no
errors were thrown. |
public Object invoke(T subject, Method method, Object[] args) throws Throwable
Proxy
public List<Throwable> getRecords()
throwables
that has been thrown.public List<Throwable> popRecords()
throwables
that has been
thrown.Copyright © 2015. All Rights Reserved.