Assertj-core: Add isEmpty() / isNotEmpty() to AbstractPathAssert

Created on 24 Nov 2020  路  9Comments  路  Source: assertj/assertj-core

Summary

AbstractPathAssert lacks assertions to test if path is empty or not empty, in the case of regular files.

These assertions could rely on java.nio.Files.size().

Example

assertThat(path).isEmpty();
assertThat(path).isNotEmpty();
good first issue new feature

All 9 comments

@scordio Can I work on this issue? IsEmpty refers that the path that you are testing doesn't exist or doesn't have any file, right?

Hi @OmarMorales71, sure. Thanks for helping!

The assertion should check that the Path exists, is a regular file and has size equals to zero. The behavior should be similar to isEmpty() for File, which uses assertIsEmptyFile:

https://github.com/assertj/assertj-core/blob/16166e38199d121c843414a5acd315106fc1f1d0/src/main/java/org/assertj/core/internal/Files.java#L325-L329

The existence and the regular file assertion can be covered by assertIsRegularFile:
https://github.com/assertj/assertj-core/blob/16166e38199d121c843414a5acd315106fc1f1d0/src/main/java/org/assertj/core/internal/Paths.java#L142-L145

@scordio Thank you! Let's work on it

@scordio Hello, I have been working on the issue. I just need to do the tests. But for a while, how you see my solution?
Here are the methods in AbstractPathAssert
https://github.com/OmarMorales71/assertj-core/blob/42cb5e258fed31e747f9b2492f33143339080207/src/main/java/org/assertj/core/api/AbstractPathAssert.java#L1753-L1761

And here are the implementations in src/main/java/org/assertj/core/internal/Paths.java
https://github.com/OmarMorales71/assertj-core/blob/42cb5e258fed31e747f9b2492f33143339080207/src/main/java/org/assertj/core/internal/Paths.java#L502-L519

I'm working on the tests right now, I'm in a good way?

Hi @OmarMorales71, the direction is good and I'd be happy to provide some specific feedback. Would you mind raising a pull request, even on draft state?

@scordio I already did a draft PR, in the afternoon I'm going to work on the tests and documentation. If you can give me some feedback or comments please I'd be really grateful.

@scordio The PR has been sent, If you can check it, it will be great. Thank you!

@scordio I read your comments in the pull request, thank you so much, I'm working in the changes!

@scordio I fixed the changes you requested and added the unit tests. If you can check it, it will be great. :D

Was this page helpful?
0 / 5 - 0 ratings