What's the meaning of Proctectable interface in JUnit source code?

What's the meaning of Proctectable interface in JUnit source code?

what'd
what w
whatsapp app
what c
what p
what h
how to pronounce what
whatsapp login

I'm recently digging into the source code of JUnit-4.11, what confuse me is that the seemingly redundant Protectable interface. the declaration is as follows:

public interface Protectable {
    public abstract void protect() throws Throwable;
}

In the TestResult class, there is a void run(final TestCase test) method, in which a anonymous Protectable instance is realized as follows:

protected void run(final TestCase test) {
    startTest(test);
    Protectable p = new Protectable() {
        public void protect() throws Throwable {
           test.runBare();
        }
    };
    runProtected(test, p);

    endTest(test);
}

runProtected method is as follows:

public void runProtected(final Test test, Protectable p) {
    try {
        p.protect();
    } catch (AssertionFailedError e) {
       addFailure(test, e);
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
        throw e;
    } catch (Throwable e) {
        addError(test, e);
    }
}

As we can see, what runProtected does is just executing test.runBare();, so is there any sense to the existence of Protectable interface? Why can't we just write code like below.

protected void run(final TestCase test) {
    startTest(test);
    test.runBare();
    endTest(test);
}

To answer your final question first, you can't use

protected void run(final TestCase test) {
    startTest(test);
    test.runBare();
    endTest(test);
}

because it won't do what you want. JUnit manages asserts using exceptions, specifically AssertionFailedError. So, Assert.assertEquals() throws an AssertionFailedError when the two values aren't equal. So, in the above method, the endTest(test) won't get called if there is an assertion failure, which means the correct events (failure/error of the test) won't get fired, and tearDown() won't get executed.

The Protectable interface is there to give a more generic interface to the runner, so that you don't have to hand a TestCase to the method, to allow different actions.

As an aside, this is part of the package junit.framework.*, which is JUnit 3. JUnit 4 is where it's at, and if you want to learn, look more in the org.junit.* packages.

What, I will do what I can to help you. TranslationsEdit. show ▽what? (interrogative pronoun)  Quickly send and receive WhatsApp messages right from your computer. Quickly send and receive WhatsApp messages right from your computer. Quickly send and receive WhatsApp messages right from your computer. WhatsApp Web. To use WhatsApp on your computer: Open WhatsApp on your phone;


It seems to handle thrown exceptions in specific way : Call addFailure for assertion exception (your test failed), addError for other exception (your test is not well coded)

Drake - Nice For What, Quickly send and receive WhatsApp messages right from your computer. noun the true nature or identity of something, or the sum of its characteristics: a lecture on the whats and hows of crop rotation.


This interface is to protect the TestCase by adding Throwable. so junit could run any testcase safely.

The Throwable class is the superclass of all errors and exceptions in the Java language.

what, what meaning: 1. used to ask for information about people or things: 2. used in questions that show you are…. Learn more. informal a punishment or reprimand (esp in the phrase give (a person) what for) 7. what have you someone, something, or somewhere unknown or unspecified: cars, motorcycles, or what have you. 8.


WhatsApp Web, Covid-19 continues to awkwardly expose the weird morality of American capitalism, where it's OK for companies to swarm for government help  WhatsApp Messenger: More than 2 billion people in over 180 countries use WhatsApp to stay in touch with friends and family, anytime and anywhere. WhatsApp is free and offers simple, secure, reliable messaging and calling, available on phones all over the world.


WHAT, What You Get for $700,000. Advertisement. Continue reading the main story. Slide 1 of 24,. In Long Beach, a two-bedroom, one-bathroom  In current usage that refers to persons or things, which chiefly to things and rarely to subhuman entities, who chiefly to persons and sometimes to animals. The notion that that should not be used to refer to persons is without foundation; such use is entirely standard.


What Matters: This is what coronavirus capitalism looks like , What happens when a film critic loses the will to watch movies? Our writer settles for cookery shows, half-hearted group-watches – and the  This is the ORIGINAL "What What (In the Butt)" video. The South Park version aired over a year after we made this video. There's been a lot of confusion about this. We can assure you, we are not