-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compose support of method and field support
The ExternalResourceSupport is now composed of the two separately implemented support classes for method and field support, respectively. Includes a test to verify the relative order of both cases. #433
- Loading branch information
Matthias Merdes
authored and
Matthias Merdes
committed
Sep 1, 2016
1 parent
96e2592
commit dc141ea
Showing
2 changed files
with
99 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...r/engine/vintage/rulesupport/ExternalResourceSupportForMixedMethodAndFieldRulesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.jupiter.engine.vintage.rulesupport; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.Rule; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.rules.ExternalResource; | ||
|
||
@ExtendWith(ExternalResourceSupport.class) | ||
public class ExternalResourceSupportForMixedMethodAndFieldRulesTests { | ||
|
||
private static boolean beforeOfRule1WasExecuted = false; | ||
private static boolean beforeOfRule2WasExecuted = false; | ||
|
||
private static boolean afterOfRule1WasExecuted = false; | ||
private static boolean afterOfRule2WasExecuted = false; | ||
|
||
private List<String> executions = new ArrayList<String>(); | ||
|
||
@Rule | ||
public ExternalResource resource1 = new ExternalResource() { | ||
@Override | ||
protected void before() throws Throwable { | ||
beforeOfRule1WasExecuted = true; | ||
executions.add("field"); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
afterOfRule1WasExecuted = true; | ||
} | ||
}; | ||
|
||
private ExternalResource resource2 = new ExternalResource() { | ||
@Override | ||
protected void before() throws Throwable { | ||
beforeOfRule2WasExecuted = true; | ||
executions.add("method"); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
afterOfRule2WasExecuted = true; | ||
} | ||
}; | ||
|
||
@Rule | ||
public ExternalResource getResource2() { | ||
return resource2; | ||
} | ||
|
||
@Test | ||
void beforeMethodsOfBothRulesWereExecuted() { | ||
assert beforeOfRule1WasExecuted; | ||
assert beforeOfRule2WasExecuted; | ||
} | ||
|
||
@Test | ||
void fieldRuleWasExecutedBeforeMethodRule() { | ||
assertEquals(Arrays.asList("field", "method"), this.executions); | ||
} | ||
|
||
@AfterAll | ||
static void afterMethodsOfBothRulesWereExecuted() { | ||
if (!afterOfRule1WasExecuted) | ||
fail(); | ||
if (!afterOfRule2WasExecuted) | ||
fail(); | ||
} | ||
|
||
static void fail() { | ||
//hack: use this blacklisted exception to fail the build, all others would be swallowed... | ||
throw new OutOfMemoryError("a postcondition was violated"); | ||
} | ||
|
||
} |