"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "junit-jupiter-migrationsupport/src/test/java/org/junit/jupiter/migrationsupport/rules/LauncherBasedEnableRuleMigrationSupportTests.java" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

LauncherBasedEnableRuleMigrationSupportTests.java  (junit5-r5.3.2):LauncherBasedEnableRuleMigrationSupportTests.java  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package org.junit.jupiter.migrationsupport.rules; package org.junit.jupiter.migrationsupport.rules;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass ; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass ;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.r equest; import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.r equest;
import org.junit.Rule; import org.junit.Rule;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.engine.JupiterTestEngine; import org.junit.platform.testkit.engine.EngineTestKit;
import org.junit.platform.engine.ExecutionRequest; import org.junit.platform.testkit.engine.Events;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.test.event.ExecutionEventRecorder;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.rules.ErrorCollector; import org.junit.rules.ErrorCollector;
import org.junit.rules.ExternalResource; import org.junit.rules.ExternalResource;
import org.junit.rules.Verifier; import org.junit.rules.Verifier;
class LauncherBasedEnableRuleMigrationSupportTests { class LauncherBasedEnableRuleMigrationSupportTests {
@Test @Test
void enableRuleMigrationSupportAnnotationWorksForBothRuleTypes() { void enableRuleMigrationSupportAnnotationWorksForBothRuleTypes() {
ExecutionEventRecorder eventRecorder = executeTestsForClass( Events tests = executeTestsForClass(EnableRuleMigrationSupportWit
EnableRuleMigrationSupportWithBothRuleTypesTestCase.class hBothRuleTypesTestCase.class);
);
assertEquals(1, eventRecorder.getTestStartedCount(), "# tests sta tests.assertStatistics(stats -> stats.started(1).succeeded(1).abo
rted"); rted(0).failed(0));
assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests
succeeded");
assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests abo
rted");
assertEquals(0, eventRecorder.getTestFailedCount(), "# tests fail
ed");
assertEquals(true, EnableRuleMigrationSupportWithBothRuleTypesTes tCase.afterOfRule1WasExecuted, assertTrue(EnableRuleMigrationSupportWithBothRuleTypesTestCase.af terOfRule1WasExecuted,
"after of rule 1 executed?"); "after of rule 1 executed?");
assertEquals(true, EnableRuleMigrationSupportWithBothRuleTypesTes tCase.beforeOfRule2WasExecuted, assertTrue(EnableRuleMigrationSupportWithBothRuleTypesTestCase.be foreOfRule2WasExecuted,
"before of rule 2 executed?"); "before of rule 2 executed?");
assertEquals(true, EnableRuleMigrationSupportWithBothRuleTypesTes tCase.afterOfRule2WasExecuted, assertTrue(EnableRuleMigrationSupportWithBothRuleTypesTestCase.af terOfRule2WasExecuted,
"before of rule 2 executed?"); "before of rule 2 executed?");
} }
@Test @Test
void verifierSupportForErrorCollectorFieldFailsTheTest() { void verifierSupportForErrorCollectorFieldFailsTheTest() {
ExecutionEventRecorder eventRecorder = executeTestsForClass(Verif ierSupportForErrorCollectorTestCase.class); Events tests = executeTestsForClass(VerifierSupportForErrorCollec torTestCase.class);
assertEquals(1, eventRecorder.getTestStartedCount(), "# tests sta tests.assertStatistics(stats -> stats.started(1).succeeded(0).abo
rted"); rted(0).failed(1));
assertEquals(0, eventRecorder.getTestSuccessfulCount(), "# tests
succeeded");
assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests abo
rted");
assertEquals(1, eventRecorder.getTestFailedCount(), "# tests fail
ed");
assertEquals(true, VerifierSupportForErrorCollectorTestCase.survi vedBothErrors, "after of rule 1 executed?"); assertTrue(VerifierSupportForErrorCollectorTestCase.survivedBothE rrors, "after of rule 1 executed?");
} }
private final JupiterTestEngine engine = new JupiterTestEngine(); private Events executeTestsForClass(Class<?> testClass) {
return EngineTestKit.execute("junit-jupiter", request().selectors
private ExecutionEventRecorder executeTestsForClass(Class<?> testClass) { (selectClass(testClass)).build()).tests();
return executeTests(request().selectors(selectClass(testClass)).b
uild());
}
private ExecutionEventRecorder executeTests(LauncherDiscoveryRequest requ
est) {
TestDescriptor testDescriptor = discoverTests(request);
ExecutionEventRecorder eventRecorder = new ExecutionEventRecorder
();
engine.execute(new ExecutionRequest(testDescriptor, eventRecorder
, request.getConfigurationParameters()));
return eventRecorder;
}
private TestDescriptor discoverTests(LauncherDiscoveryRequest request) {
return engine.discover(request, UniqueId.forEngine(engine.getId()
));
} }
@EnableRuleMigrationSupport @EnableRuleMigrationSupport
static class EnableRuleMigrationSupportWithBothRuleTypesTestCase { static class EnableRuleMigrationSupportWithBothRuleTypesTestCase {
static boolean afterOfRule1WasExecuted = false; static boolean afterOfRule1WasExecuted = false;
static boolean beforeOfRule2WasExecuted = false; static boolean beforeOfRule2WasExecuted = false;
static boolean afterOfRule2WasExecuted = false; static boolean afterOfRule2WasExecuted = false;
@Rule @Rule
public Verifier verifier1 = new Verifier() { public Verifier verifier1 = new Verifier() {
@Override @Override
protected void verify() throws Throwable { protected void verify() {
afterOfRule1WasExecuted = true; afterOfRule1WasExecuted = true;
} }
}; };
private ExternalResource resource2 = new ExternalResource() { private ExternalResource resource2 = new ExternalResource() {
@Override @Override
protected void before() throws Throwable { protected void before() {
beforeOfRule2WasExecuted = true; beforeOfRule2WasExecuted = true;
} }
@Override @Override
protected void after() { protected void after() {
afterOfRule2WasExecuted = true; afterOfRule2WasExecuted = true;
} }
}; };
@Rule @Rule
 End of changes. 14 change blocks. 
54 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)