From 5dd2c38bbc0ee0088a9e08d1d322d763a99ce139 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Thu, 21 Mar 2024 16:52:35 +0100 Subject: [PATCH] [chore] Ignore unit test regarding compiler options for Java verisons > 17 --- .../java/io/toolisticon/cute/CuteTest.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index 36ba598..b799629 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -77,7 +77,7 @@ public void test_UnitTest_successfulCompilation_build() { } @Test - public void test_compilationWithCompilerOptions_happyPath (){ + public void test_compilationWithCompilerOptions_happyPath() { Cute.blackBoxTest().given().noProcessors() .andSourceFiles("/compiletests/compileroptionstest/Java8Code.java") .andUseCompilerOptions("-source 1.8", "-target 1.8") @@ -87,25 +87,40 @@ public void test_compilationWithCompilerOptions_happyPath (){ } @Test - public void test_compilationWithCompilerOptions_invalidUsageOfJava8Code (){ - Cute.blackBoxTest().given().noProcessors() - .andSourceFiles("/compiletests/compileroptionstest/Java8Code.java") - .andUseCompilerOptions("-source 1.7", "-target 1.7") - .whenCompiled().thenExpectThat().compilationFails() - .andThat().compilerMessage().ofKindError().atSource("/compiletests/compileroptionstest/Java8Code.java").atLine(10).atColumn(56).contains("lambda expressions are not supported") - .andThat().generatedClass("io.toolisticon.cute.testcases.Java8Code").doesntExist() - .executeTest(); + public void test_compilationWithCompilerOptions_invalidUsageOfJava8Code() { + if (getJavaVersion() <= 17) { + Cute.blackBoxTest().given().noProcessors() + .andSourceFiles("/compiletests/compileroptionstest/Java8Code.java") + .andUseCompilerOptions("-source 1.7", "-target 1.7") + .whenCompiled().thenExpectThat().compilationFails() + .andThat().compilerMessage().ofKindError().atSource("/compiletests/compileroptionstest/Java8Code.java").atLine(10).atColumn(56).contains("lambda expressions are not supported") + .andThat().generatedClass("io.toolisticon.cute.testcases.Java8Code").doesntExist() + .executeTest(); + } } + private static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + } + return Integer.parseInt(version); + } + @Test - public void test_addSourceFromString(){ - Cute.blackBoxTest().given() - .noProcessors() - .andSourceFile("io.toolisticon.cute.Testclass","package io.toolisticon.cute; public class Testclass{}") - .whenCompiled().thenExpectThat().compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.Testclass").exists() - .executeTest(); + public void test_addSourceFromString() { + Cute.blackBoxTest().given() + .noProcessors() + .andSourceFile("io.toolisticon.cute.Testclass", "package io.toolisticon.cute; public class Testclass{}") + .whenCompiled().thenExpectThat().compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.Testclass").exists() + .executeTest(); }