├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── .idea └── icon.svg ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── assertj-generator ├── javadoc-theme │ ├── assertj-theme.css │ └── hljs-theme.css ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── assertj │ │ │ └── assertions │ │ │ └── generator │ │ │ ├── AssertionGenerator.java │ │ │ ├── AssertionsEntryPointGenerator.java │ │ │ ├── AssertionsEntryPointType.java │ │ │ ├── BaseAssertionGenerator.java │ │ │ ├── DefaultTemplateRegistryProducer.java │ │ │ ├── GenerateAssertion.java │ │ │ ├── Template.java │ │ │ ├── TemplateRegistry.java │ │ │ ├── cli │ │ │ └── AssertionGeneratorLauncher.java │ │ │ ├── description │ │ │ ├── ClassDescription.java │ │ │ ├── DataDescription.java │ │ │ ├── FieldDescription.java │ │ │ ├── GetterDescription.java │ │ │ ├── Visibility.java │ │ │ └── converter │ │ │ │ ├── AnnotationConfiguration.java │ │ │ │ ├── ClassDescriptionConverter.java │ │ │ │ └── ClassToClassDescriptionConverter.java │ │ │ └── util │ │ │ ├── ClassUtil.java │ │ │ └── StringUtil.java │ ├── resources │ │ ├── assemblies │ │ │ ├── unix-assembly.xml │ │ │ └── windows-assembly.xml │ │ ├── logback.xml │ │ ├── scripts │ │ │ ├── generate-assertions.bat │ │ │ └── generate-assertions.sh │ │ └── templates │ │ │ ├── auto_closeable_bdd_soft_assertions_entry_point_class_template.txt │ │ │ ├── auto_closeable_soft_assertions_entry_point_class_template.txt │ │ │ ├── bdd_assertion_entry_point_method_template.txt │ │ │ ├── bdd_assertions_entry_point_class_template.txt │ │ │ ├── bdd_soft_assertion_entry_point_method_template.txt │ │ │ ├── bdd_soft_assertions_entry_point_class_template.txt │ │ │ ├── custom_abstract_assertion_class_template.txt │ │ │ ├── custom_assertion_class_template.txt │ │ │ ├── custom_hierarchical_assertion_class_template.txt │ │ │ ├── has_assertion_template.txt │ │ │ ├── has_assertion_template_for_char.txt │ │ │ ├── has_assertion_template_for_character.txt │ │ │ ├── has_assertion_template_for_primitive.txt │ │ │ ├── has_assertion_template_for_primitive_wrapper.txt │ │ │ ├── has_assertion_template_for_real_number.txt │ │ │ ├── has_assertion_template_for_real_number_wrapper.txt │ │ │ ├── has_assertion_template_for_whole_number.txt │ │ │ ├── has_assertion_template_for_whole_number_wrapper.txt │ │ │ ├── has_elements_assertion_template_for_array.txt │ │ │ ├── has_elements_assertion_template_for_iterable.txt │ │ │ ├── is_assertion_template.txt │ │ │ ├── is_without_negative_assertion_template.txt │ │ │ ├── is_wrapper_assertion_template.txt │ │ │ ├── is_wrapper_without_negative_assertion_template.txt │ │ │ ├── junit_bdd_soft_assertions_entry_point_class_template.txt │ │ │ ├── junit_soft_assertions_entry_point_class_template.txt │ │ │ ├── soft_assertion_entry_point_method_template.txt │ │ │ ├── soft_assertions_entry_point_class_template.txt │ │ │ ├── standard_assertion_entry_point_method_template.txt │ │ │ └── standard_assertions_entry_point_class_template.txt │ └── scripts │ │ └── build.gradle │ └── test │ ├── java │ ├── my │ │ └── assertions │ │ │ └── OuterClassStaticNestedPersonAssert.java │ └── org │ │ └── assertj │ │ └── assertions │ │ └── generator │ │ ├── AssertionGeneratorOverrideTemplateTest.java │ │ ├── AssertionGeneratorTest.java │ │ ├── AssertionsEntryPointGeneratorTest.java │ │ ├── BeanWithExceptionsTest.java │ │ ├── ClassUsingDifferentClassesWithSameName.java │ │ ├── GenerationHandler.java │ │ ├── NestedClassesTest.java │ │ ├── PlayerAssertTest.java │ │ ├── TemplateTest.java │ │ ├── data │ │ ├── AnnotatedClass.java │ │ ├── AutoValue.java │ │ ├── AutoValueAnnotatedClass.java │ │ ├── BeanWithOneException.java │ │ ├── BeanWithTwoExceptions.java │ │ ├── BlockBuster.java │ │ ├── BooleanPredicates.java │ │ ├── Dollar$.java │ │ ├── EnemyReport.java │ │ ├── FieldPropertyClash.java │ │ ├── InterferencePrimitives.java │ │ ├── Keywords.java │ │ ├── Movie.java │ │ ├── Name.java │ │ ├── OuterClass.java │ │ ├── ParameterClashWithVariables.java │ │ ├── Primitives.java │ │ ├── Team.java │ │ ├── TreeEnum.java │ │ ├── WithPrivateFields.java │ │ ├── WithPrivateFieldsParent.java │ │ ├── art │ │ │ └── ArtWork.java │ │ ├── cars │ │ │ └── Car.java │ │ ├── inner │ │ │ ├── Data.java │ │ │ └── PackagePrivate.java │ │ ├── lotr │ │ │ ├── FellowshipOfTheRing.java │ │ │ ├── Race.java │ │ │ ├── Ring.java │ │ │ └── TolkienCharacter.java │ │ ├── nba │ │ │ ├── Player.java │ │ │ ├── PlayerAgent.java │ │ │ └── team │ │ │ │ ├── Coach.java │ │ │ │ └── Team.java │ │ └── package-info.java │ │ ├── description │ │ ├── FieldDescriptionTest.java │ │ ├── GetterDescriptionTest.java │ │ └── converter │ │ │ └── ClassToClassDescriptionConverterTest.java │ │ └── util │ │ ├── ClassUtilTest.java │ │ ├── PackagePrivate.java │ │ └── StringUtilTest.java │ └── resources │ ├── AbstractAnnotatedClassAssert.expected.txt │ ├── AbstractArtWorkAssert.expected.txt │ ├── AbstractAutoValueAnnotatedClassAssert.expected.txt │ ├── AbstractBlockBusterAssert.expected.txt │ ├── AbstractBooleanPredicatesAssert.expected.txt │ ├── AbstractClassUsingDifferentClassesWithSameNameAssert.expected.txt │ ├── AbstractDollar$Assert.expected.txt │ ├── AbstractFieldPropertyClashAssert.expected.txt │ ├── AbstractInterferencePrimitivesAssert.expected.txt │ ├── AbstractKeywordsAssert.expected.txt │ ├── AbstractMovieAssert.expected.txt │ ├── AbstractMultipleGenericsAssert.expected.txt │ ├── AbstractNameAssert.expected.txt │ ├── AbstractOptionalAssert.expected.txt │ ├── AbstractPlayerAgentAssert.expected.txt │ ├── AbstractPlayerAgentAssert.generated.in.custom.package.expected.txt │ ├── AbstractPlayerAssert.expected.txt │ ├── AbstractPlayerAssert.generated.in.custom.package.expected.txt │ ├── AbstractPrimitivesAssert.expected.txt │ ├── AbstractTeamAssert.expected.txt │ ├── AbstractWithPrivateFieldsAssert.expected.txt │ ├── AbstractWithPrivateFieldsParentAssert.expected.txt │ ├── AnnotatedClassAssert.expected.txt │ ├── AnnotatedClassAssert.flat.expected.txt │ ├── ArtWorkAssert.expected.txt │ ├── Assertions.expected.txt │ ├── AssertionsForClassesWithSameName.expected.txt │ ├── AssertionsWithCustomPackage.expected.txt │ ├── AutoCloseableBDDSoftAssertions.expected.txt │ ├── AutoCloseableSoftAssertions.expected.txt │ ├── AutoValueAnnotatedClassAssert.expected.txt │ ├── AutoValueAnnotatedClassAssert.flat.expected.txt │ ├── BDDSoftAssertions.expected.txt │ ├── BddAssertions.expected.txt │ ├── BeanWithOneException.expected.txt │ ├── BlockBusterAssert.expected.txt │ ├── BooleanPredicatesAssert.expected.txt │ ├── BooleanPredicatesAssert.flat.expected.txt │ ├── CarAssert.expected.txt │ ├── ClassUsingDifferentClassesWithSameNameAssert.expected.txt │ ├── ClassUsingDifferentClassesWithSameNameAssert.flat.expected.txt │ ├── Dollar$Assert.expected.txt │ ├── Dollar$Assert.flat.expected.txt │ ├── FieldPropertyClashAssert.expected.txt │ ├── FieldPropertyClashAssert.flat.expected.txt │ ├── InterferencePrimitivesAssert.expected.txt │ ├── InterferencePrimitivesAssert.flat.expected.txt │ ├── JUnitBDDSoftAssertions.expected.txt │ ├── JUnitSoftAssertions.expected.txt │ ├── KeywordsAssert.expected.txt │ ├── KeywordsAssert.flat.expected.txt │ ├── MovieAssert.expected.txt │ ├── MovieAssert.flat.expected.txt │ ├── MultipleGenericsAssert.expected.txt │ ├── MultipleGenericsAssert.flat.expected.txt │ ├── MyAssertions.expected.txt │ ├── NameAssert.expected.txt │ ├── NameAssert.flat.expected.txt │ ├── NestedClassAssert.hierarchical.template.expected.txt │ ├── NestedClassAssert.template.expected.txt │ ├── NestedClassAssert.template.generated.in.custom.package.expected.txt │ ├── OptionalAssert.expected.txt │ ├── OptionalAssert.flat.expected.txt │ ├── ParameterClashWithVariablesAssert.flat.expected.txt │ ├── PlayerAgentAssert.expected.txt │ ├── PlayerAgentAssert.flat.expected.txt │ ├── PlayerAgentAssert.generated.in.custom.package.expected.txt │ ├── PlayerAgentAssert.generated.in.custom.package.flat.expected.txt │ ├── PlayerAssert.expected.txt │ ├── PlayerAssert.flat.expected.txt │ ├── PlayerAssert.generated.in.custom.package.expected.txt │ ├── PlayerAssert.generated.in.custom.package.flat.expected.txt │ ├── PrimitivesAssert.expected.txt │ ├── PrimitivesAssert.flat.expected.txt │ ├── SoftAssertions.expected.txt │ ├── TeamAssert.expected.txt │ ├── TeamAssert.flat.expected.txt │ ├── WithPrivateFieldsAssert.expected.txt │ ├── WithPrivateFieldsAssert.flat.expected.txt │ ├── WithPrivateFieldsParentAssert.expected.txt │ └── customtemplates │ ├── custom_has_assertion_template_for_whole_number.txt │ └── my_assertion_entry_point_class.txt ├── build-assertion-generator-and-maven-plugin.sh ├── mvnw ├── mvnw.cmd └── pom.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: https://editorconfig.org/ 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | 12 | # 2 space indentation for java, xml and yml files 13 | [*.{java,xml,yml,sh}] 14 | indent_style = space 15 | indent_size = 2 16 | 17 | # Maven POM code convention 18 | [pom.xml] 19 | max_line_length = 205 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | MAVEN_ARGS: -B -V -ntp -e -Djansi.passthrough=true -Dstyle.color=always 7 | 8 | jobs: 9 | 10 | test: 11 | 12 | name: Test 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Set up Java 18 | uses: actions/setup-java@v4 19 | with: 20 | distribution: 'zulu' 21 | java-version: '21' 22 | cache: 'maven' 23 | - name: Test 24 | run: ./mvnw $MAVEN_ARGS verify 25 | 26 | javadoc: 27 | 28 | name: Javadoc 29 | runs-on: ubuntu-latest 30 | 31 | steps: 32 | - uses: actions/checkout@v4 33 | - name: Set up Java 34 | uses: actions/setup-java@v4 35 | with: 36 | distribution: 'zulu' 37 | java-version: '21' 38 | cache: 'maven' 39 | - name: Generate Javadoc 40 | run: ./mvnw $MAVEN_ARGS -DskipTests package javadoc:javadoc 41 | 42 | sonar: 43 | 44 | name: Sonar code analysis 45 | runs-on: ubuntu-latest 46 | if: github.repository == 'assertj/assertj-assertions-generator' && github.event_name == 'push' 47 | 48 | steps: 49 | - uses: actions/checkout@v4 50 | - name: Set up Java 51 | uses: actions/setup-java@v4 52 | with: 53 | distribution: 'zulu' 54 | java-version: '21' 55 | cache: 'maven' 56 | - name: Test with Sonar 57 | run: > 58 | ./mvnw -V --no-transfer-progress -e clean verify javadoc:javadoc 59 | org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar 60 | -Dsonar.host.url=https://sonarcloud.io 61 | -Dsonar.organization=assertj 62 | -Dsonar.projectKey=assertj_assertj-assertions-generator 63 | env: 64 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 65 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 66 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | env: 7 | MAVEN_ARGS: -B -V -ntp -e -Djansi.passthrough=true -Dstyle.color=always -Djacoco.skip=true 8 | 9 | jobs: 10 | release: 11 | 12 | name: Release to Maven Central 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Set up Maven Central 18 | uses: actions/setup-java@v4 19 | with: 20 | distribution: 'zulu' 21 | java-version: '21' 22 | server-id: ossrh 23 | server-username: OSSRH_USERNAME 24 | server-password: OSSRH_TOKEN 25 | gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} 26 | 27 | - name: Publish to Maven Central 28 | run: | 29 | git config user.name '${{ github.actor }}' 30 | git config user.email '${{ github.actor }}@users.noreply.github.com' 31 | ./mvnw $MAVEN_ARGS release:prepare release:perform -Dpassword=${{ secrets.GITHUB_TOKEN }} 32 | env: 33 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 34 | OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} 35 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target 3 | /.settings 4 | /.classpath 5 | /.project 6 | .idea/* 7 | !/.idea/icon.svg 8 | *.iml 9 | 10 | 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | /Vagrantfile 16 | /.vagrant/ 17 | 18 | .flattened-pom.xml 19 | .mvn/wrapper/maven-wrapper.jar 20 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 20 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | Thank you for your interest ! 5 | We appreciate your effort and to make sure that your pull request is easy to review, we ask you to make note of the following guidelines : 6 | 7 | * Use **[AssertJ code Eclipse formatting preferences](https://github.com/joel-costigliola/assertj-core/blob/master/src/ide-support/assertj-eclipse-formatter.xml)** (for Idea users, it is possible to import it) 8 | * Unit tests method naming convention is underscore based (like python) and not camel case, we find it is much readable for long test names ! 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AssertJ - Assertions Generator [](https://search.maven.org/search?q=g:%22org.assertj%22%20AND%20a:%22assertj-assertions-generator%22) [](http://www.javadoc.io/doc/org.assertj/assertj-assertions-generator) 2 | 3 | [](https://github.com/assertj/assertj-assertions-generator/actions/workflows/main.yml?query=branch%3Amain) 4 | 5 | ## Overview 6 | 7 | The Assertions Generator can create specific assertions for your classes. It comes with : 8 | * a CLI tool (this project) 9 | * a [**maven plugin**](https://github.com/assertj/assertj-assertions-generator-maven-plugin). 10 | * a [**gradle plugin**](https://github.com/assertj/assertj-generator-gradle-plugin). 11 | 12 | Let's say you have a `Player` class with `name` and `team` properties. The generator will create a `PlayerAssert` assertions class with `hasName` and `hasTeam` assertions. This allows you to write : 13 | 14 | ```java 15 | assertThat(mvp).hasName("Lebron James").hasTeam("Miami Heat"); 16 | ``` 17 | 18 | ## Documentation 19 | 20 | Please have a look at the complete documentation in the [**assertions generator section**](http://joel-costigliola.github.io/assertj/assertj-assertions-generator.html), including a [**quickstart guide**](http://joel-costigliola.github.io/assertj/assertj-assertions-generator.html#quickstart). 21 | -------------------------------------------------------------------------------- /assertj-generator/javadoc-theme/assertj-theme.css: -------------------------------------------------------------------------------- 1 | :root { 2 | /* body, block and code fonts */ 3 | --body-font-family: Verdana, Geneva, sans-serif; 4 | --block-font-family: Verdana, Geneva, serif; 5 | /* Text colors for body and block elements */ 6 | --body-text-color: #000000; 7 | --block-text-color: #000000; 8 | /* Background colors for various structural elements */ 9 | --body-background-color: #edd9a6; 10 | --section-background-color: #e9d195; 11 | --detail-background-color: #edd9a6; 12 | /* Colors for navigation bar and table captions */ 13 | --navbar-background-color: #232323; 14 | --navbar-text-color: #edd9a6; 15 | /* Background color for subnavigation and various headers */ 16 | --subnav-background-color: #e5c880; 17 | /* Background and text colors for selected tabs and navigation items */ 18 | --selected-background-color: #e5c880; 19 | --selected-text-color: #000000; 20 | --selected-link-color: #861203; 21 | /* Background colors for generated tables */ 22 | --even-row-color: #edd9a6; 23 | --odd-row-color: #e7ce8e; 24 | /* Text color for page title */ 25 | --title-color: #000000; 26 | /* Text colors for links */ 27 | --link-color: #861203; 28 | --link-color-active: #641003; 29 | /* Border colors for structural elements and user defined tables */ 30 | --border-color: #e5c880; 31 | /* Search input colors */ 32 | --search-input-background-color: #edd9a6; 33 | } 34 | -------------------------------------------------------------------------------- /assertj-generator/javadoc-theme/hljs-theme.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Railscasts-like style (c) Visoft, Inc. (Damien White) 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | background: #232323; 12 | color: #e6e1dc; 13 | /* added by us */ 14 | border-radius:8px; 15 | } 16 | 17 | .hljs-comment, 18 | .hljs-quote { 19 | color: #bc9458; 20 | font-style: italic; 21 | } 22 | 23 | .hljs-keyword, 24 | .hljs-selector-tag { 25 | color: #c26230; 26 | } 27 | 28 | .hljs-string, 29 | .hljs-number, 30 | .hljs-regexp, 31 | .hljs-variable, 32 | .hljs-template-variable { 33 | color: #a5c261; 34 | } 35 | 36 | .hljs-subst { 37 | color: #519f50; 38 | } 39 | 40 | .hljs-tag, 41 | .hljs-name { 42 | color: #e8bf6a; 43 | } 44 | 45 | .hljs-type { 46 | color: #ffc66d; 47 | } 48 | 49 | 50 | .hljs-symbol, 51 | .hljs-bullet, 52 | .hljs-built_in, 53 | .hljs-builtin-name, 54 | .hljs-attr, 55 | .hljs-link { 56 | color: #6d9cbe; 57 | } 58 | 59 | .hljs-params { 60 | color: #d0d0ff; 61 | } 62 | 63 | .hljs-attribute { 64 | color: #cda869; 65 | } 66 | 67 | .hljs-meta { 68 | color: #9b859d; 69 | } 70 | 71 | .hljs-title, 72 | .hljs-section { 73 | color: #ffc66d; 74 | } 75 | 76 | .hljs-addition { 77 | background-color: #144212; 78 | color: #e6e1dc; 79 | display: inline-block; 80 | width: 100%; 81 | } 82 | 83 | .hljs-deletion { 84 | background-color: #600; 85 | color: #e6e1dc; 86 | display: inline-block; 87 | width: 100%; 88 | } 89 | 90 | .hljs-selector-class { 91 | color: #9b703f; 92 | } 93 | 94 | .hljs-selector-id { 95 | color: #8b98ab; 96 | } 97 | 98 | .hljs-emphasis { 99 | font-style: italic; 100 | } 101 | 102 | .hljs-strong { 103 | font-weight: bold; 104 | } 105 | 106 | .hljs-link { 107 | text-decoration: underline; 108 | } 109 | -------------------------------------------------------------------------------- /assertj-generator/src/main/java/org/assertj/assertions/generator/AssertionsEntryPointGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 3 | * the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 9 | * specific language governing permissions and limitations under the License. 10 | * 11 | * Copyright 2012-2025 the original author or authors. 12 | */ 13 | package org.assertj.assertions.generator; 14 | 15 | import org.assertj.assertions.generator.description.ClassDescription; 16 | 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.util.Set; 20 | 21 | public interface AssertionsEntryPointGenerator { 22 | 23 | /** 24 | * Returns the assertions entry point class content for the given 25 | * {@link org.assertj.assertions.generator.description.ClassDescription} set. 26 | *
27 | * The idea is to generate an equivalent of assertj-core Assertions class to give easy access to all generated 28 | * assertions. With {@link AssertionsEntryPointType} parameter one can generate standard, BDD or Soft assertions entry 29 | * point class (default is {@link AssertionsEntryPointType#STANDARD}). 30 | *
31 | * You can define the package of the generated entry point class, if null the common base package of the given
32 | * classes, will be used, i.e if some classe are in a.b.c and others in a.b.c.d, then entry point class will be in
33 | * a.b.c.
34 | *
35 | * @param classDescriptionSet the set of ClassDescription we want to generate an entry point for.
36 | * @param assertionsEntryPointType the valueType of entry point class to generate
37 | * @param entryPointClassPackage the package of the generated entry point class
38 | * @return the assertions entry point class content
39 | */
40 | String generateAssertionsEntryPointClassContentFor(Set
22 | * In the following example, assertions will be generated for thisIsAProperty, anotherProperty and getStuff
23 | * (standard getter):
24 | *
26 | * Let's say we have the following method in class
32 | * To generate
27 | * Let's say we have the following method in class
33 | * To generate
41 | *
42 | * @author Joel Costigliola
43 | *
44 | */
45 | public class GetterDescription extends DataDescription implements Comparable
7 | * Example:
8 | *
7 | * Example:
8 | *
28 | * If difference is equal to the offset value, assertion is considered successful.
29 | * @param ${property_safe} the value to compare the actual ${class_to_assert}'s ${property} to.
30 | * @param assertjOffset the given offset.
31 | * @return this assertion object.
32 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not close enough to the given value.${throws_javadoc}
33 | */
34 | public ${self_type} has${Property}CloseTo(${propertyType} ${property_safe}, ${propertyType} assertjOffset) ${throws}{
35 | // check that actual ${class_to_assert} we want to make assertions on is not null.
36 | isNotNull();
37 |
38 | ${propertyType} actual${Property} = actual.${getter}();
39 |
40 | // overrides the default error message with a more explicit one
41 | String assertjErrorMessage = String.format("\nExpecting ${property}:\n <%s>\nto be close to:\n <%s>\nby less than <%s> but difference was <%s>",
42 | actual${Property}, ${property_safe}, assertjOffset, Math.abs(${property_safe} - actual${Property}));
43 |
44 | // check
45 | Assertions.assertThat(actual${Property}).overridingErrorMessage(assertjErrorMessage).isCloseTo(${property_safe}, Assertions.within(assertjOffset));
46 |
47 | // return the current assertion for method chaining
48 | return ${myself};
49 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_real_number_wrapper.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // null safe check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (!Objects.deepEquals(actual${Property}, ${property_safe})) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
24 |
25 | /**
26 | * Verifies that the actual ${class_to_assert}'s ${property} is close to the given value by less than the given offset.
27 | *
28 | * If difference is equal to the offset value, assertion is considered successful.
29 | * @param ${property_safe} the value to compare the actual ${class_to_assert}'s ${property} to.
30 | * @param assertjOffset the given offset.
31 | * @return this assertion object.
32 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not close enough to the given value.${throws_javadoc}
33 | */
34 | public ${self_type} has${Property}CloseTo(${propertyType} ${property_safe}, ${propertyType} assertjOffset) ${throws}{
35 | // check that actual ${class_to_assert} we want to make assertions on is not null.
36 | isNotNull();
37 |
38 | ${propertyType} actual${Property} = actual.${getter}();
39 |
40 | // overrides the default error message with a more explicit one
41 | String assertjErrorMessage = String.format("\nExpecting ${property}:\n <%s>\nto be close to:\n <%s>\nby less than <%s> but difference was <%s>",
42 | actual${Property}, ${property_safe}, assertjOffset, Math.abs(${property_safe} - actual${Property}));
43 |
44 | // check
45 | Assertions.assertThat(actual${Property}).overridingErrorMessage(assertjErrorMessage).isCloseTo(${property_safe}, Assertions.within(assertjOffset));
46 |
47 | // return the current assertion for method chaining
48 | return ${myself};
49 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_whole_number.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (actual${Property} != ${property_safe}) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_whole_number_wrapper.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // null safe check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (!Objects.deepEquals(actual${Property}, ${property_safe})) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/is_assertion_template.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert} ${predicate_for_javadoc}.
4 | * @return this assertion object.
5 | * @throws AssertionError - if the actual ${class_to_assert} ${negative_predicate_for_javadoc}.${throws_javadoc}
6 | */
7 | public ${self_type} ${predicate}() ${throws}{
8 | // check that actual ${class_to_assert} we want to make assertions on is not null.
9 | isNotNull();
10 |
11 | // check that property call/field access is true
12 | if (!actual.${predicate}()) {
13 | failWithMessage("\nExpecting that actual ${class_to_assert} ${predicate_for_error_message_part1} but ${predicate_for_error_message_part2}.");
14 | }
15 |
16 | // return the current assertion for method chaining
17 | return ${myself};
18 | }
19 |
20 | /**
21 | * Verifies that the actual ${class_to_assert} ${negative_predicate_for_javadoc}.
22 | * @return this assertion object.
23 | * @throws AssertionError - if the actual ${class_to_assert} ${predicate_for_javadoc}.${throws_javadoc}
24 | */
25 | public ${self_type} ${neg_predicate}() ${throws}{
26 | // check that actual ${class_to_assert} we want to make assertions on is not null.
27 | isNotNull();
28 |
29 | // check that property call/field access is false
30 | if (actual.${predicate}()) {
31 | failWithMessage("\nExpecting that actual ${class_to_assert} ${negative_predicate_for_error_message_part1} but ${negative_predicate_for_error_message_part2}.");
32 | }
33 |
34 | // return the current assertion for method chaining
35 | return ${myself};
36 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/is_without_negative_assertion_template.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert} ${predicate_for_javadoc}.
4 | * @return this assertion object.
5 | * @throws AssertionError - if the actual ${class_to_assert} ${negative_predicate_for_javadoc}.${throws_javadoc}
6 | */
7 | public ${self_type} ${predicate}() ${throws}{
8 | // check that actual ${class_to_assert} we want to make assertions on is not null.
9 | isNotNull();
10 |
11 | // check
12 | if (!actual.${predicate}()) {
13 | failWithMessage("\nExpecting that actual ${class_to_assert} ${predicate_for_error_message_part1} but ${predicate_for_error_message_part2}.");
14 | }
15 |
16 | // return the current assertion for method chaining
17 | return ${myself};
18 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/is_wrapper_assertion_template.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert} ${predicate_for_javadoc}.
4 | * @return this assertion object.
5 | * @throws AssertionError - if the actual ${class_to_assert} ${negative_predicate_for_javadoc}.${throws_javadoc}
6 | */
7 | public ${self_type} ${predicate}() ${throws}{
8 | // check that actual ${class_to_assert} we want to make assertions on is not null.
9 | isNotNull();
10 |
11 | // null safe check
12 | if (Objects.deepEquals(Boolean.FALSE, actual.${predicate}())) {
13 | failWithMessage("\nExpecting that actual ${class_to_assert} ${predicate_for_error_message_part1} but ${predicate_for_error_message_part2}.");
14 | }
15 |
16 | // return the current assertion for method chaining
17 | return ${myself};
18 | }
19 |
20 | /**
21 | * Verifies that the actual ${class_to_assert} ${negative_predicate_for_javadoc}.
22 | * @return this assertion object.
23 | * @throws AssertionError - if the actual ${class_to_assert} ${predicate_for_javadoc}.${throws_javadoc}
24 | */
25 | public ${self_type} ${neg_predicate}() ${throws}{
26 | // check that actual ${class_to_assert} we want to make assertions on is not null.
27 | isNotNull();
28 |
29 | // null safe check
30 | if (Objects.deepEquals(Boolean.TRUE, actual.${predicate}())) {
31 | failWithMessage("\nExpecting that actual ${class_to_assert} ${negative_predicate_for_error_message_part1} but ${negative_predicate_for_error_message_part2}.");
32 | }
33 |
34 | // return the current assertion for method chaining
35 | return ${myself};
36 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/is_wrapper_without_negative_assertion_template.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert} ${predicate_for_javadoc}.
4 | * @return this assertion object.
5 | * @throws AssertionError - if the actual ${class_to_assert} ${negative_predicate_for_javadoc}.${throws_javadoc}
6 | */
7 | public ${self_type} ${predicate}() ${throws}{
8 | // check that actual ${class_to_assert} we want to make assertions on is not null.
9 | isNotNull();
10 |
11 | // null safe check
12 | if (Objects.deepEquals(Boolean.FALSE, actual.${predicate}())) {
13 | failWithMessage("\nExpecting that actual ${class_to_assert} ${predicate_for_error_message_part1} but ${predicate_for_error_message_part2}.");
14 | }
15 |
16 | // return the current assertion for method chaining
17 | return ${myself};
18 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/junit_bdd_soft_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Like {@link BDDSoftAssertions} but as a junit rule that takes care of calling
5 | * {@link SoftAssertions#assertAll() assertAll()} at the end of each test.
6 | *
7 | * Example:
8 | *
7 | * Example:
8 | *
45 | * In the next example, assertions will be generated for all methods
46 | * (standard getter):
47 | *
25 | * public class AnnotatedClass {
26 | *
27 | * {@literal @}GenerateAssertion
28 | * public boolean thisIsAProperty() {
29 | * return false;
30 | * }
31 | *
32 | * public boolean thisIsNotAProperty() {
33 | * return false;
34 | * }
35 | *
36 | * public boolean getStuff() {
37 | * return false;
38 | * }
39 | *
40 | * {@literal @}GenerateAssertion
41 | * public Object anotherProperty() {
42 | * return null;
43 | * }
44 | * }
62 | */
63 | @Retention(RetentionPolicy.RUNTIME)
64 | public @interface GenerateAssertion {
65 | }
66 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/java/org/assertj/assertions/generator/TemplateRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator;
14 |
15 | import java.util.HashMap;
16 |
17 | import org.apache.commons.lang3.Validate;
18 |
19 | @SuppressWarnings("serial")
20 | public class TemplateRegistry extends HashMap {@literal @}GenerateAssertion
48 | * public class AnnotatedClass {
49 | *
50 | * public boolean thisIsAProperty() {
51 | * return false;
52 | * }
53 | *
54 | * public boolean getStuff() {
55 | * return false;
56 | * }
57 | *
58 | * public Object anotherProperty() {
59 | * return null;
60 | * }
61 | * }
Person
:
27 | *
28 | *
29 | *
31 | * public int age
30 | * PersonAssert
hasAge(int expectedAge)
assertion in PersonAssert
, we
33 | * need to know :
34 | *
35 | *
39 | * This class is immutable.
40 | *
41 | * @author Joel Costigliola
42 | */
43 | public class FieldDescription extends DataDescription implements ComparablePerson
:
28 | *
29 | *
30 | *
32 | * public int getAge()
31 | * PersonAssert
hasAge(int expectedAge)
assertion in PersonAssert
, we
34 | * need to know :
35 | *
36 | *
39 | * Note that Person
doesn't need to have an age
field, just the getAge
method.
40 | *
23 | */
24 | public class AutoCloseableBDDSoftAssertions extends org.assertj.core.api.BDDSoftAssertions implements AutoCloseable {
25 | ${all_assertions_entry_points}
26 | @Override
27 | public void close() throws SoftAssertionError {
28 | assertAll();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/auto_closeable_soft_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * A version of {@link SoftAssertions} that uses try-with-resources statement to automatically call
5 | * {@link SoftAssertions#assertAll()} so that you don't forget to.
6 | * public class AutoCloseableBDDSoftAssertionsTest {
9 | *
10 | * @Test
11 | * public void host_dinner_party_where_nobody_dies() {
12 | * Mansion mansion = new Mansion();
13 | *
14 | * mansion.hostPotentiallyMurderousDinnerParty();
15 | *
16 | * try (AutoCloseableBDDSoftAssertions softly = new AutoCloseableBDDSoftAssertions()) {
17 | * softly.then(mansion.guests()).as("Living Guests").isEqualTo(7);
18 | * softly.then(mansion.kitchen()).as("Kitchen").isEqualTo("clean");
19 | * // no need to call assertAll, it is done when softly is closed.
20 | * }
21 | * }
22 | *
21 | */
22 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
23 | public class AutoCloseableSoftAssertions extends org.assertj.core.api.SoftAssertions implements AutoCloseable {
24 | ${all_assertions_entry_points}
25 | @Override
26 | public void close() throws org.assertj.core.api.SoftAssertionError {
27 | assertAll();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/bdd_assertion_entry_point_method_template.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * Creates a new instance of public class AutoCloseableSoftAssertionsTest {
9 | *
10 | * @Test
11 | * public void host_dinner_party_where_nobody_dies() {
12 | * Mansion mansion = new Mansion();
13 | * mansion.hostPotentiallyMurderousDinnerParty();
14 | * try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
15 | * softly.assertThat(mansion.guests()).as("Living Guests").isEqualTo(7);
16 | * softly.assertThat(mansion.kitchen()).as("Kitchen").isEqualTo("clean");
17 | * // no need to call assertAll, it is done when softly is closed.
18 | * }
19 | * }
20 | *
{@link ${custom_assertion_class}}
.
3 | *
4 | * @param actual the actual value.
5 | * @return the created assertion object.
6 | */
7 | @org.assertj.core.util.CheckReturnValue
8 | public static ${custom_assertion_class} then(${class_to_assert} actual) {
9 | return new ${custom_assertion_class}(actual);
10 | }
11 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/bdd_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Entry point for BDD assertions of different data types.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public class BddAssertions {
8 | ${all_assertions_entry_points}
9 | /**
10 | * Creates a new {@link BddAssertions}
.
11 | */
12 | protected BddAssertions() {
13 | // empty
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/bdd_soft_assertion_entry_point_method_template.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * Creates a new "soft" instance of {@link ${custom_assertion_class}}
.
3 | *
4 | * @param actual the actual value.
5 | * @return the created "soft" assertion object.
6 | */
7 | @org.assertj.core.util.CheckReturnValue
8 | public ${custom_assertion_class} then(${class_to_assert} actual) {
9 | return proxy(${custom_assertion_class}.class, ${class_to_assert}.class, actual);
10 | }
11 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/bdd_soft_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Entry point for BDD soft assertions of different data types.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public class BDDSoftAssertions extends org.assertj.core.api.BDDSoftAssertions {
8 | ${all_assertions_entry_points}
9 | }
10 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/custom_abstract_assertion_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | ${imports}
3 | /**
4 | * Abstract base class for {@link ${class_to_assert}} specific assertions - Generated by CustomAssertionGenerator.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public abstract class ${custom_assertion_class}, A extends ${class_to_assert}> extends ${super_assertion_class} {
8 |
9 | /**
10 | * Creates a new {@link ${custom_assertion_class}}
to make assertions on actual ${class_to_assert}.
11 | * @param actual the ${class_to_assert} we want to make assertions on.
12 | */
13 | protected ${custom_assertion_class}(A actual, Class selfType) {
14 | super(actual, selfType);
15 | }
16 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/custom_assertion_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | ${imports}
3 | /**
4 | * {@link ${class_to_assert}} specific assertions - Generated by CustomAssertionGenerator.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public class ${custom_assertion_class} extends AbstractObjectAssert<${custom_assertion_class}, ${class_to_assert}> {
8 |
9 | /**
10 | * Creates a new {@link ${custom_assertion_class}}
to make assertions on actual ${class_to_assert}.
11 | * @param actual the ${class_to_assert} we want to make assertions on.
12 | */
13 | public ${custom_assertion_class}(${class_to_assert} actual) {
14 | super(actual, ${custom_assertion_class}.class);
15 | }
16 |
17 | /**
18 | * An entry point for ${custom_assertion_class} to follow AssertJ standard assertThat()
statements.
19 | * With a static import, one can write directly: assertThat(my${class_to_assert})
and get specific assertion with code completion.
20 | * @param actual the ${class_to_assert} we want to make assertions on.
21 | * @return a new {@link ${custom_assertion_class}}
22 | */
23 | @org.assertj.core.util.CheckReturnValue
24 | public static ${custom_assertion_class} assertThat(${class_to_assert} actual) {
25 | return new ${custom_assertion_class}(actual);
26 | }
27 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/custom_hierarchical_assertion_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | ${imports}
3 | /**
4 | * {@link ${class_to_assert}} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link Abstract${custom_assertion_class}} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class ${custom_assertion_class} extends Abstract${custom_assertion_class}<${custom_assertion_class}, ${class_to_assert}> {
11 |
12 | /**
13 | * Creates a new {@link ${custom_assertion_class}}
to make assertions on actual ${class_to_assert}.
14 | * @param actual the ${class_to_assert} we want to make assertions on.
15 | */
16 | public ${custom_assertion_class}(${class_to_assert} actual) {
17 | super(actual, ${custom_assertion_class}.class);
18 | }
19 |
20 | /**
21 | * An entry point for ${custom_assertion_class} to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(my${class_to_assert})
and get specific assertion with code completion.
23 | * @param actual the ${class_to_assert} we want to make assertions on.
24 | * @return a new {@link ${custom_assertion_class}}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static ${custom_assertion_class} assertThat(${class_to_assert} actual) {
28 | return new ${custom_assertion_class}(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // null safe check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (!Objects.deepEquals(actual${Property}, ${property_safe})) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_char.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // check ${property} char matches
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (actual${Property} != ${property_safe}) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_character.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // null safe check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (!Objects.deepEquals(actual${Property}, ${property_safe})) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_primitive.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (actual${Property} != ${property_safe}) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_primitive_wrapper.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // null safe check
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (!Objects.deepEquals(actual${Property}, ${property_safe})) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/has_assertion_template_for_real_number.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | // overrides the default error message with a more explicit one
13 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
14 |
15 | // check value for ${property}
16 | ${propertyType} actual${Property} = actual.${getter}();
17 | if (actual${Property} != ${property_safe}) {
18 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
19 | }
20 |
21 | // return the current assertion for method chaining
22 | return ${myself};
23 | }
24 |
25 | /**
26 | * Verifies that the actual ${class_to_assert}'s ${property} is close to the given value by less than the given offset.
27 | *
20 | */
21 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
22 | public class JUnitBDDSoftAssertions extends org.assertj.core.api.JUnitBDDSoftAssertions {
23 | ${all_assertions_entry_points}
24 | }
25 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/junit_soft_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Like {@link SoftAssertions} but as a junit rule that takes care of calling
5 | * {@link SoftAssertions#assertAll() assertAll()} at the end of each test.
6 | * public class SoftlyTest {
9 | *
10 | * @Rule
11 | * public final JUnitBDDSoftAssertions softly = new JUnitBDDSoftAssertions();
12 | *
13 | * @Test
14 | * public void soft_bdd_assertions() throws Exception {
15 | * softly.then(1).isEqualTo(2);
16 | * softly.then(Lists.newArrayList(1, 2)).containsOnly(1, 2);
17 | * // no need to call assertAll(), this is done automatically.
18 | * }
19 | * }
20 | */
21 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
22 | public class JUnitSoftAssertions extends org.assertj.core.api.JUnitSoftAssertions {
23 | ${all_assertions_entry_points}
24 | }
25 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/soft_assertion_entry_point_method_template.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * Creates a new "soft" instance of public class SoftlyTest {
9 | *
10 | * @Rule
11 | * public final JUnitBDDSoftAssertions softly = new JUnitBDDSoftAssertions();
12 | *
13 | * @Test
14 | * public void soft_bdd_assertions() throws Exception {
15 | * softly.assertThat(1).isEqualTo(2);
16 | * softly.assertThat(Lists.newArrayList(1, 2)).containsOnly(1, 2);
17 | * // no need to call assertAll(), this is done automatically.
18 | * }
19 | * }
{@link ${custom_assertion_class}}
.
3 | *
4 | * @param actual the actual value.
5 | * @return the created "soft" assertion object.
6 | */
7 | @org.assertj.core.util.CheckReturnValue
8 | public ${custom_assertion_class} assertThat(${class_to_assert} actual) {
9 | return proxy(${custom_assertion_class}.class, ${class_to_assert}.class, actual);
10 | }
11 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/soft_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Entry point for soft assertions of different data types.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public class SoftAssertions extends org.assertj.core.api.SoftAssertions {
8 | ${all_assertions_entry_points}
9 | }
10 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/standard_assertion_entry_point_method_template.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * Creates a new instance of {@link ${custom_assertion_class}}
.
3 | *
4 | * @param actual the actual value.
5 | * @return the created assertion object.
6 | */
7 | @org.assertj.core.util.CheckReturnValue
8 | public static ${custom_assertion_class} assertThat(${class_to_assert} actual) {
9 | return new ${custom_assertion_class}(actual);
10 | }
11 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/resources/templates/standard_assertions_entry_point_class_template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Entry point for assertions of different data types. Each method in this class is a static factory for the
5 | * type-specific assertion objects.
6 | */
7 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
8 | public class Assertions {
9 | ${all_assertions_entry_points}
10 | /**
11 | * Creates a new {@link Assertions}
.
12 | */
13 | protected Assertions() {
14 | // empty
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/assertj-generator/src/main/scripts/build.gradle:
--------------------------------------------------------------------------------
1 | // use assertj generator from gradle example
2 |
3 | def assertjOutput = file('src-gen/test/java')
4 |
5 | configurations {
6 | assertj
7 | }
8 |
9 | dependencies {
10 | testCompile 'org.assertj:assertj-core:3.2.0'
11 |
12 | assertj 'org.assertj:assertj-assertions-generator:2.0.0'
13 | assertj project(':bacsapp:metadata')
14 | }
15 |
16 | sourceSets {
17 | test {
18 | java {
19 | srcDir 'src/test/java'
20 | srcDir 'src-gen/test/java'
21 | }
22 | }
23 | }
24 |
25 | task assertjClean(type: Delete) {
26 | delete assertjOutput
27 | }
28 |
29 | task assertjGen(dependsOn: assertjClean, type: JavaExec) {
30 | doFirst {
31 | if (!assertjOutput.exists()) {
32 | logger.info("Creating `$assertjOutput` directory")
33 |
34 | if (!assertjOutput.mkdirs()) {
35 | throw new InvalidUserDataException("Unable to create `$assertjOutput` directory")
36 | }
37 | }
38 | }
39 |
40 | main 'org.assertj.assertions.generator.cli.AssertionGeneratorLauncher'
41 | classpath = files(configurations.assertj)
42 | workingDir = assertjOutput
43 | args = [
44 | // TODO: instear FQCN or FQPN
45 | ]
46 | }
47 |
48 | compileTestJava.dependsOn(assertjGen)
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/my/assertions/OuterClassStaticNestedPersonAssert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package my.assertions;
14 |
15 | import java.util.Objects;
16 | import org.assertj.assertions.generator.data.OuterClass;
17 | import org.assertj.core.api.AbstractObjectAssert;
18 |
19 | /**
20 | * this class was generated but kep in source control to see what was needed in term of import when dealing with nested classes
21 | */
22 | @javax.annotation.processing.Generated(value = "assertj-assertions-generator")
23 | public class OuterClassStaticNestedPersonAssert
24 | extends AbstractObjectAssert{@link OuterClassStaticNestedPersonAssert}
to make assertions on actual OuterClass.StaticNestedPerson.
28 | * @param actual the OuterClass.StaticNestedPerson we want to make assertions on.
29 | */
30 | public OuterClassStaticNestedPersonAssert(OuterClass.StaticNestedPerson actual) {
31 | super(actual, OuterClassStaticNestedPersonAssert.class);
32 | }
33 |
34 | /**
35 | * An entry point for OuterClassStaticNestedPersonAssert to follow AssertJ standard assertThat()
statements.
36 | * With a static import, one can write directly: assertThat(myOuterClass.StaticNestedPerson)
and get specific assertion with code completion.
37 | * @param actual the OuterClass.StaticNestedPerson we want to make assertions on.
38 | * @return a new {@link OuterClassStaticNestedPersonAssert}
39 | */
40 | @org.assertj.core.util.CheckReturnValue
41 | public static OuterClassStaticNestedPersonAssert assertThat(OuterClass.StaticNestedPerson actual) {
42 | OuterClass.StaticNestedPerson.SNP_InnerPerson d = null;
43 | OuterClass.StaticNestedPerson.SNP_StaticNestedPerson f = null;
44 | return new OuterClassStaticNestedPersonAssert(actual);
45 | }
46 |
47 | /**
48 | * Verifies that the actual OuterClass.StaticNestedPerson's name is equal to the given one.
49 | * @param name the given name to compare the actual OuterClass.StaticNestedPerson's name to.
50 | * @return this assertion object.
51 | * @throws AssertionError - if the actual OuterClass.StaticNestedPerson's name is not equal to the given one.
52 | */
53 | public OuterClassStaticNestedPersonAssert hasName(String name) {
54 | // check that actual OuterClass.StaticNestedPerson we want to make assertions on is not null.
55 | isNotNull();
56 |
57 | // overrides the default error message with a more explicit one
58 | String assertjErrorMessage = "\nExpecting name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
59 |
60 | // null safe check
61 | String actualName = actual.getName();
62 | if (!Objects.deepEquals(actualName, name)) {
63 | failWithMessage(assertjErrorMessage, actual, name, actualName);
64 | }
65 |
66 | // return the current assertion for method chaining
67 | return this;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/AssertionGeneratorOverrideTemplateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator;
14 |
15 | import org.assertj.assertions.generator.data.cars.Car;
16 | import org.assertj.assertions.generator.description.converter.ClassToClassDescriptionConverter;
17 | import org.junit.jupiter.api.BeforeEach;
18 | import org.junit.jupiter.api.Test;
19 | import org.junit.jupiter.api.io.TempDir;
20 |
21 | import java.io.File;
22 | import java.io.IOException;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 |
26 | import static org.assertj.assertions.generator.Template.Type.ABSTRACT_ASSERT_CLASS;
27 | import static org.assertj.core.api.Assertions.assertThat;
28 | import static org.assertj.core.api.Assertions.assertThatNullPointerException;
29 | import static org.assertj.core.api.Assertions.assertThatRuntimeException;
30 |
31 | class AssertionGeneratorOverrideTemplateTest {
32 |
33 | private BaseAssertionGenerator assertionGenerator;
34 | private ClassToClassDescriptionConverter converter;
35 | private GenerationHandler genHandle;
36 |
37 | @BeforeEach
38 | void before(@TempDir Path tempDir) throws IOException {
39 | assertionGenerator = new BaseAssertionGenerator();
40 | assertionGenerator.setDirectoryWhereAssertionFilesAreGenerated(tempDir.toFile());
41 | converter = new ClassToClassDescriptionConverter();
42 | genHandle = new GenerationHandler(tempDir, Paths.get("src/test/resources"));
43 | }
44 |
45 | @Test
46 | void should_fail_if_custom_template_is_null() {
47 | assertThatNullPointerException().isThrownBy(() -> assertionGenerator.register(null));
48 | }
49 |
50 | @Test
51 | void should_fail_if_custom_template_content_is_null() {
52 | assertThatNullPointerException().isThrownBy(() -> assertionGenerator.register(new Template(ABSTRACT_ASSERT_CLASS, (File) null)));
53 | }
54 |
55 | @Test
56 | void should_fail_if_custom_template_content_cant_be_read() {
57 | assertThatRuntimeException().isThrownBy(() -> assertionGenerator.register(new Template(ABSTRACT_ASSERT_CLASS, new File("not_existing.template"))));
58 | }
59 |
60 | @Test
61 | void should_generate_assertion_with_custom_template() throws IOException {
62 | assertionGenerator.register(new Template(Template.Type.HAS_FOR_WHOLE_NUMBER,
63 | new File("customtemplates" + File.separator,
64 | "custom_has_assertion_template_for_whole_number.txt")));
65 |
66 | assertionGenerator.generateCustomAssertionFor(converter.convertToClassDescription(Car.class));
67 | File expectedFile = genHandle.getResourcesDir().resolve("CarAssert.expected.txt").toAbsolutePath().toFile();
68 | File actualFile = genHandle.fileGeneratedFor(Car.class);
69 | // compile it!
70 | genHandle.compileGeneratedFilesFor(Car.class);
71 |
72 | assertThat(actualFile).hasSameTextualContentAs(expectedFile);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/ClassUsingDifferentClassesWithSameName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator;
14 |
15 | // used in test - getters implemntation don't matter
16 | public class ClassUsingDifferentClassesWithSameName {
17 | public org.assertj.assertions.generator.data.nba.team.Team getNbaTeam() {
18 | return null;
19 | }
20 |
21 | public org.assertj.assertions.generator.data.Team getTeam() {
22 | return null;
23 | }
24 | }
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/PlayerAssertTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator;
14 |
15 | // import static org.assertj.assertions.generator.data.PlayerAssert.assertThat;
16 |
17 | import org.junit.jupiter.api.Test;
18 |
19 | public class PlayerAssertTest {
20 |
21 | @Test
22 | void test() {
23 | // uncomment to test
24 | // Player tonyParker = new Player(new Name("Tony", "Parker"), "Spurs");
25 | // tonyParker.setAssistsPerGame(9);
26 | // tonyParker.setPointsPerGame(21);
27 | // tonyParker.setReboundsPerGame(5);
28 | // tonyParker.setPreviousTeams(new String[] { "paris" });
29 | // Player tim = new Player(new Name("Tim", "Duncan"), "Spurs");
30 | // tonyParker.getTeamMates().add(tim);
31 | //
32 | // assertThat(tonyParker).isNotRookie()
33 | // .hasTeam("paris")
34 | // .hasTeamMates(new Player(new Name("Kobe", "Bryant"), "Lakers"), tim)
35 | // .hasTeam("spurs")
36 | // .hasPreviousTeams("paris")
37 | // .hasPointsPerGame(21);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/TemplateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator;
14 |
15 | import org.junit.jupiter.api.Test;
16 |
17 | import static org.assertj.assertions.generator.BaseAssertionGenerator.TEMPLATES_DIR;
18 | import static org.assertj.assertions.generator.DefaultTemplateRegistryProducer.DEFAULT_HAS_ASSERTION_TEMPLATE;
19 | import static org.assertj.assertions.generator.Template.Type.ASSERT_CLASS;
20 | import static org.assertj.assertions.generator.Template.Type.HAS;
21 | import static org.assertj.core.api.Assertions.assertThat;
22 | import static org.assertj.core.api.Assertions.fail;
23 |
24 | import java.io.File;
25 | import java.net.URL;
26 |
27 | class TemplateTest {
28 |
29 | @Test
30 | void should_throw_an_exception_when_url_is_a_directory() {
31 | URL templateURL = getClass().getClassLoader().getResource(TEMPLATES_DIR);
32 | try {
33 | new Template(ASSERT_CLASS, templateURL);
34 | fail("A directory url should throw an exception");
35 | } catch (RuntimeException e) {
36 | assertThat(e).hasMessageStartingWith("Failed to read template from an URL which is not a file");
37 | }
38 | }
39 |
40 | @Test
41 | void should_create_template_from_url() {
42 | URL templateURL = getClass().getClassLoader().getResource(TEMPLATES_DIR + DEFAULT_HAS_ASSERTION_TEMPLATE);
43 | Template template = new Template(ASSERT_CLASS, templateURL);
44 | assertThat(template.getContent()).isNotEmpty();
45 | }
46 |
47 | @Test
48 | void should_create_template_from_file() {
49 | File templateFile = new File(TEMPLATES_DIR, DEFAULT_HAS_ASSERTION_TEMPLATE);
50 | Template template = new Template(HAS, templateFile);
51 | assertThat(template.getContent()).isNotEmpty();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/data/AnnotatedClass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator.data;
14 |
15 | import org.assertj.assertions.generator.GenerateAssertion;
16 |
17 | /**
18 | * class with annotated non standard getters in order to generate assertions for them.
19 | */
20 | public class AnnotatedClass {
21 |
22 | @GenerateAssertion
23 | public boolean thisIsAProperty() {
24 | return false;
25 | }
26 |
27 | public boolean thisIsNotAProperty() {
28 | return false;
29 | }
30 |
31 | // assertion will be generated as this is a standard getter
32 | public boolean getStuff() {
33 | return false;
34 | }
35 |
36 | @GenerateAssertion
37 | public Object anotherProperty() {
38 | return null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/data/AutoValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator.data;
14 |
15 | import java.lang.annotation.Retention;
16 | import java.lang.annotation.RetentionPolicy;
17 |
18 | @Retention(RetentionPolicy.RUNTIME)
19 | public @interface AutoValue {
20 | }
21 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/data/AutoValueAnnotatedClass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator.data;
14 |
15 | @AutoValue
16 | public class AutoValueAnnotatedClass {
17 |
18 | public boolean thisIsAProperty() {
19 | return false;
20 | }
21 |
22 | // assertion will be generated as this is a standard getter
23 | public boolean getStuff() {
24 | return false;
25 | }
26 |
27 | public Object anotherProperty() {
28 | return null;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/java/org/assertj/assertions/generator/data/BeanWithOneException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3 | * the License. You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 | * specific language governing permissions and limitations under the License.
10 | *
11 | * Copyright 2012-2025 the original author or authors.
12 | */
13 | package org.assertj.assertions.generator.data;
14 |
15 | import java.io.IOException;
16 | import java.util.List;
17 |
18 | /**
19 | * This is a bean whose getters throws one exception.
20 | */
21 | public class BeanWithOneException {
22 | @SuppressWarnings("unused")
23 | public String getStringPropertyThrowsException() throws IOException {
24 | return null;
25 | }
26 |
27 | @SuppressWarnings("unused")
28 | public boolean isBooleanPropertyThrowsException() throws IOException {
29 | return false;
30 | }
31 |
32 | @SuppressWarnings("unused")
33 | public String[] getArrayPropertyThrowsException() throws IOException {
34 | return null;
35 | }
36 |
37 | @SuppressWarnings("unused")
38 | public List, A extends ArtWork> extends AbstractObjectAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractArtWorkAssert}
to make assertions on actual ArtWork.
14 | * @param actual the ArtWork we want to make assertions on.
15 | */
16 | protected AbstractArtWorkAssert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual ArtWork's title is equal to the given one.
22 | * @param title the given title to compare the actual ArtWork's title to.
23 | * @return this assertion object.
24 | * @throws AssertionError - if the actual ArtWork's title is not equal to the given one.
25 | */
26 | public S hasTitle(String title) {
27 | // check that actual ArtWork we want to make assertions on is not null.
28 | isNotNull();
29 |
30 | // overrides the default error message with a more explicit one
31 | String assertjErrorMessage = "\nExpecting title of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
32 |
33 | // null safe check
34 | String actualTitle = actual.getTitle();
35 | if (!Objects.deepEquals(actualTitle, title)) {
36 | failWithMessage(assertjErrorMessage, actual, title, actualTitle);
37 | }
38 |
39 | // return the current assertion for method chaining
40 | return myself;
41 | }
42 |
43 | /**
44 | * Verifies that the actual ArtWork's creator is equal to the given one.
45 | * @param creator the given creator to compare the actual ArtWork's creator to.
46 | * @return this assertion object.
47 | * @throws AssertionError - if the actual ArtWork's creator is not equal to the given one.
48 | */
49 | public S hasCreator(String creator) {
50 | // check that actual ArtWork we want to make assertions on is not null.
51 | isNotNull();
52 |
53 | // overrides the default error message with a more explicit one
54 | String assertjErrorMessage = "\nExpecting creator of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
55 |
56 | // null safe check
57 | String actualCreator = actual.creator;
58 | if (!Objects.deepEquals(actualCreator, creator)) {
59 | failWithMessage(assertjErrorMessage, actual, creator, actualCreator);
60 | }
61 |
62 | // return the current assertion for method chaining
63 | return myself;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractBlockBusterAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * Abstract base class for {@link BlockBuster} specific assertions - Generated by CustomAssertionGenerator.
5 | */
6 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
7 | public abstract class AbstractBlockBusterAssert, A extends BlockBuster> extends AbstractMovieAssert {
8 |
9 | /**
10 | * Creates a new {@link AbstractBlockBusterAssert}
to make assertions on actual BlockBuster.
11 | * @param actual the BlockBuster we want to make assertions on.
12 | */
13 | protected AbstractBlockBusterAssert(A actual, Class selfType) {
14 | super(actual, selfType);
15 | }
16 |
17 | /**
18 | * Verifies that the actual BlockBuster's revenue is equal to the given one.
19 | * @param revenue the given revenue to compare the actual BlockBuster's revenue to.
20 | * @return this assertion object.
21 | * @throws AssertionError - if the actual BlockBuster's revenue is not equal to the given one.
22 | */
23 | public S hasRevenue(int revenue) {
24 | // check that actual BlockBuster we want to make assertions on is not null.
25 | isNotNull();
26 |
27 | // overrides the default error message with a more explicit one
28 | String assertjErrorMessage = "\nExpecting revenue of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
29 |
30 | // check
31 | int actualRevenue = actual.getRevenue();
32 | if (actualRevenue != revenue) {
33 | failWithMessage(assertjErrorMessage, actual, revenue, actualRevenue);
34 | }
35 |
36 | // return the current assertion for method chaining
37 | return myself;
38 | }
39 |
40 | /**
41 | * Verifies that the actual BlockBuster's numberOfSpectators is equal to the given one.
42 | * @param numberOfSpectators the given numberOfSpectators to compare the actual BlockBuster's numberOfSpectators to.
43 | * @return this assertion object.
44 | * @throws AssertionError - if the actual BlockBuster's numberOfSpectators is not equal to the given one.
45 | */
46 | public S hasNumberOfSpectators(int numberOfSpectators) {
47 | // check that actual BlockBuster we want to make assertions on is not null.
48 | isNotNull();
49 |
50 | // overrides the default error message with a more explicit one
51 | String assertjErrorMessage = "\nExpecting numberOfSpectators of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
52 |
53 | // check
54 | int actualNumberOfSpectators = actual.numberOfSpectators;
55 | if (actualNumberOfSpectators != numberOfSpectators) {
56 | failWithMessage(assertjErrorMessage, actual, numberOfSpectators, actualNumberOfSpectators);
57 | }
58 |
59 | // return the current assertion for method chaining
60 | return myself;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractClassUsingDifferentClassesWithSameNameAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * Abstract base class for {@link ClassUsingDifferentClassesWithSameName} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public abstract class AbstractClassUsingDifferentClassesWithSameNameAssert, A extends ClassUsingDifferentClassesWithSameName> extends AbstractObjectAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractClassUsingDifferentClassesWithSameNameAssert}
to make assertions on actual ClassUsingDifferentClassesWithSameName.
14 | * @param actual the ClassUsingDifferentClassesWithSameName we want to make assertions on.
15 | */
16 | protected AbstractClassUsingDifferentClassesWithSameNameAssert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual ClassUsingDifferentClassesWithSameName's nbaTeam is equal to the given one.
22 | * @param nbaTeam the given nbaTeam to compare the actual ClassUsingDifferentClassesWithSameName's nbaTeam to.
23 | * @return this assertion object.
24 | * @throws AssertionError - if the actual ClassUsingDifferentClassesWithSameName's nbaTeam is not equal to the given one.
25 | */
26 | public S hasNbaTeam(org.assertj.assertions.generator.data.nba.team.Team nbaTeam) {
27 | // check that actual ClassUsingDifferentClassesWithSameName we want to make assertions on is not null.
28 | isNotNull();
29 |
30 | // overrides the default error message with a more explicit one
31 | String assertjErrorMessage = "\nExpecting nbaTeam of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
32 |
33 | // null safe check
34 | org.assertj.assertions.generator.data.nba.team.Team actualNbaTeam = actual.getNbaTeam();
35 | if (!Objects.deepEquals(actualNbaTeam, nbaTeam)) {
36 | failWithMessage(assertjErrorMessage, actual, nbaTeam, actualNbaTeam);
37 | }
38 |
39 | // return the current assertion for method chaining
40 | return myself;
41 | }
42 |
43 | /**
44 | * Verifies that the actual ClassUsingDifferentClassesWithSameName's team is equal to the given one.
45 | * @param team the given team to compare the actual ClassUsingDifferentClassesWithSameName's team to.
46 | * @return this assertion object.
47 | * @throws AssertionError - if the actual ClassUsingDifferentClassesWithSameName's team is not equal to the given one.
48 | */
49 | public S hasTeam(org.assertj.assertions.generator.data.Team team) {
50 | // check that actual ClassUsingDifferentClassesWithSameName we want to make assertions on is not null.
51 | isNotNull();
52 |
53 | // overrides the default error message with a more explicit one
54 | String assertjErrorMessage = "\nExpecting team of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
55 |
56 | // null safe check
57 | org.assertj.assertions.generator.data.Team actualTeam = actual.getTeam();
58 | if (!Objects.deepEquals(actualTeam, team)) {
59 | failWithMessage(assertjErrorMessage, actual, team, actualTeam);
60 | }
61 |
62 | // return the current assertion for method chaining
63 | return myself;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractDollar$Assert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * Abstract base class for {@link Dollar$} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public abstract class AbstractDollar$Assert, A extends Dollar$> extends AbstractObjectAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractDollar$Assert}
to make assertions on actual Dollar$.
14 | * @param actual the Dollar$ we want to make assertions on.
15 | */
16 | protected AbstractDollar$Assert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual Dollar$'s test is equal to the given one.
22 | * @param test the given test to compare the actual Dollar$'s test to.
23 | * @return this assertion object.
24 | * @throws AssertionError - if the actual Dollar$'s test is not equal to the given one.
25 | */
26 | public S hasTest(String test) {
27 | // check that actual Dollar$ we want to make assertions on is not null.
28 | isNotNull();
29 |
30 | // overrides the default error message with a more explicit one
31 | String assertjErrorMessage = "\nExpecting test of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
32 |
33 | // null safe check
34 | String actualTest = actual.test;
35 | if (!Objects.deepEquals(actualTest, test)) {
36 | failWithMessage(assertjErrorMessage, actual, test, actualTest);
37 | }
38 |
39 | // return the current assertion for method chaining
40 | return myself;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractInterferencePrimitivesAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * Abstract base class for {@link InterferencePrimitives} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public abstract class AbstractInterferencePrimitivesAssert, A extends InterferencePrimitives> extends AbstractObjectAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractInterferencePrimitivesAssert}
to make assertions on actual InterferencePrimitives.
14 | * @param actual the InterferencePrimitives we want to make assertions on.
15 | */
16 | protected AbstractInterferencePrimitivesAssert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual InterferencePrimitives is a boolean.
22 | * @return this assertion object.
23 | * @throws AssertionError - if the actual InterferencePrimitives is not a boolean.
24 | */
25 | public S isABoolean() {
26 | // check that actual InterferencePrimitives we want to make assertions on is not null.
27 | isNotNull();
28 |
29 | // null safe check
30 | if (Objects.deepEquals(Boolean.FALSE, actual.isABoolean())) {
31 | failWithMessage("\nExpecting that actual InterferencePrimitives is a boolean but is not.");
32 | }
33 |
34 | // return the current assertion for method chaining
35 | return myself;
36 | }
37 |
38 | /**
39 | * Verifies that the actual InterferencePrimitives is not a boolean.
40 | * @return this assertion object.
41 | * @throws AssertionError - if the actual InterferencePrimitives is a boolean.
42 | */
43 | public S isNotABoolean() {
44 | // check that actual InterferencePrimitives we want to make assertions on is not null.
45 | isNotNull();
46 |
47 | // null safe check
48 | if (Objects.deepEquals(Boolean.FALSE, actual.isNotABoolean())) {
49 | failWithMessage("\nExpecting that actual InterferencePrimitives is not a boolean but is.");
50 | }
51 |
52 | // return the current assertion for method chaining
53 | return myself;
54 | }
55 |
56 | /**
57 | * Verifies that the actual InterferencePrimitives is not working.
58 | * @return this assertion object.
59 | * @throws AssertionError - if the actual InterferencePrimitives is working.
60 | */
61 | public S isNotWorking() {
62 | // check that actual InterferencePrimitives we want to make assertions on is not null.
63 | isNotNull();
64 |
65 | // check
66 | if (!actual.isNotWorking()) {
67 | failWithMessage("\nExpecting that actual InterferencePrimitives is not working but is.");
68 | }
69 |
70 | // return the current assertion for method chaining
71 | return myself;
72 | }
73 |
74 | /**
75 | * Verifies that the actual InterferencePrimitives is working.
76 | * @return this assertion object.
77 | * @throws AssertionError - if the actual InterferencePrimitives is not working.
78 | */
79 | public S isWorking() {
80 | // check that actual InterferencePrimitives we want to make assertions on is not null.
81 | isNotNull();
82 |
83 | // check
84 | if (!actual.isWorking()) {
85 | failWithMessage("\nExpecting that actual InterferencePrimitives is working but is not.");
86 | }
87 |
88 | // return the current assertion for method chaining
89 | return myself;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractNameAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractComparableAssert;
5 |
6 | /**
7 | * Abstract base class for {@link Name} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public abstract class AbstractNameAssert, A extends Name> extends AbstractComparableAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractNameAssert}
to make assertions on actual Name.
14 | * @param actual the Name we want to make assertions on.
15 | */
16 | protected AbstractNameAssert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual Name's first is equal to the given one.
22 | * @param first the given first to compare the actual Name's first to.
23 | * @return this assertion object.
24 | * @throws AssertionError - if the actual Name's first is not equal to the given one.
25 | */
26 | public S hasFirst(String first) {
27 | // check that actual Name we want to make assertions on is not null.
28 | isNotNull();
29 |
30 | // overrides the default error message with a more explicit one
31 | String assertjErrorMessage = "\nExpecting first of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
32 |
33 | // null safe check
34 | String actualFirst = actual.getFirst();
35 | if (!Objects.deepEquals(actualFirst, first)) {
36 | failWithMessage(assertjErrorMessage, actual, first, actualFirst);
37 | }
38 |
39 | // return the current assertion for method chaining
40 | return myself;
41 | }
42 |
43 | /**
44 | * Verifies that the actual Name's last is equal to the given one.
45 | * @param last the given last to compare the actual Name's last to.
46 | * @return this assertion object.
47 | * @throws AssertionError - if the actual Name's last is not equal to the given one.
48 | */
49 | public S hasLast(String last) {
50 | // check that actual Name we want to make assertions on is not null.
51 | isNotNull();
52 |
53 | // overrides the default error message with a more explicit one
54 | String assertjErrorMessage = "\nExpecting last of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
55 |
56 | // null safe check
57 | String actualLast = actual.getLast();
58 | if (!Objects.deepEquals(actualLast, last)) {
59 | failWithMessage(assertjErrorMessage, actual, last, actualLast);
60 | }
61 |
62 | // return the current assertion for method chaining
63 | return myself;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractOptionalAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package com.google.common.base;
2 |
3 | import org.assertj.core.api.AbstractObjectAssert;
4 |
5 | /**
6 | * Abstract base class for {@link Optional} specific assertions - Generated by CustomAssertionGenerator.
7 | */
8 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
9 | public abstract class AbstractOptionalAssert, A extends Optional> extends AbstractObjectAssert {
10 |
11 | /**
12 | * Creates a new {@link AbstractOptionalAssert}
to make assertions on actual Optional.
13 | * @param actual the Optional we want to make assertions on.
14 | */
15 | protected AbstractOptionalAssert(A actual, Class selfType) {
16 | super(actual, selfType);
17 | }
18 |
19 | /**
20 | * Verifies that the actual Optional is present.
21 | * @return this assertion object.
22 | * @throws AssertionError - if the actual Optional is not present.
23 | */
24 | public S isPresent() {
25 | // check that actual Optional we want to make assertions on is not null.
26 | isNotNull();
27 |
28 | // check that property call/field access is true
29 | if (!actual.isPresent()) {
30 | failWithMessage("\nExpecting that actual Optional is present but is not.");
31 | }
32 |
33 | // return the current assertion for method chaining
34 | return myself;
35 | }
36 |
37 | /**
38 | * Verifies that the actual Optional is not present.
39 | * @return this assertion object.
40 | * @throws AssertionError - if the actual Optional is present.
41 | */
42 | public S isNotPresent() {
43 | // check that actual Optional we want to make assertions on is not null.
44 | isNotNull();
45 |
46 | // check that property call/field access is false
47 | if (actual.isPresent()) {
48 | failWithMessage("\nExpecting that actual Optional is not present but is.");
49 | }
50 |
51 | // return the current assertion for method chaining
52 | return myself;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractPlayerAgentAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.nba;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * Abstract base class for {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public abstract class AbstractPlayerAgentAssert, A extends PlayerAgent> extends AbstractObjectAssert {
11 |
12 | /**
13 | * Creates a new {@link AbstractPlayerAgentAssert}
to make assertions on actual PlayerAgent.
14 | * @param actual the PlayerAgent we want to make assertions on.
15 | */
16 | protected AbstractPlayerAgentAssert(A actual, Class selfType) {
17 | super(actual, selfType);
18 | }
19 |
20 | /**
21 | * Verifies that the actual PlayerAgent's managedPlayer is equal to the given one.
22 | * @param managedPlayer the given managedPlayer to compare the actual PlayerAgent's managedPlayer to.
23 | * @return this assertion object.
24 | * @throws AssertionError - if the actual PlayerAgent's managedPlayer is not equal to the given one.
25 | */
26 | public S hasManagedPlayer(Player managedPlayer) {
27 | // check that actual PlayerAgent we want to make assertions on is not null.
28 | isNotNull();
29 |
30 | // overrides the default error message with a more explicit one
31 | String assertjErrorMessage = "\nExpecting managedPlayer of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
32 |
33 | // null safe check
34 | Player actualManagedPlayer = actual.getManagedPlayer();
35 | if (!Objects.deepEquals(actualManagedPlayer, managedPlayer)) {
36 | failWithMessage(assertjErrorMessage, actual, managedPlayer, actualManagedPlayer);
37 | }
38 |
39 | // return the current assertion for method chaining
40 | return myself;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AbstractPlayerAgentAssert.generated.in.custom.package.expected.txt:
--------------------------------------------------------------------------------
1 | package my.assertions;
2 |
3 | import java.util.Objects;
4 | import org.assertj.assertions.generator.data.nba.PlayerAgent;
5 | import org.assertj.core.api.AbstractObjectAssert;
6 |
7 | /**
8 | * Abstract base class for {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
9 | */
10 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
11 | public abstract class AbstractPlayerAgentAssert, A extends PlayerAgent> extends AbstractObjectAssert {
12 |
13 | /**
14 | * Creates a new {@link AbstractPlayerAgentAssert}
to make assertions on actual PlayerAgent.
15 | * @param actual the PlayerAgent we want to make assertions on.
16 | */
17 | protected AbstractPlayerAgentAssert(A actual, Class selfType) {
18 | super(actual, selfType);
19 | }
20 |
21 | /**
22 | * Verifies that the actual PlayerAgent's managedPlayer is equal to the given one.
23 | * @param managedPlayer the given managedPlayer to compare the actual PlayerAgent's managedPlayer to.
24 | * @return this assertion object.
25 | * @throws AssertionError - if the actual PlayerAgent's managedPlayer is not equal to the given one.
26 | */
27 | public S hasManagedPlayer(org.assertj.assertions.generator.data.nba.Player managedPlayer) {
28 | // check that actual PlayerAgent we want to make assertions on is not null.
29 | isNotNull();
30 |
31 | // overrides the default error message with a more explicit one
32 | String assertjErrorMessage = "\nExpecting managedPlayer of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
33 |
34 | // null safe check
35 | org.assertj.assertions.generator.data.nba.Player actualManagedPlayer = actual.getManagedPlayer();
36 | if (!Objects.deepEquals(actualManagedPlayer, managedPlayer)) {
37 | failWithMessage(assertjErrorMessage, actual, managedPlayer, actualManagedPlayer);
38 | }
39 |
40 | // return the current assertion for method chaining
41 | return myself;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AnnotatedClassAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link AnnotatedClass} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractAnnotatedClassAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class AnnotatedClassAssert extends AbstractAnnotatedClassAssert{@link AnnotatedClassAssert}
to make assertions on actual AnnotatedClass.
14 | * @param actual the AnnotatedClass we want to make assertions on.
15 | */
16 | public AnnotatedClassAssert(AnnotatedClass actual) {
17 | super(actual, AnnotatedClassAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for AnnotatedClassAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myAnnotatedClass)
and get specific assertion with code completion.
23 | * @param actual the AnnotatedClass we want to make assertions on.
24 | * @return a new {@link AnnotatedClassAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static AnnotatedClassAssert assertThat(AnnotatedClass actual) {
28 | return new AnnotatedClassAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/ArtWorkAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.art;
2 |
3 | /**
4 | * {@link ArtWork} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractArtWorkAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class ArtWorkAssert extends AbstractArtWorkAssert{@link ArtWorkAssert}
to make assertions on actual ArtWork.
14 | * @param actual the ArtWork we want to make assertions on.
15 | */
16 | public ArtWorkAssert(ArtWork actual) {
17 | super(actual, ArtWorkAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for ArtWorkAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myArtWork)
and get specific assertion with code completion.
23 | * @param actual the ArtWork we want to make assertions on.
24 | * @return a new {@link ArtWorkAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static ArtWorkAssert assertThat(ArtWork actual) {
28 | return new ArtWorkAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AssertionsForClassesWithSameName.expected.txt:
--------------------------------------------------------------------------------
1 | package org;
2 |
3 | /**
4 | * Entry point for assertions of different data types. Each method in this class is a static factory for the
5 | * type-specific assertion objects.
6 | */
7 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
8 | public class Assertions {
9 |
10 | /**
11 | * Creates a new instance of {@link org.assertj.assertions.generator.data.TeamAssert}
.
12 | *
13 | * @param actual the actual value.
14 | * @return the created assertion object.
15 | */
16 | @org.assertj.core.util.CheckReturnValue
17 | public static org.assertj.assertions.generator.data.TeamAssert assertThat(org.assertj.assertions.generator.data.Team actual) {
18 | return new org.assertj.assertions.generator.data.TeamAssert(actual);
19 | }
20 |
21 | /**
22 | * Creates a new instance of {@link org.assertj.assertions.generator.data.nba.team.TeamAssert}
.
23 | *
24 | * @param actual the actual value.
25 | * @return the created assertion object.
26 | */
27 | @org.assertj.core.util.CheckReturnValue
28 | public static org.assertj.assertions.generator.data.nba.team.TeamAssert assertThat(org.assertj.assertions.generator.data.nba.team.Team actual) {
29 | return new org.assertj.assertions.generator.data.nba.team.TeamAssert(actual);
30 | }
31 |
32 | /**
33 | * Creates a new {@link Assertions}
.
34 | */
35 | protected Assertions() {
36 | // empty
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/AutoValueAnnotatedClassAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link AutoValueAnnotatedClass} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractAutoValueAnnotatedClassAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class AutoValueAnnotatedClassAssert extends AbstractAutoValueAnnotatedClassAssert{@link AutoValueAnnotatedClassAssert}
to make assertions on actual AutoValueAnnotatedClass.
14 | * @param actual the AutoValueAnnotatedClass we want to make assertions on.
15 | */
16 | public AutoValueAnnotatedClassAssert(AutoValueAnnotatedClass actual) {
17 | super(actual, AutoValueAnnotatedClassAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for AutoValueAnnotatedClassAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myAutoValueAnnotatedClass)
and get specific assertion with code completion.
23 | * @param actual the AutoValueAnnotatedClass we want to make assertions on.
24 | * @return a new {@link AutoValueAnnotatedClassAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static AutoValueAnnotatedClassAssert assertThat(AutoValueAnnotatedClass actual) {
28 | return new AutoValueAnnotatedClassAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/BlockBusterAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link BlockBuster} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractBlockBusterAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class BlockBusterAssert extends AbstractBlockBusterAssert{@link BlockBusterAssert}
to make assertions on actual BlockBuster.
14 | * @param actual the BlockBuster we want to make assertions on.
15 | */
16 | public BlockBusterAssert(BlockBuster actual) {
17 | super(actual, BlockBusterAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for BlockBusterAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myBlockBuster)
and get specific assertion with code completion.
23 | * @param actual the BlockBuster we want to make assertions on.
24 | * @return a new {@link BlockBusterAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static BlockBusterAssert assertThat(BlockBuster actual) {
28 | return new BlockBusterAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/BooleanPredicatesAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link BooleanPredicates} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractBooleanPredicatesAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class BooleanPredicatesAssert extends AbstractBooleanPredicatesAssert{@link BooleanPredicatesAssert}
to make assertions on actual BooleanPredicates.
14 | * @param actual the BooleanPredicates we want to make assertions on.
15 | */
16 | public BooleanPredicatesAssert(BooleanPredicates actual) {
17 | super(actual, BooleanPredicatesAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for BooleanPredicatesAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myBooleanPredicates)
and get specific assertion with code completion.
23 | * @param actual the BooleanPredicates we want to make assertions on.
24 | * @return a new {@link BooleanPredicatesAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static BooleanPredicatesAssert assertThat(BooleanPredicates actual) {
28 | return new BooleanPredicatesAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/CarAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.cars;
2 |
3 | import org.assertj.core.api.AbstractObjectAssert;
4 |
5 | /**
6 | * {@link Car} specific assertions - Generated by CustomAssertionGenerator.
7 | */
8 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
9 | public class CarAssert extends AbstractObjectAssert{@link CarAssert}
to make assertions on actual Car.
13 | * @param actual the Car we want to make assertions on.
14 | */
15 | public CarAssert(Car actual) {
16 | super(actual, CarAssert.class);
17 | }
18 |
19 | /**
20 | * An entry point for CarAssert to follow AssertJ standard assertThat()
statements.
21 | * With a static import, one can write directly: assertThat(myCar)
and get specific assertion with code completion.
22 | * @param actual the Car we want to make assertions on.
23 | * @return a new {@link CarAssert}
24 | */
25 | @org.assertj.core.util.CheckReturnValue
26 | public static CarAssert assertThat(Car actual) {
27 | return new CarAssert(actual);
28 | }
29 |
30 | /**
31 | * Verifies that the actual Car's wheelsCount is equal to the given one.
32 | * @param wheelsCount the given wheelsCount to compare the actual Car's wheelsCount to.
33 | * @return this assertion object.
34 | * @throws AssertionError - if the actual Car's wheelsCount is not equal to the given one.
35 | */
36 | public CarAssert hasWheelsCount(int wheelsCount) {
37 | // check that actual Car we want to make assertions on is not null.
38 | isNotNull();
39 |
40 | System.out.println("Custom template for whole number");
41 |
42 | // overrides the default error message with a more explicit one
43 | String assertjErrorMessage = "\nExpecting wheelsCount of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
44 |
45 | // check
46 | int actualWheelsCount = actual.getWheelsCount();
47 | if (actualWheelsCount != wheelsCount) {
48 | failWithMessage(assertjErrorMessage, actual, wheelsCount, actualWheelsCount);
49 | }
50 |
51 | // return the current assertion for method chaining
52 | return this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/ClassUsingDifferentClassesWithSameNameAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator;
2 |
3 | /**
4 | * {@link ClassUsingDifferentClassesWithSameName} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractClassUsingDifferentClassesWithSameNameAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class ClassUsingDifferentClassesWithSameNameAssert extends AbstractClassUsingDifferentClassesWithSameNameAssert{@link ClassUsingDifferentClassesWithSameNameAssert}
to make assertions on actual ClassUsingDifferentClassesWithSameName.
14 | * @param actual the ClassUsingDifferentClassesWithSameName we want to make assertions on.
15 | */
16 | public ClassUsingDifferentClassesWithSameNameAssert(ClassUsingDifferentClassesWithSameName actual) {
17 | super(actual, ClassUsingDifferentClassesWithSameNameAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for ClassUsingDifferentClassesWithSameNameAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myClassUsingDifferentClassesWithSameName)
and get specific assertion with code completion.
23 | * @param actual the ClassUsingDifferentClassesWithSameName we want to make assertions on.
24 | * @return a new {@link ClassUsingDifferentClassesWithSameNameAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static ClassUsingDifferentClassesWithSameNameAssert assertThat(ClassUsingDifferentClassesWithSameName actual) {
28 | return new ClassUsingDifferentClassesWithSameNameAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/Dollar$Assert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Dollar$} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractDollar$Assert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class Dollar$Assert extends AbstractDollar$Assert{@link Dollar$Assert}
to make assertions on actual Dollar$.
14 | * @param actual the Dollar$ we want to make assertions on.
15 | */
16 | public Dollar$Assert(Dollar$ actual) {
17 | super(actual, Dollar$Assert.class);
18 | }
19 |
20 | /**
21 | * An entry point for Dollar$Assert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myDollar$)
and get specific assertion with code completion.
23 | * @param actual the Dollar$ we want to make assertions on.
24 | * @return a new {@link Dollar$Assert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static Dollar$Assert assertThat(Dollar$ actual) {
28 | return new Dollar$Assert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/Dollar$Assert.flat.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * {@link Dollar$} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class Dollar$Assert extends AbstractObjectAssert{@link Dollar$Assert}
to make assertions on actual Dollar$.
14 | * @param actual the Dollar$ we want to make assertions on.
15 | */
16 | public Dollar$Assert(Dollar$ actual) {
17 | super(actual, Dollar$Assert.class);
18 | }
19 |
20 | /**
21 | * An entry point for Dollar$Assert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myDollar$)
and get specific assertion with code completion.
23 | * @param actual the Dollar$ we want to make assertions on.
24 | * @return a new {@link Dollar$Assert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static Dollar$Assert assertThat(Dollar$ actual) {
28 | return new Dollar$Assert(actual);
29 | }
30 |
31 | /**
32 | * Verifies that the actual Dollar$'s test is equal to the given one.
33 | * @param test the given test to compare the actual Dollar$'s test to.
34 | * @return this assertion object.
35 | * @throws AssertionError - if the actual Dollar$'s test is not equal to the given one.
36 | */
37 | public Dollar$Assert hasTest(String test) {
38 | // check that actual Dollar$ we want to make assertions on is not null.
39 | isNotNull();
40 |
41 | // overrides the default error message with a more explicit one
42 | String assertjErrorMessage = "\nExpecting test of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
43 |
44 | // null safe check
45 | String actualTest = actual.test;
46 | if (!Objects.deepEquals(actualTest, test)) {
47 | failWithMessage(assertjErrorMessage, actual, test, actualTest);
48 | }
49 |
50 | // return the current assertion for method chaining
51 | return this;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/FieldPropertyClashAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link FieldPropertyClash} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractFieldPropertyClashAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class FieldPropertyClashAssert extends AbstractFieldPropertyClashAssert{@link FieldPropertyClashAssert}
to make assertions on actual FieldPropertyClash.
14 | * @param actual the FieldPropertyClash we want to make assertions on.
15 | */
16 | public FieldPropertyClashAssert(FieldPropertyClash actual) {
17 | super(actual, FieldPropertyClashAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for FieldPropertyClashAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myFieldPropertyClash)
and get specific assertion with code completion.
23 | * @param actual the FieldPropertyClash we want to make assertions on.
24 | * @return a new {@link FieldPropertyClashAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static FieldPropertyClashAssert assertThat(FieldPropertyClash actual) {
28 | return new FieldPropertyClashAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/InterferencePrimitivesAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link InterferencePrimitives} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractInterferencePrimitivesAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class InterferencePrimitivesAssert extends AbstractInterferencePrimitivesAssert{@link InterferencePrimitivesAssert}
to make assertions on actual InterferencePrimitives.
14 | * @param actual the InterferencePrimitives we want to make assertions on.
15 | */
16 | public InterferencePrimitivesAssert(InterferencePrimitives actual) {
17 | super(actual, InterferencePrimitivesAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for InterferencePrimitivesAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myInterferencePrimitives)
and get specific assertion with code completion.
23 | * @param actual the InterferencePrimitives we want to make assertions on.
24 | * @return a new {@link InterferencePrimitivesAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static InterferencePrimitivesAssert assertThat(InterferencePrimitives actual) {
28 | return new InterferencePrimitivesAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/KeywordsAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Keywords} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractKeywordsAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class KeywordsAssert extends AbstractKeywordsAssert{@link KeywordsAssert}
to make assertions on actual Keywords.
14 | * @param actual the Keywords we want to make assertions on.
15 | */
16 | public KeywordsAssert(Keywords actual) {
17 | super(actual, KeywordsAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for KeywordsAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myKeywords)
and get specific assertion with code completion.
23 | * @param actual the Keywords we want to make assertions on.
24 | * @return a new {@link KeywordsAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static KeywordsAssert assertThat(Keywords actual) {
28 | return new KeywordsAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/MovieAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Movie} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractMovieAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class MovieAssert extends AbstractMovieAssert{@link MovieAssert}
to make assertions on actual Movie.
14 | * @param actual the Movie we want to make assertions on.
15 | */
16 | public MovieAssert(Movie actual) {
17 | super(actual, MovieAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for MovieAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myMovie)
and get specific assertion with code completion.
23 | * @param actual the Movie we want to make assertions on.
24 | * @return a new {@link MovieAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static MovieAssert assertThat(Movie actual) {
28 | return new MovieAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/MultipleGenericsAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.generic;
2 |
3 | /**
4 | * {@link MultipleGenerics{@link MultipleGenericsAssert
to make assertions on actual MultipleGenericsassertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myMultipleGenerics
and get specific assertion with code completion.
23 | * @param actual the MultipleGenerics{@link MultipleGenericsAssert
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static {@link org.assertj.assertions.generator.data.lotr.RingAssert}
.
12 | *
13 | * @param actual the actual value.
14 | * @return the created assertion object.
15 | */
16 | @org.assertj.core.util.CheckReturnValue
17 | public static org.assertj.assertions.generator.data.lotr.RingAssert assertThat(org.assertj.assertions.generator.data.lotr.Ring actual) {
18 | return new org.assertj.assertions.generator.data.lotr.RingAssert(actual);
19 | }
20 |
21 | /**
22 | * Creates a new {@link MyAssertions}
.
23 | */
24 | protected MyAssertions() {
25 | // empty
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/NameAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Name} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractNameAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class NameAssert extends AbstractNameAssert{@link NameAssert}
to make assertions on actual Name.
14 | * @param actual the Name we want to make assertions on.
15 | */
16 | public NameAssert(Name actual) {
17 | super(actual, NameAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for NameAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myName)
and get specific assertion with code completion.
23 | * @param actual the Name we want to make assertions on.
24 | * @return a new {@link NameAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static NameAssert assertThat(Name actual) {
28 | return new NameAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/NameAssert.flat.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractComparableAssert;
5 |
6 | /**
7 | * {@link Name} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class NameAssert extends AbstractComparableAssert{@link NameAssert}
to make assertions on actual Name.
14 | * @param actual the Name we want to make assertions on.
15 | */
16 | public NameAssert(Name actual) {
17 | super(actual, NameAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for NameAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myName)
and get specific assertion with code completion.
23 | * @param actual the Name we want to make assertions on.
24 | * @return a new {@link NameAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static NameAssert assertThat(Name actual) {
28 | return new NameAssert(actual);
29 | }
30 |
31 | /**
32 | * Verifies that the actual Name's first is equal to the given one.
33 | * @param first the given first to compare the actual Name's first to.
34 | * @return this assertion object.
35 | * @throws AssertionError - if the actual Name's first is not equal to the given one.
36 | */
37 | public NameAssert hasFirst(String first) {
38 | // check that actual Name we want to make assertions on is not null.
39 | isNotNull();
40 |
41 | // overrides the default error message with a more explicit one
42 | String assertjErrorMessage = "\nExpecting first of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
43 |
44 | // null safe check
45 | String actualFirst = actual.getFirst();
46 | if (!Objects.deepEquals(actualFirst, first)) {
47 | failWithMessage(assertjErrorMessage, actual, first, actualFirst);
48 | }
49 |
50 | // return the current assertion for method chaining
51 | return this;
52 | }
53 |
54 | /**
55 | * Verifies that the actual Name's last is equal to the given one.
56 | * @param last the given last to compare the actual Name's last to.
57 | * @return this assertion object.
58 | * @throws AssertionError - if the actual Name's last is not equal to the given one.
59 | */
60 | public NameAssert hasLast(String last) {
61 | // check that actual Name we want to make assertions on is not null.
62 | isNotNull();
63 |
64 | // overrides the default error message with a more explicit one
65 | String assertjErrorMessage = "\nExpecting last of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
66 |
67 | // null safe check
68 | String actualLast = actual.getLast();
69 | if (!Objects.deepEquals(actualLast, last)) {
70 | failWithMessage(assertjErrorMessage, actual, last, actualLast);
71 | }
72 |
73 | // return the current assertion for method chaining
74 | return this;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/NestedClassAssert.hierarchical.template.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link ${nestedClass}} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link Abstract${nestedClass}Assert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class ${nestedClass}Assert extends Abstract${nestedClass}Assert<${nestedClass}Assert, ${nestedClass}> {
11 |
12 | /**
13 | * Creates a new {@link ${nestedClass}Assert}
to make assertions on actual ${nestedClass}.
14 | * @param actual the ${nestedClass} we want to make assertions on.
15 | */
16 | public ${nestedClass}Assert(${nestedClass} actual) {
17 | super(actual, ${nestedClass}Assert.class);
18 | }
19 |
20 | /**
21 | * An entry point for ${nestedClass}Assert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(my${nestedClass})
and get specific assertion with code completion.
23 | * @param actual the ${nestedClass} we want to make assertions on.
24 | * @return a new {@link ${nestedClass}Assert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static ${nestedClass}Assert assertThat(${nestedClass} actual) {
28 | return new ${nestedClass}Assert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/NestedClassAssert.template.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * {@link ${nestedClass}} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class ${nestedClass}Assert extends AbstractObjectAssert<${nestedClass}Assert, ${nestedClass}> {
11 |
12 | /**
13 | * Creates a new {@link ${nestedClass}Assert}
to make assertions on actual ${nestedClass}.
14 | * @param actual the ${nestedClass} we want to make assertions on.
15 | */
16 | public ${nestedClass}Assert(${nestedClass} actual) {
17 | super(actual, ${nestedClass}Assert.class);
18 | }
19 |
20 | /**
21 | * An entry point for ${nestedClass}Assert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(my${nestedClass})
and get specific assertion with code completion.
23 | * @param actual the ${nestedClass} we want to make assertions on.
24 | * @return a new {@link ${nestedClass}Assert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static ${nestedClass}Assert assertThat(${nestedClass} actual) {
28 | return new ${nestedClass}Assert(actual);
29 | }
30 |
31 | /**
32 | * Verifies that the actual ${nestedClass}'s name is equal to the given one.
33 | * @param name the given name to compare the actual ${nestedClass}'s name to.
34 | * @return this assertion object.
35 | * @throws AssertionError - if the actual ${nestedClass}'s name is not equal to the given one.
36 | */
37 | public ${nestedClass}Assert hasName(String name) {
38 | // check that actual ${nestedClass} we want to make assertions on is not null.
39 | isNotNull();
40 |
41 | // overrides the default error message with a more explicit one
42 | String assertjErrorMessage = "\nExpecting name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
43 |
44 | // null safe check
45 | String actualName = actual.getName();
46 | if (!Objects.deepEquals(actualName, name)) {
47 | failWithMessage(assertjErrorMessage, actual, name, actualName);
48 | }
49 |
50 | // return the current assertion for method chaining
51 | return this;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/NestedClassAssert.template.generated.in.custom.package.expected.txt:
--------------------------------------------------------------------------------
1 | package my.assertions;
2 |
3 | import java.util.Objects;
4 | import ${fullyQualifiedOuterClassName};
5 | import org.assertj.core.api.AbstractObjectAssert;
6 |
7 | /**
8 | * {@link ${nestedClass}} specific assertions - Generated by CustomAssertionGenerator.
9 | */
10 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
11 | public class ${nestedClass}Assert extends AbstractObjectAssert<${nestedClass}Assert, ${nestedClass}> {
12 |
13 | /**
14 | * Creates a new {@link ${nestedClass}Assert}
to make assertions on actual ${nestedClass}.
15 | * @param actual the ${nestedClass} we want to make assertions on.
16 | */
17 | public ${nestedClass}Assert(${nestedClass} actual) {
18 | super(actual, ${nestedClass}Assert.class);
19 | }
20 |
21 | /**
22 | * An entry point for ${nestedClass}Assert to follow AssertJ standard assertThat()
statements.
23 | * With a static import, one can write directly: assertThat(my${nestedClass})
and get specific assertion with code completion.
24 | * @param actual the ${nestedClass} we want to make assertions on.
25 | * @return a new {@link ${nestedClass}Assert}
26 | */
27 | @org.assertj.core.util.CheckReturnValue
28 | public static ${nestedClass}Assert assertThat(${nestedClass} actual) {
29 | return new ${nestedClass}Assert(actual);
30 | }
31 |
32 | /**
33 | * Verifies that the actual ${nestedClass}'s name is equal to the given one.
34 | * @param name the given name to compare the actual ${nestedClass}'s name to.
35 | * @return this assertion object.
36 | * @throws AssertionError - if the actual ${nestedClass}'s name is not equal to the given one.
37 | */
38 | public ${nestedClass}Assert hasName(String name) {
39 | // check that actual ${nestedClass} we want to make assertions on is not null.
40 | isNotNull();
41 |
42 | // overrides the default error message with a more explicit one
43 | String assertjErrorMessage = "\nExpecting name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
44 |
45 | // null safe check
46 | String actualName = actual.getName();
47 | if (!Objects.deepEquals(actualName, name)) {
48 | failWithMessage(assertjErrorMessage, actual, name, actualName);
49 | }
50 |
51 | // return the current assertion for method chaining
52 | return this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/OptionalAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package com.google.common.base;
2 |
3 | /**
4 | * {@link Optional} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractOptionalAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class OptionalAssert extends AbstractOptionalAssert{@link OptionalAssert}
to make assertions on actual Optional.
14 | * @param actual the Optional we want to make assertions on.
15 | */
16 | public OptionalAssert(Optional actual) {
17 | super(actual, OptionalAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for OptionalAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myOptional)
and get specific assertion with code completion.
23 | * @param actual the Optional we want to make assertions on.
24 | * @return a new {@link OptionalAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static OptionalAssert assertThat(Optional actual) {
28 | return new OptionalAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/OptionalAssert.flat.expected.txt:
--------------------------------------------------------------------------------
1 | package com.google.common.base;
2 |
3 | import org.assertj.core.api.AbstractObjectAssert;
4 |
5 | /**
6 | * {@link Optional} specific assertions - Generated by CustomAssertionGenerator.
7 | */
8 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
9 | public class OptionalAssert extends AbstractObjectAssert{@link OptionalAssert}
to make assertions on actual Optional.
13 | * @param actual the Optional we want to make assertions on.
14 | */
15 | public OptionalAssert(Optional actual) {
16 | super(actual, OptionalAssert.class);
17 | }
18 |
19 | /**
20 | * An entry point for OptionalAssert to follow AssertJ standard assertThat()
statements.
21 | * With a static import, one can write directly: assertThat(myOptional)
and get specific assertion with code completion.
22 | * @param actual the Optional we want to make assertions on.
23 | * @return a new {@link OptionalAssert}
24 | */
25 | @org.assertj.core.util.CheckReturnValue
26 | public static OptionalAssert assertThat(Optional actual) {
27 | return new OptionalAssert(actual);
28 | }
29 |
30 | /**
31 | * Verifies that the actual Optional is present.
32 | * @return this assertion object.
33 | * @throws AssertionError - if the actual Optional is not present.
34 | */
35 | public OptionalAssert isPresent() {
36 | // check that actual Optional we want to make assertions on is not null.
37 | isNotNull();
38 |
39 | // check that property call/field access is true
40 | if (!actual.isPresent()) {
41 | failWithMessage("\nExpecting that actual Optional is present but is not.");
42 | }
43 |
44 | // return the current assertion for method chaining
45 | return this;
46 | }
47 |
48 | /**
49 | * Verifies that the actual Optional is not present.
50 | * @return this assertion object.
51 | * @throws AssertionError - if the actual Optional is present.
52 | */
53 | public OptionalAssert isNotPresent() {
54 | // check that actual Optional we want to make assertions on is not null.
55 | isNotNull();
56 |
57 | // check that property call/field access is false
58 | if (actual.isPresent()) {
59 | failWithMessage("\nExpecting that actual Optional is not present but is.");
60 | }
61 |
62 | // return the current assertion for method chaining
63 | return this;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAgentAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.nba;
2 |
3 | /**
4 | * {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractPlayerAgentAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class PlayerAgentAssert extends AbstractPlayerAgentAssert{@link PlayerAgentAssert}
to make assertions on actual PlayerAgent.
14 | * @param actual the PlayerAgent we want to make assertions on.
15 | */
16 | public PlayerAgentAssert(PlayerAgent actual) {
17 | super(actual, PlayerAgentAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for PlayerAgentAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myPlayerAgent)
and get specific assertion with code completion.
23 | * @param actual the PlayerAgent we want to make assertions on.
24 | * @return a new {@link PlayerAgentAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static PlayerAgentAssert assertThat(PlayerAgent actual) {
28 | return new PlayerAgentAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAgentAssert.flat.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.nba;
2 |
3 | import java.util.Objects;
4 | import org.assertj.core.api.AbstractObjectAssert;
5 |
6 | /**
7 | * {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class PlayerAgentAssert extends AbstractObjectAssert{@link PlayerAgentAssert}
to make assertions on actual PlayerAgent.
14 | * @param actual the PlayerAgent we want to make assertions on.
15 | */
16 | public PlayerAgentAssert(PlayerAgent actual) {
17 | super(actual, PlayerAgentAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for PlayerAgentAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myPlayerAgent)
and get specific assertion with code completion.
23 | * @param actual the PlayerAgent we want to make assertions on.
24 | * @return a new {@link PlayerAgentAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static PlayerAgentAssert assertThat(PlayerAgent actual) {
28 | return new PlayerAgentAssert(actual);
29 | }
30 |
31 | /**
32 | * Verifies that the actual PlayerAgent's managedPlayer is equal to the given one.
33 | * @param managedPlayer the given managedPlayer to compare the actual PlayerAgent's managedPlayer to.
34 | * @return this assertion object.
35 | * @throws AssertionError - if the actual PlayerAgent's managedPlayer is not equal to the given one.
36 | */
37 | public PlayerAgentAssert hasManagedPlayer(Player managedPlayer) {
38 | // check that actual PlayerAgent we want to make assertions on is not null.
39 | isNotNull();
40 |
41 | // overrides the default error message with a more explicit one
42 | String assertjErrorMessage = "\nExpecting managedPlayer of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
43 |
44 | // null safe check
45 | Player actualManagedPlayer = actual.getManagedPlayer();
46 | if (!Objects.deepEquals(actualManagedPlayer, managedPlayer)) {
47 | failWithMessage(assertjErrorMessage, actual, managedPlayer, actualManagedPlayer);
48 | }
49 |
50 | // return the current assertion for method chaining
51 | return this;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAgentAssert.generated.in.custom.package.expected.txt:
--------------------------------------------------------------------------------
1 | package my.assertions;
2 |
3 | import org.assertj.assertions.generator.data.nba.PlayerAgent;
4 |
5 | /**
6 | * {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
7 | *
8 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
9 | * extend {@link AbstractPlayerAgentAssert} instead.
10 | */
11 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
12 | public class PlayerAgentAssert extends AbstractPlayerAgentAssert{@link PlayerAgentAssert}
to make assertions on actual PlayerAgent.
16 | * @param actual the PlayerAgent we want to make assertions on.
17 | */
18 | public PlayerAgentAssert(PlayerAgent actual) {
19 | super(actual, PlayerAgentAssert.class);
20 | }
21 |
22 | /**
23 | * An entry point for PlayerAgentAssert to follow AssertJ standard assertThat()
statements.
24 | * With a static import, one can write directly: assertThat(myPlayerAgent)
and get specific assertion with code completion.
25 | * @param actual the PlayerAgent we want to make assertions on.
26 | * @return a new {@link PlayerAgentAssert}
27 | */
28 | @org.assertj.core.util.CheckReturnValue
29 | public static PlayerAgentAssert assertThat(PlayerAgent actual) {
30 | return new PlayerAgentAssert(actual);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAgentAssert.generated.in.custom.package.flat.expected.txt:
--------------------------------------------------------------------------------
1 | package my.assertions;
2 |
3 | import java.util.Objects;
4 | import org.assertj.assertions.generator.data.nba.PlayerAgent;
5 | import org.assertj.core.api.AbstractObjectAssert;
6 |
7 | /**
8 | * {@link PlayerAgent} specific assertions - Generated by CustomAssertionGenerator.
9 | */
10 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
11 | public class PlayerAgentAssert extends AbstractObjectAssert{@link PlayerAgentAssert}
to make assertions on actual PlayerAgent.
15 | * @param actual the PlayerAgent we want to make assertions on.
16 | */
17 | public PlayerAgentAssert(PlayerAgent actual) {
18 | super(actual, PlayerAgentAssert.class);
19 | }
20 |
21 | /**
22 | * An entry point for PlayerAgentAssert to follow AssertJ standard assertThat()
statements.
23 | * With a static import, one can write directly: assertThat(myPlayerAgent)
and get specific assertion with code completion.
24 | * @param actual the PlayerAgent we want to make assertions on.
25 | * @return a new {@link PlayerAgentAssert}
26 | */
27 | @org.assertj.core.util.CheckReturnValue
28 | public static PlayerAgentAssert assertThat(PlayerAgent actual) {
29 | return new PlayerAgentAssert(actual);
30 | }
31 |
32 | /**
33 | * Verifies that the actual PlayerAgent's managedPlayer is equal to the given one.
34 | * @param managedPlayer the given managedPlayer to compare the actual PlayerAgent's managedPlayer to.
35 | * @return this assertion object.
36 | * @throws AssertionError - if the actual PlayerAgent's managedPlayer is not equal to the given one.
37 | */
38 | public PlayerAgentAssert hasManagedPlayer(org.assertj.assertions.generator.data.nba.Player managedPlayer) {
39 | // check that actual PlayerAgent we want to make assertions on is not null.
40 | isNotNull();
41 |
42 | // overrides the default error message with a more explicit one
43 | String assertjErrorMessage = "\nExpecting managedPlayer of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
44 |
45 | // null safe check
46 | org.assertj.assertions.generator.data.nba.Player actualManagedPlayer = actual.getManagedPlayer();
47 | if (!Objects.deepEquals(actualManagedPlayer, managedPlayer)) {
48 | failWithMessage(assertjErrorMessage, actual, managedPlayer, actualManagedPlayer);
49 | }
50 |
51 | // return the current assertion for method chaining
52 | return this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data.nba;
2 |
3 | /**
4 | * {@link Player} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractPlayerAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class PlayerAssert extends AbstractPlayerAssert{@link PlayerAssert}
to make assertions on actual Player.
14 | * @param actual the Player we want to make assertions on.
15 | */
16 | public PlayerAssert(Player actual) {
17 | super(actual, PlayerAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for PlayerAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myPlayer)
and get specific assertion with code completion.
23 | * @param actual the Player we want to make assertions on.
24 | * @return a new {@link PlayerAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static PlayerAssert assertThat(Player actual) {
28 | return new PlayerAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PlayerAssert.generated.in.custom.package.expected.txt:
--------------------------------------------------------------------------------
1 | package my.assertions;
2 |
3 | import org.assertj.assertions.generator.data.nba.Player;
4 |
5 | /**
6 | * {@link Player} specific assertions - Generated by CustomAssertionGenerator.
7 | *
8 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
9 | * extend {@link AbstractPlayerAssert} instead.
10 | */
11 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
12 | public class PlayerAssert extends AbstractPlayerAssert{@link PlayerAssert}
to make assertions on actual Player.
16 | * @param actual the Player we want to make assertions on.
17 | */
18 | public PlayerAssert(Player actual) {
19 | super(actual, PlayerAssert.class);
20 | }
21 |
22 | /**
23 | * An entry point for PlayerAssert to follow AssertJ standard assertThat()
statements.
24 | * With a static import, one can write directly: assertThat(myPlayer)
and get specific assertion with code completion.
25 | * @param actual the Player we want to make assertions on.
26 | * @return a new {@link PlayerAssert}
27 | */
28 | @org.assertj.core.util.CheckReturnValue
29 | public static PlayerAssert assertThat(Player actual) {
30 | return new PlayerAssert(actual);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/PrimitivesAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Primitives} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractPrimitivesAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class PrimitivesAssert extends AbstractPrimitivesAssert{@link PrimitivesAssert}
to make assertions on actual Primitives.
14 | * @param actual the Primitives we want to make assertions on.
15 | */
16 | public PrimitivesAssert(Primitives actual) {
17 | super(actual, PrimitivesAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for PrimitivesAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myPrimitives)
and get specific assertion with code completion.
23 | * @param actual the Primitives we want to make assertions on.
24 | * @return a new {@link PrimitivesAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static PrimitivesAssert assertThat(Primitives actual) {
28 | return new PrimitivesAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/TeamAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link Team} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractTeamAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class TeamAssert extends AbstractTeamAssert{@link TeamAssert}
to make assertions on actual Team.
14 | * @param actual the Team we want to make assertions on.
15 | */
16 | public TeamAssert(Team actual) {
17 | super(actual, TeamAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for TeamAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myTeam)
and get specific assertion with code completion.
23 | * @param actual the Team we want to make assertions on.
24 | * @return a new {@link TeamAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static TeamAssert assertThat(Team actual) {
28 | return new TeamAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/WithPrivateFieldsAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link WithPrivateFields} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractWithPrivateFieldsAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class WithPrivateFieldsAssert extends AbstractWithPrivateFieldsAssert{@link WithPrivateFieldsAssert}
to make assertions on actual WithPrivateFields.
14 | * @param actual the WithPrivateFields we want to make assertions on.
15 | */
16 | public WithPrivateFieldsAssert(WithPrivateFields actual) {
17 | super(actual, WithPrivateFieldsAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for WithPrivateFieldsAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myWithPrivateFields)
and get specific assertion with code completion.
23 | * @param actual the WithPrivateFields we want to make assertions on.
24 | * @return a new {@link WithPrivateFieldsAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static WithPrivateFieldsAssert assertThat(WithPrivateFields actual) {
28 | return new WithPrivateFieldsAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/WithPrivateFieldsParentAssert.expected.txt:
--------------------------------------------------------------------------------
1 | package org.assertj.assertions.generator.data;
2 |
3 | /**
4 | * {@link WithPrivateFieldsParent} specific assertions - Generated by CustomAssertionGenerator.
5 | *
6 | * Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
7 | * extend {@link AbstractWithPrivateFieldsParentAssert} instead.
8 | */
9 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
10 | public class WithPrivateFieldsParentAssert extends AbstractWithPrivateFieldsParentAssert{@link WithPrivateFieldsParentAssert}
to make assertions on actual WithPrivateFieldsParent.
14 | * @param actual the WithPrivateFieldsParent we want to make assertions on.
15 | */
16 | public WithPrivateFieldsParentAssert(WithPrivateFieldsParent actual) {
17 | super(actual, WithPrivateFieldsParentAssert.class);
18 | }
19 |
20 | /**
21 | * An entry point for WithPrivateFieldsParentAssert to follow AssertJ standard assertThat()
statements.
22 | * With a static import, one can write directly: assertThat(myWithPrivateFieldsParent)
and get specific assertion with code completion.
23 | * @param actual the WithPrivateFieldsParent we want to make assertions on.
24 | * @return a new {@link WithPrivateFieldsParentAssert}
25 | */
26 | @org.assertj.core.util.CheckReturnValue
27 | public static WithPrivateFieldsParentAssert assertThat(WithPrivateFieldsParent actual) {
28 | return new WithPrivateFieldsParentAssert(actual);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/customtemplates/custom_has_assertion_template_for_whole_number.txt:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one.
4 | * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to.
5 | * @return this assertion object.
6 | * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is not equal to the given one.${throws_javadoc}
7 | */
8 | public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{
9 | // check that actual ${class_to_assert} we want to make assertions on is not null.
10 | isNotNull();
11 |
12 | System.out.println("Custom template for whole number");
13 |
14 | // overrides the default error message with a more explicit one
15 | String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
16 |
17 | // check
18 | ${propertyType} actual${Property} = actual.get${Property}();
19 | if (actual${Property} != ${property_safe}) {
20 | failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property});
21 | }
22 |
23 | // return the current assertion for method chaining
24 | return ${myself};
25 | }
--------------------------------------------------------------------------------
/assertj-generator/src/test/resources/customtemplates/my_assertion_entry_point_class.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | /**
4 | * Entry point for assertions of different data types. Each method in this class is a static factory for the
5 | * type-specific assertion objects.
6 | */
7 | @javax.annotation.processing.Generated(value="assertj-assertions-generator")
8 | public class MyAssertions {
9 | ${all_assertions_entry_points}
10 | /**
11 | * Creates a new {@link MyAssertions}
.
12 | */
13 | protected MyAssertions() {
14 | // empty
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/build-assertion-generator-and-maven-plugin.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | echo ''
3 | echo 'Build AssertJ assertion generator ...'
4 | echo ''
5 | mvn clean install
6 |
7 | echo ''
8 | echo ''
9 | echo 'Build AssertJ assertion generator maven plugin ...'
10 | echo ''
11 | cd ../assertj-assertions-generator-maven-plugin
12 | mvn clean install
13 |
14 | # go back to previous directory
15 | cd -
16 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |