Skip to content

Commit

Permalink
[SUREFIRE-2190] Integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
hgschmie committed Aug 20, 2023
1 parent 229ba28 commit e367888
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 org.apache.maven.surefire.its.jiras;

import org.apache.maven.surefire.its.fixture.AbstractJava9PlusIT;
import org.apache.maven.surefire.its.fixture.OutputValidator;
import org.junit.Test;

/**
* Integration test for <a href="https://issues.apache.org/jira/browse/SUREFIRE-2190">SUREFIRE-2190</a>.
*/
public class Surefire2190JUnitIT extends AbstractJava9PlusIT {
@Test
public void test() throws Exception {
OutputValidator validator = assumeJava9().debugLogging().executeVerify().assertTestSuiteResults(4, 0, 0, 0);

// OutputValidator validator = unpack("surefire-2190", "-" + jupiter)
// .setTestToRun("MainTest")
// .sysProp("junit5.version", jupiter)
// .maven()
// .withFailure()
// .executeTest()
// .verifyTextInLog("MainTest.testNulLSupplierWithoutNullable")
// .assertTestSuiteResults(1, 0, 1, 0);

// validator
// .getSurefireReportsFile("jira1748.AssertionsFailEmptyStringParameterJupiterTest.txt", UTF_8)
// .assertContainsText(
//
// "AssertionsFailEmptyStringParameterJupiterTest.doTest(AssertionsFailEmptyStringParameterJupiterTest");
}

@Override
protected String getProjectDirectoryName() {
return "surefire-2190";
}
}
68 changes: 68 additions & 0 deletions surefire-its/src/test/resources/surefire-2190/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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
~
~ http://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.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>surefire-2190-it</artifactId>
<version>1.0</version>

<properties>
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module surefire.bug.thing3 {
requires static jakarta.annotation;

exports surefirebug.thing;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package surefirebug.thing;

import java.util.concurrent.Callable;
import java.util.function.Supplier;

public final class Main implements Callable<String> {

private static final Supplier<String> DEFAULT_PROVIDER = () -> "Hello, World";


public static void main(String... args) throws Exception {
Main main = new Main();
String text = main.call();

System.out.println(text);
}

private final Supplier<String> supplier;

public Main(Supplier<String> supplier) {
this.supplier = supplier;
}

public Main() {
this(DEFAULT_PROVIDER);
}

@Override
public String call() {
var value = supplier.get();

if (value == null) {
var annotations = supplier.getClass().getAnnotations();
for (var annotation : annotations) {
if (annotation.annotationType().getSimpleName().equals("Nullable")) {
return "<null value>";
}
}
throw new IllegalStateException("null without @Nullable annotation");
}

return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package surefirebug.thing;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.annotation.Nullable;
import java.util.function.Supplier;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class MainTest {

@Test
public void testDefault() {
Main main = new Main();
assertEquals("Hello, World", main.call());
}

@Test
public void testNonStandard() {
Main main = new Main(new NonstandardSupplier());
assertEquals("Hello, People", main.call());
}

@Test
public void testNullSupplierWithNullable() {
Main main = new Main(new NullSupplierWithNullable());
assertEquals("<null value>", main.call());
}

@Test
public void testNullSupplierWithoutNullable() {
Main main = new Main(new NullSupplierWithoutNullable());
IllegalStateException e = Assertions.assertThrows(IllegalStateException.class, main::call);
assertEquals("null without @Nullable annotation", e.getMessage());
}

public static class NonstandardSupplier implements Supplier<String> {
public String get() {
return "Hello, People";
}
}

@Nullable
public static class NullSupplierWithNullable implements Supplier<String> {
public String get() {
return null;
}
}

public static class NullSupplierWithoutNullable implements Supplier<String> {
public String get() {
return null;
}
}
}

0 comments on commit e367888

Please sign in to comment.