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

review: test: introduce generated AssertJ asserts #5644

Merged
merged 17 commits into from
Feb 11, 2024
Merged
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
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ jobs:
run: nix develop ${{ env.NIX_OPTIONS }} --command true
- name: Check maven pom quality
run: nix develop ${{ env.NIX_OPTIONS }} --command maven-pom-quality

codegen:
runs-on: ubuntu-latest
name: Codegeneration
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
fetch-depth: 0
- name: Setup env
uses: ./.github/actions/setup-tests

- name: Time nix setup
run: nix develop ${{ env.NIX_OPTIONS }} --command true
- name: Run codegen checks
run: nix develop ${{ env.NIX_OPTIONS }} --command codegen
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
mvn -f spoon-pom -B test-compile
mvn -f spoon-pom -Pcoveralls test jacoco:report coveralls:report -DrepoToken=$GITHUB_TOKEN -DserviceName=github -DpullRequest=$PR_NUMBER --fail-never
'';
codegen = pkgs.writeScriptBin "codegen" ''
set -eu
mvn test -Dgroups=codegen
mvn spotless:apply
git diff --exit-code || "::error::Generated code is not up to date. Execute mvn test -Dgroups=codegen, mvn spotless:apply and commit your changes."
'';
extra = pkgs.writeScriptBin "extra" (if !extraChecks then "exit 2" else ''
set -eu
# Use silent log config
Expand Down Expand Up @@ -174,7 +180,7 @@
])
else [ ];
packages = with pkgs;
[ jdk maven test coverage mavenPomQuality javadocQuality reproducibleBuilds ]
[ jdk maven test codegen coverage mavenPomQuality javadocQuality reproducibleBuilds ]
++ (if extraChecks then [ gradle pythonEnv extra extraRemote jbang ] else [ ])
++ (if release then [ semver jreleaser ] else [ ]);
};
Expand Down
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
<artifactId>jspecify</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.2</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- to reproduce JTD error with nullable annotation -->
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -228,6 +234,36 @@
</classpathDependencyExcludes>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<formats>
<format>
<includes>
<include>src/test/java/spoon/testing/assertions/**/*.java</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<tabs>true</tabs>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<includes>
<include>src/test/java/spoon/testing/assertions/**/*.java</include>
</includes>
<palantirJavaFormat>
<version>2.40.0</version>
<style>PALANTIR</style>
<formatJavadoc>true</formatJavadoc>
</palantirJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ListAssert;
import spoon.reflect.code.CtAbstractInvocation;
import spoon.reflect.code.CtExpression;
interface CtAbstractInvocationAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAbstractInvocation<?>> extends CtElementAssertInterface<A, W> , SpoonAssert<A, W> {
default ListAssert<CtExpression<?>> getArguments() {
return Assertions.assertThat(actual().getArguments());
}

default CtExecutableReferenceAssertInterface<?, ?> getExecutable() {
return SpoonAssertions.assertThat(actual().getExecutable());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ListAssert;
import spoon.reflect.code.CtAbstractSwitch;
import spoon.reflect.code.CtCase;
interface CtAbstractSwitchAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAbstractSwitch<?>> extends CtElementAssertInterface<A, W> , SpoonAssert<A, W> {
default ListAssert<CtCase<?>> getCases() {
return Assertions.assertThat(actual().getCases());
}

default CtExpressionAssertInterface<?, ?> getSelector() {
return SpoonAssertions.assertThat(actual().getSelector());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ListAssert;
import spoon.reflect.reference.CtActualTypeContainer;
import spoon.reflect.reference.CtTypeReference;
interface CtActualTypeContainerAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtActualTypeContainer> extends SpoonAssert<A, W> {
default ListAssert<CtTypeReference<?>> getActualTypeArguments() {
return Assertions.assertThat(actual().getActualTypeArguments());
}
}
23 changes: 23 additions & 0 deletions src/test/java/spoon/testing/assertions/CtAnnotationAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnnotation;
public class CtAnnotationAssert extends AbstractObjectAssert<CtAnnotationAssert, CtAnnotation<?>> implements CtAnnotationAssertInterface<CtAnnotationAssert, CtAnnotation<?>> {
CtAnnotationAssert(CtAnnotation<?> actual) {
super(actual, CtAnnotationAssert.class);
}

@Override
public CtAnnotationAssert self() {
return this;
}

@Override
public CtAnnotation<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.MapAssert;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtAnnotation;
interface CtAnnotationAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAnnotation<?>> extends SpoonAssert<A, W> , CtExpressionAssertInterface<A, W> , CtShadowableAssertInterface<A, W> {
default CtTypeReferenceAssertInterface<?, ?> getAnnotationType() {
return SpoonAssertions.assertThat(actual().getAnnotationType());
}

default MapAssert<String, CtExpression> getValues() {
return Assertions.assertThat(actual().getValues());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtAnnotationFieldAccess;
public class CtAnnotationFieldAccessAssert extends AbstractObjectAssert<CtAnnotationFieldAccessAssert, CtAnnotationFieldAccess<?>> implements CtAnnotationFieldAccessAssertInterface<CtAnnotationFieldAccessAssert, CtAnnotationFieldAccess<?>> {
CtAnnotationFieldAccessAssert(CtAnnotationFieldAccess<?> actual) {
super(actual, CtAnnotationFieldAccessAssert.class);
}

@Override
public CtAnnotationFieldAccessAssert self() {
return this;
}

@Override
public CtAnnotationFieldAccess<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtAnnotationFieldAccess;
interface CtAnnotationFieldAccessAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAnnotationFieldAccess<?>> extends CtVariableReadAssertInterface<A, W> , SpoonAssert<A, W> , CtTargetedExpressionAssertInterface<A, W> {
default CtFieldReferenceAssertInterface<?, ?> getVariable() {
return SpoonAssertions.assertThat(actual().getVariable());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnnotationMethod;
public class CtAnnotationMethodAssert extends AbstractObjectAssert<CtAnnotationMethodAssert, CtAnnotationMethod<?>> implements CtAnnotationMethodAssertInterface<CtAnnotationMethodAssert, CtAnnotationMethod<?>> {
CtAnnotationMethodAssert(CtAnnotationMethod<?> actual) {
super(actual, CtAnnotationMethodAssert.class);
}

@Override
public CtAnnotationMethodAssert self() {
return this;
}

@Override
public CtAnnotationMethod<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnnotationMethod;
interface CtAnnotationMethodAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAnnotationMethod<?>> extends SpoonAssert<A, W> , CtMethodAssertInterface<A, W> {
default CtExpressionAssertInterface<?, ?> getDefaultExpression() {
return SpoonAssertions.assertThat(actual().getDefaultExpression());
}
}
23 changes: 23 additions & 0 deletions src/test/java/spoon/testing/assertions/CtAnnotationTypeAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnnotationType;
public class CtAnnotationTypeAssert extends AbstractObjectAssert<CtAnnotationTypeAssert, CtAnnotationType<?>> implements CtAnnotationTypeAssertInterface<CtAnnotationTypeAssert, CtAnnotationType<?>> {
CtAnnotationTypeAssert(CtAnnotationType<?> actual) {
super(actual, CtAnnotationTypeAssert.class);
}

@Override
public CtAnnotationTypeAssert self() {
return this;
}

@Override
public CtAnnotationType<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnnotationType;
interface CtAnnotationTypeAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAnnotationType<?>> extends SpoonAssert<A, W> , CtTypeAssertInterface<A, W> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnonymousExecutable;
public class CtAnonymousExecutableAssert extends AbstractObjectAssert<CtAnonymousExecutableAssert, CtAnonymousExecutable> implements CtAnonymousExecutableAssertInterface<CtAnonymousExecutableAssert, CtAnonymousExecutable> {
CtAnonymousExecutableAssert(CtAnonymousExecutable actual) {
super(actual, CtAnonymousExecutableAssert.class);
}

@Override
public CtAnonymousExecutableAssert self() {
return this;
}

@Override
public CtAnonymousExecutable actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.declaration.CtAnonymousExecutable;
interface CtAnonymousExecutableAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtAnonymousExecutable> extends SpoonAssert<A, W> , CtExecutableAssertInterface<A, W> , CtTypeMemberAssertInterface<A, W> {}
23 changes: 23 additions & 0 deletions src/test/java/spoon/testing/assertions/CtArrayAccessAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtArrayAccess;
public class CtArrayAccessAssert extends AbstractObjectAssert<CtArrayAccessAssert, CtArrayAccess<?, ?>> implements CtArrayAccessAssertInterface<CtArrayAccessAssert, CtArrayAccess<?, ?>> {
CtArrayAccessAssert(CtArrayAccess<?, ?> actual) {
super(actual, CtArrayAccessAssert.class);
}

@Override
public CtArrayAccessAssert self() {
return this;
}

@Override
public CtArrayAccess<?, ?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtArrayAccess;
interface CtArrayAccessAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtArrayAccess<?, ?>> extends SpoonAssert<A, W> , CtTargetedExpressionAssertInterface<A, W> {
default CtExpressionAssertInterface<?, ?> getIndexExpression() {
return SpoonAssertions.assertThat(actual().getIndexExpression());
}
}
23 changes: 23 additions & 0 deletions src/test/java/spoon/testing/assertions/CtArrayReadAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtArrayRead;
public class CtArrayReadAssert extends AbstractObjectAssert<CtArrayReadAssert, CtArrayRead<?>> implements CtArrayReadAssertInterface<CtArrayReadAssert, CtArrayRead<?>> {
CtArrayReadAssert(CtArrayRead<?> actual) {
super(actual, CtArrayReadAssert.class);
}

@Override
public CtArrayReadAssert self() {
return this;
}

@Override
public CtArrayRead<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.code.CtArrayRead;
interface CtArrayReadAssertInterface<A extends AbstractObjectAssert<A, W>, W extends CtArrayRead<?>> extends SpoonAssert<A, W> , CtArrayAccessAssertInterface<A, W> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spoon.testing.assertions;
import org.assertj.core.api.AbstractObjectAssert;
import spoon.reflect.reference.CtArrayTypeReference;
public class CtArrayTypeReferenceAssert extends AbstractObjectAssert<CtArrayTypeReferenceAssert, CtArrayTypeReference<?>> implements CtArrayTypeReferenceAssertInterface<CtArrayTypeReferenceAssert, CtArrayTypeReference<?>> {
CtArrayTypeReferenceAssert(CtArrayTypeReference<?> actual) {
super(actual, CtArrayTypeReferenceAssert.class);
}

@Override
public CtArrayTypeReferenceAssert self() {
return this;
}

@Override
public CtArrayTypeReference<?> actual() {
return this.actual;
}

@Override
public void failWithMessage(String errorMessage, Object... arguments) {
super.failWithMessage(errorMessage, arguments);
}
}
Loading
Loading