diff --git a/skippy-gradle/src/test/java/io/skippy/gradle/SkippyPluginSmokeTest.java b/skippy-gradle/src/test/java/io/skippy/gradle/SkippyPluginSmokeTest.java new file mode 100644 index 0000000..ff19095 --- /dev/null +++ b/skippy-gradle/src/test/java/io/skippy/gradle/SkippyPluginSmokeTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.skippy.gradle; + +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Functional test for the Getting Started With Gradle & JUnit 5 Tutorial. + * + * @author Florian McKee + */ +public class SkippyPluginSmokeTest { + + @Test + public void runTestsWithoutAnalysis() throws Exception { + + var buildFile = new File(getClass().getResource("skippyplugin/build.gradle").toURI()); + var projectDir = buildFile.getParentFile(); + + BuildResult result = GradleRunner.create() + .withProjectDir(projectDir) + .withPluginClasspath() + .withArguments("-b", "build-with-plugin.gradle", "clean", "build", "skippyAnalyze") + .forwardOutput() + .build(); + + var output = result.getOutput(); + + assertThat(output).contains(""" + > Task :skippyCoverage_com.example.LeftPadderTest + Capturing coverage data for com.example.LeftPadderTest in skippy/com.example.LeftPadderTest.csv + + > Task :skippyCoverage_com.example.RightPadderTest + Capturing coverage data for com.example.RightPadderTest in skippy/com.example.RightPadderTest.csv + + > Task :skippyAnalyze + Creating the Skippy analysis file skippy/analyzedFiles.txt."""); + } + +} \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build-with-plugin.gradle b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build-with-plugin.gradle new file mode 100644 index 0000000..06f8926 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build-with-plugin.gradle @@ -0,0 +1,21 @@ +plugins { + id 'io.skippy' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' +} + +test { + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + exceptionFormat "full" + } + useJUnitPlatform() +} \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build.gradle b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build.gradle new file mode 100644 index 0000000..959a53f --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' + id 'jacoco' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' +} + +test { + testLogging { + events "passed", "skipped", "failed" + showStandardStreams = true + exceptionFormat "full" + } + useJUnitPlatform() +} \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/settings.gradle b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/settings.gradle new file mode 100644 index 0000000..e69de29 diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/LeftPadder.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/LeftPadder.java new file mode 100644 index 0000000..153ad5f --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/LeftPadder.java @@ -0,0 +1,9 @@ +package com.example; + +class LeftPadder { + + static String padLeft(String input, int size) { + return StringUtils.padLeft(input, size); + } + +} \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/RightPadder.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/RightPadder.java new file mode 100644 index 0000000..aba9e63 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/RightPadder.java @@ -0,0 +1,9 @@ +package com.example; + +class RightPadder { + + static String padRight(String input, int size) { + return StringUtils.padRight(input, size); + } + +} diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/StringUtils.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/StringUtils.java new file mode 100644 index 0000000..296a3ea --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/StringUtils.java @@ -0,0 +1,24 @@ +package com.example; + +class StringUtils { + + /** + * Pads a {@index input} string on the left with blanks until the size is equal or greater to {@index size}. + */ + static String padLeft(String input, int size) { + if (input.length() < size) { + return padLeft(" " + input, size); + } + return input; + } + + /** + * Pads a {@index input} string on the right with blanks until the size is equal or greater to {@index size}. + */ + static String padRight(String input, int size) { + if (input.length() < size) { + return padRight(input + " ", size); + } + return input; + } +} diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/io/skippy/junit5/Skippy.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/io/skippy/junit5/Skippy.java new file mode 100644 index 0000000..58c0e25 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/java/io/skippy/junit5/Skippy.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.skippy.junit5; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * Decides whether a test case needs to run based on a {@link SkippyAnalysis}. + * + * @author Florian McKee + */ +public class Skippy implements ExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + return ConditionEvaluationResult.enabled(""); + } + + +} diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/resources/log4j2.properties b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/resources/log4j2.properties new file mode 100644 index 0000000..b60b190 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/resources/log4j2.properties @@ -0,0 +1,14 @@ +status = warn +name = PropertiesConfig + +appender.console.type = Console +appender.console.name = ConsoleAppender +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %-5level %logger{1.} - %msg%n + +rootLogger.level = warn +rootLogger.appenderRefs = console +rootLogger.appenderRef.console.ref = ConsoleAppender + +logger.com_example.name = io.skippy +logger.com_example.level = debug \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/LeftPadderTest.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/LeftPadderTest.java new file mode 100644 index 0000000..f6a6978 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/LeftPadderTest.java @@ -0,0 +1,18 @@ +package com.example; + +import io.skippy.junit5.Skippy; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(Skippy.class) +public class LeftPadderTest { + + @Test + void testPadLeft() { + var input = TestConstants.HELLO; + assertEquals(" hello", LeftPadder.padLeft(input, 6)); + } + +} diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/RightPadderTest.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/RightPadderTest.java new file mode 100644 index 0000000..5f33c7d --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/RightPadderTest.java @@ -0,0 +1,18 @@ +package com.example; + +import io.skippy.junit5.Skippy; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(Skippy.class) +public class RightPadderTest { + + @Test + void testPadLeft() { + var input = TestConstants.HELLO; + assertEquals("hello ", RightPadder.padRight(input, 6)); + } + +} diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/StringUtilsTest.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/StringUtilsTest.java new file mode 100644 index 0000000..ce4c63f --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/StringUtilsTest.java @@ -0,0 +1,21 @@ +package com.example; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StringUtilsTest { + + @Test + void testPadLeft() { + var input = TestConstants.HELLO; + assertEquals(" hello", StringUtils.padLeft(input, 6)); + } + + @Test + void testPadRight() { + var input = TestConstants.HELLO; + assertEquals("hello ", StringUtils.padRight(input, 6)); + } + +} \ No newline at end of file diff --git a/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/TestConstants.java b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/TestConstants.java new file mode 100644 index 0000000..e7aa929 --- /dev/null +++ b/skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/TestConstants.java @@ -0,0 +1,7 @@ +package com.example; + +class TestConstants { + + static final String HELLO = "hello"; + +} diff --git a/skippy-junit5/src/main/java/io/skippy/junit5/Skippy.java b/skippy-junit5/src/main/java/io/skippy/junit5/Skippy.java index 0f26814..deab7f6 100644 --- a/skippy-junit5/src/main/java/io/skippy/junit5/Skippy.java +++ b/skippy-junit5/src/main/java/io/skippy/junit5/Skippy.java @@ -30,6 +30,9 @@ public class Skippy implements ExecutionCondition { private final SkippyAnalysis skippyAnalysis; + /** + * Comment to make the JavaDoc task happy. + */ public Skippy() { this(SkippyAnalysis.parse()); }