google/truth

File Subject?

lukesandberg opened this issue · 9 comments

closure-templates has a bunch of tests for how the compiler generates files. It would be nice if Truth had some support for asserting on local files via File objects.

e.g.
assertThat(file).exists()
assertThat(file).doesNotExist()
assertThat(file).contentEquals(otherFile);
assertThat(file).isDirectory();

others?
URL objects? java7 Paths?

Semi-related is (internal) bug 18722931 where I asked Colin to "polish up PathSubject and put it somewhere common".

+1 for the PathSubject. Currently the following does not compile due to method ambiguity:

    @Test
    public void shouldConvertToPath() throws IOException {
        // given
        final Path expectedPath = ...;

        // when
        final Path convertedPath = ...;

        // then
        ASSERT.that(convertedPath).isEqualTo(expectedPath);
    }

Declaring convertedPath as Object resolves the ambiguity. It's fine in this case since i'm treating convertedPath as an Object anyway, but having a specialized PathSubject sure would be nice!

+1 on resolving the ambiguity; it took me a while to realize Path is an Iterable<Path> and a Comparable<Path>.

basil commented

+1, just hit the same issue.

Hey @cgdecker - this would be a good thing. Let's sync about how I can help you get it moved in. I'd really like to see this in for 1.0.

To be honest, I've lost track of this and would have to dig up what I'd done again. I don't think it was ready or that we'd even worked out the API issues really. And I don't think I really have time to work on it this quarter. If you do want to try to push on getting this in, I can probably find what I had in terms of API plan and/or implementation and you can try to take it from there though.

+1, I just hit this issue as well

See #285 for PathSubject; I'd like to see that added, even just as a stub.

PathSubject exists as part of the Truth8 extension now, mostly to resolve the ambiguity of IterableSubject and ComparableSubject:

public static PathSubject assertThat(@NullableDecl Path target) {

Leaving this open to decide how to do more assertions on the Path object.