Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
persist-credentials: false
- name: Initialize CodeQL
uses: github/codeql-action/init@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.30.5
uses: github/codeql-action/init@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.30.6
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
Expand All @@ -60,6 +60,6 @@ jobs:
-Dscan.tag.CodeQL \
classes
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.30.5
uses: github/codeql-action/analyze@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.30.6
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/ossf-scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard (optional).
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.30.5
uses: github/codeql-action/upload-sarif@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.30.6
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ asciidoctorPdf = { id = "org.asciidoctor.jvm.pdf", version.ref = "asciidoctor-pl
bnd = { id = "biz.aQute.bnd", version.ref = "bnd" }
buildParameters = { id = "org.gradlex.build-parameters", version = "1.4.4" }
commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin", version = "2.4.0" }
develocity = { id = "com.gradle.develocity", version = "4.2" }
develocity = { id = "com.gradle.develocity", version = "4.2.1" }
download = { id = "de.undercouch.download", version = "5.6.0" }
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ public static void assertPreconditionViolationNotNullFor(String name, ThrowingCa
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null", name);
}

public static void assertPreconditionViolationNotBlankFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessageContaining("%s must not be blank", name);
}

public static void assertPreconditionViolationNotEmptyFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be empty", name);
}

public static void assertPreconditionViolationNotNullOrBlankFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null or blank", name);
}

public static void assertPreconditionViolationNotNullOrEmptyFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null or empty", name);
}

public static ThrowableAssertAlternative<PreconditionViolationException> assertPreconditionViolationFor(
ThrowingCallable throwingCallable) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
package org.junit.vintage.engine.descriptor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotEmptyFor;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
Expand All @@ -23,7 +23,6 @@
import java.util.Set;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.PreconditionViolationException;
import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;

