diff --git a/exercises/build.gradle b/exercises/build.gradle index 0adf54f5e..59381df2d 100644 --- a/exercises/build.gradle +++ b/exercises/build.gradle @@ -1,87 +1,25 @@ -// This root Gradle project is used for: -// -// - Checking that every test suite compiles against its corresponding reference implementation; -// - Checking that every reference implementation passes its corresponding test suite; -// - Checking that every provided starter implementation compiles. -// -// This file is never delivered to Exercism users. - -def generatedTestSourceDir = "build/gen/test/java" - -subprojects { - - apply plugin: "checkstyle" - - // Add a task that copies test source files into a build directory. All @Ignore annotations - // are removed during this copying, so that when we run the copied tests, none are skipped and - // all should execute. - // - // Note that journey-test.sh also strips @Ignore annotations using sed. The - // stripping implementations here and in journey-test.sh should be kept - // consistent. - task copyTestsFilteringIgnores(type: Copy) { - from "src/test/java" - into generatedTestSourceDir - filter { line -> - line.contains("@Ignore") ? null : line - } - } - - afterEvaluate { project -> - // skip project named 'concept' or 'practice' - // they are only folders containing exercises - if(project.name == 'concept' || project.name == 'practice') - return; - - sourceSets { - // Set the directory containing the reference solution as the default source set. Default - // compile tasks will now run against this source set. - main { - java.srcDirs = [".meta/src/reference/java"] - } - - // Define a custom source set named "starterSource" that points to the starter implementations - // delivered to users. We can then use the generated "compileStarterSourceJava" task to verify - // that the starter source compiles as-is. - starterSource { - java.srcDirs = ["src/main/java"] - } - - // Set the directory containing the @Ignore-stripped tests as the default test source set. - // Default test tasks will now run against this source set. - test { - java.srcDirs = [generatedTestSourceDir] - } - - // Log the source paths associated with each source set to verify they are what we expect. - logCompileTaskSourcePath(project, "compileJava") // Corresponds to the "main" source set. - logCompileTaskSourcePath(project, "compileStarterSourceJava") - logCompileTaskSourcePath(project, "compileTestJava") - - } - - // configuration of the linter - checkstyle { - toolVersion '7.8.1' - configFile file("checkstyle.xml") - sourceSets = [project.sourceSets.main, project.sourceSets.test] - } - - checkstyleTest { - source = "src/test/java" - } - - // When running the standard test task, make sure we prepopulate the test source set with the - // @Ignore-stripped tests. - test.dependsOn(copyTestsFilteringIgnores) - } +apply plugin: "java" +apply plugin: "eclipse" +apply plugin: "idea" +// set default encoding to UTF-8 +compileJava.options.encoding = "UTF-8" +compileTestJava.options.encoding = "UTF-8" +repositories { + mavenCentral() +} +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' + testImplementation "org.assertj:assertj-core:3.15.0" } -def logCompileTaskSourcePath(Project project, String taskName) { - project[taskName].doFirst { compileTask -> - println " (source = ${compileTask.source.asPath})" +test { + useJUnitPlatform() + testLogging { + exceptionFormat = 'short' + showStandardStreams = true + events = ["passed", "failed", "skipped"] } } diff --git a/exercises/concept/lasagna/src/test/java/LasagnaTest.java b/exercises/concept/lasagna/src/test/java/LasagnaTest.java index ca897198a..737888f49 100644 --- a/exercises/concept/lasagna/src/test/java/LasagnaTest.java +++ b/exercises/concept/lasagna/src/test/java/LasagnaTest.java @@ -1,8 +1,9 @@ -import org.junit.Test; + +import org.junit.jupiter.api.Test; import utils.Lasagna; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; public class LasagnaTest { @@ -67,24 +68,29 @@ public void preparation_time_in_minutes_for_multiple_layers() { @Test public void implemented_total_time_in_minutes() { - assertThat(new Lasagna().hasMethod("totalTimeInMinutes", int.class, int.class)) + assertThat(new Lasagna().hasMethod("totalTimeInMinutes", int.class)) .withFailMessage("Method totalTimeInMinutes must be created") .isTrue(); - assertThat(new Lasagna().isMethodPublic("totalTimeInMinutes", int.class, int.class)) + assertThat(new Lasagna().isMethodPublic("totalTimeInMinutes", int.class)) .withFailMessage("Method totalTimeInMinutes must be public") .isTrue(); - assertThat(new Lasagna().isMethodReturnType(int.class, "totalTimeInMinutes", int.class, int.class)) + assertThat(new Lasagna().isMethodReturnType(int.class, "totalTimeInMinutes", int.class)) .withFailMessage("Method totalTimeInMinutes must return an int") .isTrue(); } @Test public void total_time_in_minutes_for_one_layer() { - assertThat(new Lasagna().totalTimeInMinutes(1, 30)).isEqualTo(32); + assertThat(new Lasagna().totalTimeInMinutes(1)).isEqualTo(42); + } + + @Test + public void total_time_in_minutes_for_three_layers() { + assertThat(new Lasagna().totalTimeInMinutes(3)).isEqualTo(46); } @Test public void total_time_in_minutes_for_multiple_layers() { - assertThat(new Lasagna().totalTimeInMinutes(4, 8)).isEqualTo(16); + assertThat(new Lasagna().totalTimeInMinutes(4)).isEqualTo(48); } } diff --git a/exercises/concept/lasagna/src/test/java/utils/Lasagna.java b/exercises/concept/lasagna/src/test/java/utils/Lasagna.java index 21e12ef63..bc92cdd96 100644 --- a/exercises/concept/lasagna/src/test/java/utils/Lasagna.java +++ b/exercises/concept/lasagna/src/test/java/utils/Lasagna.java @@ -31,11 +31,11 @@ public int preparationTimeInMinutes(int amountLayers) { } } - public int totalTimeInMinutes(int amountLayers, int actualMinutes) { + public int totalTimeInMinutes(int amountLayers) { try { - return invokeMethod("totalTimeInMinutes", new Class[]{int.class, int.class}, amountLayers, actualMinutes); + return invokeMethod("totalTimeInMinutes", new Class[]{int.class}, amountLayers); } catch (Exception e) { - throw new UnsupportedOperationException("Please implement the totalTimeInMinutes(int, int) method"); + throw new UnsupportedOperationException("Please implement the totalTimeInMinutes(int) method"); } } }