Duplicated assertion method with target class implementing method from interface

Abierto
#278 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java
Área
tooling

Línea de trabajo

No se nombra ningún archivo fuente ni ninguna prueba. Empieza por localizar la ruta del generador que convierte los métodos de interfaz e implementación en métodos de aserción y, después, reproduce el caso con una interfaz id() y una clase que la implemente. La tarea está terminada cuando la generación ya no produzca métodos hasId duplicados y el comportamiento esté cubierto por una prueba de regresión.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hi @scordio ,

let me thank you first for your work. Because I was looking a long time that we can use records with AssertJ and can remove the templates.

The new version works perfectly in our project. Unfortunately, I found a bug with M4/M5. But maybe isn't bug, because our clever programming isn't that clever ;). Should I open an issue for that?

Short summary of the bug

  • We have an Interface X which has method called id()
  • We implement this Interface X in several classes. The typical implementation is
  • String id = "someId"; public String id() { return id; }
  • When AssertJ creates the *Assert classes it creates the method hasId twice, e.g.
 /**
   * Verifies that the actual Data's id is equal to the given one.
   * @param id the given id to compare the actual Data's id to.
   * @return this assertion object.
   * @throws AssertionError - if the actual Data's id is not equal to the given one.
   */
  public S hasId(String id) {
    // check that actual Data we want to make assertions on is not null.
    isNotNull();

    // overrides the default error message with a more explicit one
    String assertjErrorMessage = "\nExpecting id of:\n  <%s>\nto be:\n  <%s>\nbut was:\n  <%s>";

    // null safe check
    String actualId = actual.getId();
    if (!Objects.deepEquals(actualId, id)) {
      failWithMessage(assertjErrorMessage, actual, id, actualId);
    }

    // return the current assertion for method chaining
    return myself;
  }

  /**
   * Verifies that the actual Data's id is equal to the given one.
   * @param id the given id to compare the actual Data's id to.
   * @return this assertion object.
   * @throws AssertionError - if the actual Data's id is not equal to the given one.
   */
  public S hasId(String id) {
    // check that actual Data we want to make assertions on is not null.
    isNotNull();

    // overrides the default error message with a more explicit one
    String assertjErrorMessage = "\nExpecting id of:\n  <%s>\nto be:\n  <%s>\nbut was:\n  <%s>";

    // null safe check
    String actualId = actual.id();
    if (!Objects.deepEquals(actualId, id)) {
      failWithMessage(assertjErrorMessage, actual, id, actualId);
    }

    // return the current assertion for method chaining
    return myself;
  }

Simple workaround
Renaming the method id() to getId() solved the problem and all Assertions classes are created correctly.

Originally posted by @schmuka0501 in https://github.com/assertj/assertj-assertions-generator-maven-plugin/issues/93#issuecomment-3183154411

Lenguaje dominante
Java
Estrellas
72
Forks
47
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de assertj/assertj-generator

Todos los issues de assertj/assertj-generator

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.