Simplify SourceFileAssert assertion methods
Remove assertion methods that turned out not to be needed when testing Spring Framework's AOT generated code. Closes gh-28556
This commit is contained in:
@@ -100,8 +100,7 @@ class TestCompilerTests {
|
||||
@Test
|
||||
void compileAndGetSourceFile() {
|
||||
TestCompiler.forSystem().withSources(SourceFile.of(HELLO_SPRING)).compile(
|
||||
compiled -> assertThat(compiled.getSourceFile()).hasMethodNamed(
|
||||
"get").withBodyContaining("// !!"));
|
||||
compiled -> assertThat(compiled.getSourceFile()).contains("// !!"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.aot.test.generator.file;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link MethodAssert}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class MethodAssertTests {
|
||||
|
||||
private static final String SAMPLE = """
|
||||
package com.example;
|
||||
|
||||
public class Sample {
|
||||
|
||||
public void run() {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
|
||||
}
|
||||
""";
|
||||
|
||||
private final SourceFile sourceFile = SourceFile.of(SAMPLE);
|
||||
|
||||
@Test
|
||||
void withBodyWhenMatches() {
|
||||
assertThat(this.sourceFile).hasMethodNamed("run").withBody("""
|
||||
System.out.println("Hello World!");""");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBodyWhenDoesNotMatchThrowsException() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).hasMethodNamed("run").withBody("""
|
||||
System.out.println("Hello Spring!");""")).withMessageContaining(
|
||||
"to be equal to");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBodyContainingWhenContainsAll() {
|
||||
assertThat(this.sourceFile).hasMethodNamed("run").withBodyContaining("Hello",
|
||||
"World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withBodyWhenDoesNotContainOneThrowsException() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).hasMethodNamed(
|
||||
"run").withBodyContaining("Hello",
|
||||
"Spring!")).withMessageContaining("to contain");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.aot.test.generator.file;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -77,52 +75,4 @@ class SourceFileAssertTests {
|
||||
"expected", "but was");
|
||||
}
|
||||
|
||||
@Test
|
||||
void implementsInterfaceWhenImplementsInterface() {
|
||||
assertThat(this.sourceFile).implementsInterface(Runnable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void implementsInterfaceWhenDoesNotImplementInterfaceThrowsException() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).implementsInterface(
|
||||
Callable.class)).withMessageContaining("to contain:");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMethodNamedWhenHasName() {
|
||||
MethodAssert methodAssert = assertThat(this.sourceFile).hasMethodNamed("main");
|
||||
assertThat(methodAssert).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMethodNameWhenDoesNotHaveMethodThrowsException() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).hasMethodNamed(
|
||||
"missing")).withMessageContaining("to contain method");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMethodNameWhenHasMultipleMethodsWithNameThrowsException() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).hasMethodNamed(
|
||||
"run")).withMessageContaining("to contain unique method");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMethodWhenHasMethod() {
|
||||
MethodAssert methodAssert = assertThat(this.sourceFile).hasMethod("run",
|
||||
String.class);
|
||||
assertThat(methodAssert).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMethodWhenDoesNotHaveMethod() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(this.sourceFile).hasMethod("run",
|
||||
Integer.class)).withMessageContaining(
|
||||
"to contain").withMessageContaining(
|
||||
"run(java.lang.Integer");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aot.test.generator.file;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.thoughtworks.qdox.model.JavaSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -90,12 +89,6 @@ class SourceFileTests {
|
||||
assertThat(sourceFile.getContent()).isEqualTo(HELLO_WORLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJavaSourceReturnsJavaSource() {
|
||||
SourceFile sourceFile = SourceFile.of(HELLO_WORLD);
|
||||
assertThat(sourceFile.getJavaSource()).isInstanceOf(JavaSource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void assertThatReturnsAssert() {
|
||||
|
||||
Reference in New Issue
Block a user