Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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.openrewrite.java.testing.cleanup;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings("SimplifyStreamApiCallChains")
@Value
@EqualsAndHashCode(callSuper = false)
public class TestsShouldIncludeAssertions extends Recipe {
private static final List TEST_ANNOTATIONS = Collections.singletonList("org.junit.jupiter.api.Test");
private static final List DEFAULT_ASSERTIONS = Arrays.asList(
"com.github.tomakehurst.wiremock.client.WireMock",
"io.restassured",
"mockit",
"org.assertj.core.api",
"org.easymock",
"org.hamcrest.MatcherAssert",
"org.jmock",
"org.junit.Assert", // rarely, the test annotation is junit 5 but the assert is junit 4
"org.junit.jupiter.api.Assertions",
"org.mockito.Mockito.verify",
"org.mockito.Mockito.verifyNoInteractions",
"org.mockito.Mockito.verifyNoMoreInteractions",
"org.mockito.Mockito.verifyZeroInteractions",
"org.springframework.test.web.client.MockRestServiceServer.verify",
"org.springframework.test.web.servlet.ResultActions",
"reactor.test.StepVerifier"
);
@Option(displayName = "Additional assertions",
description = "A comma delimited list of packages and/or classes that will be identified as assertions. I.E. a common assertion utility `org.foo.TestUtil`.",
example = "org.foo.TestUtil, org.bar",
required = false)
@Nullable
String additionalAsserts;
@Override
public String getDisplayName() {
return "Include an assertion in tests";
}
@Override
public String getDescription() {
return "For tests not having any assertions, wrap the statements with JUnit Jupiter's `Assertions#assertDoesNotThrow(..)`.";
}
@Override
public Set getTags() {
return Collections.singleton("RSPEC-S2699");
}
@Override
public Validated