All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.internal.expectations.FailureState Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for developer (unit/integration) testing. It contains mocking APIs and other tools, supporting both JUnit and TestNG. The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested in isolation from selected dependencies.

There is a newer version: 1.7
Show newest version
/*
 * Copyright (c) 2006-2012 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.internal.expectations;

final class FailureState
{
   private final Thread testThread;
   private Error errorThrownInAnotherThread;

   /**
    * Holds an error associated to an ExpectedInvocation that is to be reported to the user.
    * 

* This field is also set if and when an unexpected invocation is detected, so that any future * invocations in this same phase execution can rethrow the original error instead of throwing a * new one, which would hide the original. * Such a situation can happen when test code or the code under test contains a "catch" or * "finally" block where a mock invocation is made after a previous such invocation in the "try" * block already failed. */ private Error errorThrown; FailureState() { testThread = Thread.currentThread(); } Error getErrorThrown() { return errorThrown; } void setErrorThrown(Error error) { errorThrown = error; } void clearErrorThrown() { errorThrown = null; } void reportErrorThrownIfAny() { if (errorThrown != null) { if (testThread == Thread.currentThread()) { throw errorThrown; } else { errorThrownInAnotherThread = errorThrown; } } } Error getErrorThrownInAnotherThreadIfAny(Error errorFromTestThread) { return errorThrownInAnotherThread == null ? errorFromTestThread : errorThrownInAnotherThread; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy