Skip to content

isEqualTo(null) should be possible #21

Closed

Description

@otoniel-isidoro

In some cases we need to verify if the value on the table is the same value of the expected and the expected value can be null. Then isEqualTo(null) should work if the actual and the expected is null too.
example:

Application application = new Application();
application.setName = null;
dao.save(application);
Table applicationTable = new Table(dataSource, DatabaseHelper.APPLICATION_TABLE_NAME);
assertThat(applicationTable).row(0).column("name").value().isEqualTo(application.getName());

In this case I dont want to use isNull because I can modify the name attribute from null to a valid value later and my tests still passing.

Activity

  1. otoniel-isidoro commented on Aug 31, 2015

    @otoniel-isidoro
    Author

    An another example that can use this feature:
    To DRY my test code I can create a generic method assertion for each table too, and use it on various tests with valid or null values on each field.
    example:

     public void assertApplicationTable(List<Application> expectedApplications){
        for(Application application : expectedApplications){
            assertThat(applicationTable)
                    .row(expectedApplications.indexOf(application))
                    .column("id").value().isEqualTo(application.getId())
                    .column("name").value().isEqualTo(application.getName())
                    .column("description").value().isEqualTo(application.getDescription())
                    .column("application_key").value().isEqualTo(application.getApplicationKey())
                    .column("platform").value().isEqualTo(application.getPlatform().getId())
                    .column("product_id").value().isEqualTo(application.getProductId())
                    .column("package_name").value().isEqualTo(application.getPackageName())
                    .column("environment").value().isEqualTo(application.getEnvironment().getId())
                    .column("company_id").value().isEqualTo(application.getCompanyId())
                    .column("created_at").value().isEqualTo(new DateTimeValue(Timestamp.from(application.getCreatedAt().toInstant())));
        }
    }
    
  2. otoniel-isidoro commented on Aug 31, 2015

    @otoniel-isidoro
    Author

    The equality of null=null is not satisfied because of NOT_IDENTIFIED type and on the isEqualTo methods there is a verification on valueType without the type NOT_IDENTIFIED.
    example:

    public static <A extends AbstractAssert> A isEqualTo(A assertion, WritableAssertionInfo info, Object value,
                                                           DateTimeValue expected) {
        AssertionsOnValueType.isOfAnyTypeIn(assertion, info, value, ValueType.DATE, ValueType.DATE_TIME);
    [...]
    }
    
  3. regis1512 commented on Aug 31, 2015

    @regis1512
    Member

    Understood. It is not an urgent bug but it is more than an enhancement

  4. otoniel-isidoro commented on Sep 2, 2015

    @otoniel-isidoro
    Author

    Just to discuss: I think that the behavior of isAfterOrEqualTo and isBeforeOrEqualTo (I didn't remember if there were more methods like these) are wrong too because it shoud be able to verify if null=null too.

  5. regis1512 commented on Sep 3, 2015

    @regis1512
    Member

    I started to work on this.
    I do isEqualTo and isNotEqualTo
    For other methods, i do not the real interest for the moment so i think to let like that

  6. regis1512 commented on Sep 6, 2015

    @regis1512
    Member

    Note that it will never be possible to use directly isEqualTo(null) because there is conflict : Java don't know which method is called. But it is possible to implement isEqualTo(Object) and after call it with isEqualTo((Object) null)

  7. added a commit that references this issue on Sep 6, 2015
  8. regis1512 commented on Sep 6, 2015

    @regis1512
    Member

    Please, give me your test results but for me it is closed

  9. otoniel-isidoro commented on Sep 9, 2015

    @otoniel-isidoro
    Author

    It's ok thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions