Java: Add test for pom targeting Java 8 but rquiring Java 11

This commit is contained in:
idrissrio
2025-10-15 13:18:09 +02:00
parent 6b890eaf94
commit 5247c88da1
5 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>maven-java8-java11-dependency</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-java8-java11-dependency</name>
<description>Test case: Java 8 project with dependency requiring Java 11+</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- TestNG 7.7.0 is compiled with Java 11 (class file version 55.0) -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,4 @@
pom.xml
src/main/java/com/example/Calculator.java
src/test/java/com/example/CalculatorTest.java
target/maven-archiver/pom.properties

View File

@@ -0,0 +1,11 @@
package com.example;
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public int multiply(int a, int b) {
return a * b;
}
}

View File

@@ -0,0 +1,21 @@
package com.example;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Test class using TestNG 7.7.0 which requires Java 11+.
*/
public class CalculatorTest {
@Test
public void testAdd() {
Calculator calc = new Calculator();
Assert.assertEquals(calc.add(2, 3), 5);
}
@Test
public void testMultiply() {
Calculator calc = new Calculator();
Assert.assertEquals(calc.multiply(3, 4), 12);
}
}

View File

@@ -0,0 +1,2 @@
def test(codeql, java):
codeql.database.create()