Skip to content

Commit

Permalink
Skip builds also when test class is disabled via JUnit annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbliznak authored and mnovak1 committed Aug 25, 2022
1 parent 70d3bec commit 20d3afe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.junit.jupiter.api.Disabled;
import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.support.descriptor.ClassSource;
import org.junit.platform.launcher.TestExecutionListener;
Expand Down Expand Up @@ -169,11 +170,12 @@ private void process(List<BuildDefinition> buildsToBeBuilt, Set<BuildDefinition>
}

static boolean shouldSkipBuildsForClass(Class<?> klass) {
boolean classDisabled = Arrays.stream(klass.getAnnotationsByType(Disabled.class)).findAny().isPresent();
boolean classSkippedForStream = Arrays.stream(klass.getAnnotationsByType(SkipFor.class))
.anyMatch(a -> SkipForCondition.resolve(a).isDisabled());
boolean classSkippedForTestedVersion = Arrays.stream(klass.getAnnotationsByType(SinceVersion.class))
.anyMatch(a -> SinceVersionCondition.resolve(a).isDisabled());

return classSkippedForStream || classSkippedForTestedVersion;
return classDisabled || classSkippedForStream || classSkippedForTestedVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

Expand Down Expand Up @@ -59,6 +60,11 @@ public void buildFromClassWithHighEnoughVersionIsNotSkipped() {
.isFalse();
}

@Test
public void buildFromDisabledClassIsSkipped() {
Assertions.assertThat(ManagedBuildPrebuilder.shouldSkipBuildsForClass(TestClassDisabledTest.class)).isTrue();
}

@Test
public void buildFromClassMatchingAllSkipConditionsIsSkipped() {
Assertions.assertThat(ManagedBuildPrebuilder.shouldSkipBuildsForClass(TestClassSkippedByAllConditionsTest.class))
Expand All @@ -80,8 +86,14 @@ static class TestClassSkippedForImageTest {
static class TestClassSkippedForLowerVersionTest {
}

@Disabled("Some reason given")
@UsesTestBuild(TestBuilds.testBuild)
static class TestClassDisabledTest {
}

@SkipFor(image = "eap", name = "wildfly-s2i-jdk11", reason = "This test is skipped based on the image name.")
@SinceVersion(image = "eap", name = "wildfly-s2i-jdk11", since = "27.0", jira = "JIRA-1234")
@Disabled("Some reason given")
@UsesTestBuild(TestBuilds.testBuild)
static class TestClassSkippedByAllConditionsTest {
}
Expand Down

0 comments on commit 20d3afe

Please sign in to comment.