Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements and fixes #800

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: "61ab2579215aa8a0024a2f9368fc1298fdecfd18"
run: ./gradlew jacocoTestReport sonarqube --stacktrace -i
run: ./gradlew jacocoTestReport sonar --stacktrace -i

# Code format check
code-format-check:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ tasks {
javadoc {
if (releaseBuild) {
javadocTool.set(project.javaToolchains.javadocToolFor {
// create Javadoc with least Java version to get all features
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"latest"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think this means that we use the smallest Java version we need for all the features we want to use but it's phrased a bit weird?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe something like:

// create Javadoc with the minimum Java version needed for our desired features (e.g. search)

// create Javadoc with the last Java version to get all features
// (e.g. search result page on 20)
languageVersion.set(JavaLanguageVersion.of(21))
})
Expand Down Expand Up @@ -342,7 +342,7 @@ tasks {
enabled = !experimentalBuild
reports {
xml.required.set(true)
xml.outputLocation.set(file("${layout.buildDirectory}/reports/jacoco/report.xml"))
Michael1993 marked this conversation as resolved.
Show resolved Hide resolved
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/report.xml"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

package org.junitpioneer.jupiter;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

import java.io.IOException;

Expand All @@ -38,7 +38,7 @@ void test1() {
@Test
@Order(2)
void test2() {
fail();
Michael1993 marked this conversation as resolved.
Show resolved Hide resolved
fail("fails");
}

@Test
Expand All @@ -64,7 +64,7 @@ void test1() {
@Order(2)
void test2() {
// fails test with assertion
assertTrue(false);
assertThat(false).isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package org.junitpioneer.jupiter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

Expand All @@ -21,7 +21,7 @@ public class ExpectedToFailExtensionDemo {
@ExpectedToFail
void test() {
int actual = brokenMethod();
assertEquals(10, actual);
assertThat(actual).isEqualTo(10);
}
// end::expected_to_fail[]

Expand All @@ -30,7 +30,7 @@ void test() {
@ExpectedToFail("Implementation bug in brokenMethod()")
void doSomething() {
int actual = brokenMethod();
assertEquals(10, actual);
assertThat(actual).isEqualTo(10);
}
// end::expected_to_fail_message[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ void testReadLines(StdIn in) throws IOException {
String[] lines = in.capturedLines();

// This is failing
// assertEquals(lines, "line1", "line2");
// assertThat(lines).containsExactly("line1", "line2");

// This is passing
// assertEquals(lines, "line1", "line2", "line3");
// assertThat(lines).containsExactly("line1", "line2", "line3");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.jupiter.api.extension.ExtensionContext;

// implementation example, does not contain tests
public class BitArgumentProvider {

// tag::cartesian_bit_source_annotation[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.temporal.TemporalUnit;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
Expand Down Expand Up @@ -178,6 +179,7 @@ static ArgumentSets stringIntFactory() {
}
// end::cartesian_argument_sets_reuse[]

// these tests fail intentionally ~> no @Nested
static class MisconfiguredExamples {

// tag::cartesian_bad_examples[]
Expand Down Expand Up @@ -236,7 +238,7 @@ static ArgumentSets resolveTestReporterParam() {

// tag::cartesian_argument_sets_int_argument_provider[]
class IntArgumentsProvider
implements CartesianParameterArgumentsProvider {
implements CartesianParameterArgumentsProvider<Integer> {

@Override
public Stream<Integer> provideArguments(
Expand Down Expand Up @@ -282,5 +284,13 @@ ArgumentSets provideArguments() {
}
// end::cartesian_argument_sets_with_non_static_factory[]

static class MyTestReporter implements TestReporter {
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved

@Override
public void publishEntry(Map<String, String> map) {
}

}

}
// @formatter:on

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.support.AnnotationConsumer;

// implementation example, does not contain tests
public class NumberArgumentProvider {

// tag::cartesian_number_argument_provider[]
Expand All @@ -31,7 +32,7 @@ public class NumberArgumentProvider {

}

class NumberArgumentsProvider implements CartesianMethodArgumentsProvider, AnnotationConsumer<NumberSource> {
static class NumberArgumentsProvider implements CartesianMethodArgumentsProvider, AnnotationConsumer<NumberSource> {

private int[] numbers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.support.AnnotationConsumer;

// implementation example, does not contain tests
public class PeopleProviderSources {

// tag::cartesian_people_provider_with_CartesianParameterArgumentsProvider[]
Expand All @@ -36,7 +37,7 @@ public class PeopleProviderSources {

}

class PeopleProvider implements CartesianParameterArgumentsProvider {
class PeopleProvider implements CartesianParameterArgumentsProvider<Person> {

@Override
public Stream<Person> provideArguments(ExtensionContext context, Parameter parameter) {
Expand All @@ -49,7 +50,7 @@ public Stream<Person> provideArguments(ExtensionContext context, Parameter param
}
// end::cartesian_people_provider_with_CartesianParameterArgumentsProvider[]

class Person {
static class Person {

String name;
int age;
Expand All @@ -63,7 +64,7 @@ public Person(String name, int age) {

// tag::cartesian_people_provider_with_AnnotationConsumer[]
class PeopleProviderWithAnnotationConsumer
implements CartesianParameterArgumentsProvider, AnnotationConsumer<People> {
implements CartesianParameterArgumentsProvider<Person>, AnnotationConsumer<People> {

private People source;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package org.junitpioneer.jupiter.params;

import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.fail;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;

// implementation example, does not contain tests
// tag::in_memory_directory[]

public final class InMemoryDirectory implements ResourceFactory<Path> {

private static final AtomicInteger DIRECTORY_NAME = new AtomicInteger();
Expand All @@ -42,16 +42,16 @@ public Resource<Path> create(List<String> arguments) throws Exception {
Path newInMemoryDirectory = this.fileSystem.getPath("/" + directoryPrefix + DIRECTORY_NAME.getAndIncrement());
Files.createDirectory(newInMemoryDirectory);

return new Resource<Path>() {
return new Resource<>() {

@Override
public Path get() throws Exception {
public Path get() {
return newInMemoryDirectory;
}

@Override
public void close() throws Exception {
Files.walkFileTree(newInMemoryDirectory, new SimpleFileVisitor<Path>() {
Files.walkFileTree(newInMemoryDirectory, new SimpleFileVisitor<>() {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

package org.junitpioneer.jupiter.resource;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public class ResourceExtensionDemo {
Expand All @@ -24,7 +24,7 @@ public class ResourceExtensionDemo {
@Test
void test1(@New(TemporaryDirectory.class) Path tempDir) {
// Test code goes here, e.g.,
assertTrue(Files.exists(tempDir));
assertThat(tempDir).exists();
}

@Test
Expand All @@ -37,7 +37,7 @@ void test2(@New(TemporaryDirectory.class) Path tempDir) {
@Test
void dirTest1(@Dir Path tempDir) {
// Test code goes here, e.g.,
assertTrue(Files.exists(tempDir));
assertThat(tempDir).exists();
}

@Test
Expand All @@ -54,7 +54,7 @@ void testWithArg(
Path tempDir) {
// Test code goes here, e.g.,
Path rootTempDir = Paths.get(System.getProperty("java.io.tmpdir"));
assertTrue(rootTempDir.relativize(tempDir).toString().startsWith("customPrefix"));
assertThat(rootTempDir.relativize(tempDir)).asString().startsWith("customPrefix");
}
// end::create_new_resource_with_arg_demo[]
// @formatter:on
Expand All @@ -66,7 +66,7 @@ void sharedResourceTest1(
@Shared(factory = TemporaryDirectory.class, name = "sharedTempDir")
Path sharedTempDir) {
// Test code goes here, e.g.,
assertTrue(Files.exists(sharedTempDir));
assertThat(sharedTempDir).exists();
}

@Test
Expand Down Expand Up @@ -105,40 +105,42 @@ void secondSharedResource(
// end::create_multiple_shared_resources_demo[]
// @formatter:on

}

// @formatter:off
// tag::create_global_shared_resource_demo_first[]
class FirstTest {
@Nested
// @formatter:off
// tag::create_global_shared_resource_demo_first[]
class FirstTest {

@Test
void test(
@Shared(
factory = TemporaryDirectory.class,
name = "globalTempDir",
scope = Shared.Scope.GLOBAL)
Path tempDir) {
// Test code using the global shared resource...
}

@Test
void test(
@Shared(
factory = TemporaryDirectory.class,
name = "globalTempDir",
scope = Shared.Scope.GLOBAL)
Path tempDir) {
// Test code using the global shared resource...
}
// end::create_global_shared_resource_demo_first[]
// @formatter:on

}
// end::create_global_shared_resource_demo_first[]
// @formatter:on

// @formatter:off
// tag::create_global_shared_resource_demo_second[]
class SecondTest {
@Nested
// @formatter:off
// tag::create_global_shared_resource_demo_second[]
class SecondTest {

@Test
void test(
@Shared(
factory = TemporaryDirectory.class,
name = "globalTempDir",
scope = Shared.Scope.GLOBAL)
Path tempDir) {
// Test code using the global shared resource...
}

@Test
void test(
@Shared(
factory = TemporaryDirectory.class,
name = "globalTempDir",
scope = Shared.Scope.GLOBAL)
Path tempDir) {
// Test code using the global shared resource...
}
// end::create_global_shared_resource_demo_second[]
// @formatter:on

}
// end::create_global_shared_resource_demo_second[]
// @formatter:on