Expand All @@ -34,8 +33,7 @@ class OrFilterTests {

@Test
void exceptionWithoutAnyFilters() {
var actual = assertThrows(PreconditionViolationException.class, () -> new OrFilter(Set.of()));
assertEquals("filters must not be empty", actual.getMessage());
assertPreconditionViolationNotEmptyFor("filters", () -> new OrFilter(Set.of()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.AssertionTestUtils.assertMessageEquals;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotNullFor;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotNullOrEmptyFor;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import org.junit.jupiter.api.function.Executable;
import org.junit.platform.commons.PreconditionViolationException;
import org.opentest4j.AssertionFailedError;
import org.opentest4j.MultipleFailuresError;

Expand All @@ -40,36 +40,36 @@ class AssertAllAssertionsTests {
@SuppressWarnings("DataFlowIssue")
@Test
void assertAllWithNullExecutableArray() {
assertPrecondition("executables array must not be null or empty", () -> assertAll((Executable[]) null));
assertPreconditionViolationNotNullOrEmptyFor("executables array", () -> assertAll((Executable[]) null));
}

@SuppressWarnings("DataFlowIssue")
@Test
void assertAllWithNullExecutableCollection() {
assertPrecondition("executables collection must not be null", () -> assertAll((Collection<Executable>) null));
assertPreconditionViolationNotNullFor("executables collection", () -> assertAll((Collection<Executable>) null));
}

@SuppressWarnings("DataFlowIssue")
@Test
void assertAllWithNullExecutableStream() {
assertPrecondition("executables stream must not be null", () -> assertAll((Stream<Executable>) null));
assertPreconditionViolationNotNullFor("executables stream", () -> assertAll((Stream<Executable>) null));
}

@SuppressWarnings("DataFlowIssue")
@Test
void assertAllWithNullInExecutableArray() {
assertPrecondition("individual executables must not be null", () -> assertAll((Executable) null));
assertPreconditionViolationNotNullFor("individual executables", () -> assertAll((Executable) null));
}

@Test
void assertAllWithNullInExecutableCollection() {
assertPrecondition("individual executables must not be null", () -> assertAll(asList((Executable) null)));
assertPreconditionViolationNotNullFor("individual executables", () -> assertAll(asList((Executable) null)));
}

@SuppressWarnings("DataFlowIssue")
@Test
void assertAllWithNullInExecutableStream() {
assertPrecondition("individual executables must not be null", () -> assertAll(Stream.of((Executable) null)));
assertPreconditionViolationNotNullFor("individual executables", () -> assertAll(Stream.of((Executable) null)));
}

@Test
Expand Down Expand Up @@ -198,11 +198,6 @@ void assertAllWithParallelStream() {
assertThat(multipleFailuresError.getFailures()).hasSize(100).doesNotContainNull();
}

private void assertPrecondition(String msg, Executable executable) {
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, executable);
assertMessageEquals(exception, msg);
}

@SafeVarargs
static void assertExpectedExceptionTypes(MultipleFailuresError multipleFailuresError,
Class<? extends Throwable>... exceptionTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

import static org.junit.jupiter.api.AssertLinesMatch.isFastForwardLine;
import static org.junit.jupiter.api.AssertLinesMatch.parseFastForwardLimit;
import static org.junit.jupiter.api.AssertionTestUtils.assertMessageEquals;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotNullFor;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -31,7 +32,6 @@
import java.util.stream.Stream;

import org.jspecify.annotations.Nullable;
import org.junit.platform.commons.PreconditionViolationException;
import org.opentest4j.AssertionFailedError;

/**
Expand Down Expand Up @@ -97,20 +97,18 @@ void assertLinesMatchUsingFastForwardMarkerWithLimit3() {
@Test
@SuppressWarnings({ "unchecked", "rawtypes", "DataFlowIssue" })
void assertLinesMatchWithNullFails() {
assertThrows(PreconditionViolationException.class, () -> assertLinesMatch(null, (List) null));
assertThrows(PreconditionViolationException.class, () -> assertLinesMatch(null, Collections.emptyList()));
assertThrows(PreconditionViolationException.class, () -> assertLinesMatch(Collections.emptyList(), null));
assertPreconditionViolationFor(() -> assertLinesMatch(null, (List) null));
assertPreconditionViolationFor(() -> assertLinesMatch(null, Collections.emptyList()));
assertPreconditionViolationFor(() -> assertLinesMatch(Collections.emptyList(), null));
}

@Test
void assertLinesMatchWithNullElementsFails() {
var list = List.of("1", "2", "3");
var withNullElement = Arrays.asList("1", null, "3"); // List.of() doesn't permit null values.
assertDoesNotThrow(() -> assertLinesMatch(withNullElement, withNullElement));
var e1 = assertThrows(PreconditionViolationException.class, () -> assertLinesMatch(withNullElement, list));
assertEquals("expected line must not be null", e1.getMessage());
var e2 = assertThrows(PreconditionViolationException.class, () -> assertLinesMatch(list, withNullElement));
assertEquals("actual line must not be null", e2.getMessage());
assertPreconditionViolationNotNullFor("expected line", () -> assertLinesMatch(withNullElement, list));
assertPreconditionViolationNotNullFor("actual line", () -> assertLinesMatch(list, withNullElement));
}

private void assertError(AssertionFailedError error, String expectedMessage, List<String> expectedLines,
Expand Down Expand Up @@ -215,12 +213,12 @@ void assertLinesMatchParseFastForwardLimit() {
() -> assertEquals(9, parseFastForwardLimit(">> 9 >>")),
() -> assertEquals(9, parseFastForwardLimit(" >> 9 >> ")),
() -> assertEquals(9, parseFastForwardLimit(" >> 9 >> ")));
Throwable error = assertThrows(PreconditionViolationException.class, () -> parseFastForwardLimit(">>0>>"));
assertMessageEquals(error, "fast-forward(0) limit must be greater than zero");
error = assertThrows(PreconditionViolationException.class, () -> parseFastForwardLimit(">>-1>>"));
assertMessageEquals(error, "fast-forward(-1) limit must be greater than zero");
error = assertThrows(PreconditionViolationException.class, () -> parseFastForwardLimit(">>-2147483648>>"));
assertMessageEquals(error, "fast-forward(-2147483648) limit must be greater than zero");
assertPreconditionViolationFor(() -> parseFastForwardLimit(">>0>>"))//
.withMessage("fast-forward(0) limit must be greater than zero");
assertPreconditionViolationFor(() -> parseFastForwardLimit(">>-1>>"))//
.withMessage("fast-forward(-1) limit must be greater than zero");
assertPreconditionViolationFor(() -> parseFastForwardLimit(">>-2147483648>>"))//
.withMessage("fast-forward(-2147483648) limit must be greater than zero");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -29,7 +30,6 @@
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.function.ThrowingConsumer;
import org.junit.platform.commons.PreconditionViolationException;
import org.junit.platform.commons.support.ReflectionSupport;
import org.opentest4j.AssertionFailedError;

Expand All @@ -50,12 +50,9 @@ void streamFromStreamPreconditions() {
};
Function<Object, String> displayNameGenerator = Object::toString;

assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream((Stream<?>) null, displayNameGenerator, testExecutor));
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream(Stream.empty(), null, testExecutor));
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream(Stream.empty(), displayNameGenerator, null));
assertPreconditionViolationFor(() -> DynamicTest.stream((Stream<?>) null, displayNameGenerator, testExecutor));
assertPreconditionViolationFor(() -> DynamicTest.stream(Stream.empty(), null, testExecutor));
assertPreconditionViolationFor(() -> DynamicTest.stream(Stream.empty(), displayNameGenerator, null));
}

@SuppressWarnings("DataFlowIssue")
Expand All @@ -65,12 +62,10 @@ void streamFromIteratorPreconditions() {
};
Function<Object, String> displayNameGenerator = Object::toString;

assertThrows(PreconditionViolationException.class,
assertPreconditionViolationFor(
() -> DynamicTest.stream((Iterator<?>) null, displayNameGenerator, testExecutor));
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream(emptyIterator(), null, testExecutor));
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream(emptyIterator(), displayNameGenerator, null));
assertPreconditionViolationFor(() -> DynamicTest.stream(emptyIterator(), null, testExecutor));
assertPreconditionViolationFor(() -> DynamicTest.stream(emptyIterator(), displayNameGenerator, null));
}

@SuppressWarnings("DataFlowIssue")
Expand All @@ -79,9 +74,8 @@ void streamFromStreamWithNamesPreconditions() {
ThrowingConsumer<Object> testExecutor = input -> {
};

assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream((Stream<? extends Named<Object>>) null, testExecutor));
assertThrows(PreconditionViolationException.class, () -> DynamicTest.stream(Stream.empty(), null));
assertPreconditionViolationFor(() -> DynamicTest.stream((Stream<? extends Named<Object>>) null, testExecutor));
assertPreconditionViolationFor(() -> DynamicTest.stream(Stream.empty(), null));
}

@SuppressWarnings("DataFlowIssue")
Expand All @@ -90,23 +84,21 @@ void streamFromIteratorWithNamesPreconditions() {
ThrowingConsumer<Object> testExecutor = input -> {
};

assertThrows(PreconditionViolationException.class,
assertPreconditionViolationFor(
() -> DynamicTest.stream((Iterator<? extends Named<Object>>) null, testExecutor));
assertThrows(PreconditionViolationException.class, () -> DynamicTest.stream(emptyIterator(), null));
assertPreconditionViolationFor(() -> DynamicTest.stream(emptyIterator(), null));
}

@SuppressWarnings("DataFlowIssue")
@Test
void streamFromStreamWithNamedExecutablesPreconditions() {
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream((Stream<DummyNamedExecutableForTests>) null));
assertPreconditionViolationFor(() -> DynamicTest.stream((Stream<DummyNamedExecutableForTests>) null));
}

@SuppressWarnings("DataFlowIssue")
@Test
void streamFromIteratorWithNamedExecutablesPreconditions() {
assertThrows(PreconditionViolationException.class,
() -> DynamicTest.stream((Iterator<DummyNamedExecutableForTests>) null));
assertPreconditionViolationFor(() -> DynamicTest.stream((Iterator<DummyNamedExecutableForTests>) null));
}

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

package org.junit.jupiter.api.condition;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.condition.DisabledIfEnvironmentVariableIntegrationTests.ENIGMA;
import static org.junit.jupiter.api.condition.DisabledIfEnvironmentVariableIntegrationTests.KEY1;
import static org.junit.jupiter.api.condition.DisabledIfEnvironmentVariableIntegrationTests.KEY2;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotBlankFor;

import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.platform.commons.PreconditionViolationException;

/**
* Unit tests for {@link DisabledIfEnvironmentVariableCondition}.
Expand Down Expand Up @@ -68,17 +66,15 @@ void enabledBecauseAnnotationIsNotPresent() {
*/
@Test
void blankNamedAttribute() {
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
assertThat(exception).hasMessageContaining("The 'named' attribute must not be blank");
assertPreconditionViolationNotBlankFor("The 'named' attribute", this::evaluateCondition);
}

/**
* @see DisabledIfEnvironmentVariableIntegrationTests#blankMatchesAttribute()
*/
@Test
void blankMatchesAttribute() {
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
assertThat(exception).hasMessageContaining("The 'matches' attribute must not be blank");
assertPreconditionViolationNotBlankFor("The 'matches' attribute", this::evaluateCondition);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

package org.junit.jupiter.api.condition;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotBlankFor;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.platform.commons.PreconditionViolationException;

/**
* Unit tests for {@link DisabledIfSystemPropertyCondition}.
Expand Down Expand Up @@ -64,17 +62,15 @@ void enabledBecauseAnnotationIsNotPresent() {
*/
@Test
void blankNamedAttribute() {
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
assertThat(exception).hasMessageContaining("The 'named' attribute must not be blank");
assertPreconditionViolationNotBlankFor("The 'named' attribute", this::evaluateCondition);
}

/**
* @see DisabledIfSystemPropertyIntegrationTests#blankMatchesAttribute()
*/
@Test
void blankMatchesAttribute() {
Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
assertThat(exception).hasMessageContaining("The 'matches' attribute must not be blank");
assertPreconditionViolationNotBlankFor("The 'matches' attribute", this::evaluateCondition);
}

/**
Expand Down
Loading