JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

hasProperty with value fails if the scope of the instance's class is not public

Open JasonWThompson opened this issue 9 years ago • 1 comments

If an instance of a default scoped class is passed into the hasProperty matcher, the assertion will always fail when the get method is invoked to get the value of the property.

JasonWThompson avatar Jun 24 '16 21:06 JasonWThompson

I believe this is the issue I'm seeing? My test case:

import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class LibraryTest {
    @Test
    public void testSomeLibraryMethod() {
        Path path = Paths.get("hi.txt");
        assertThat(path.getFileName().toString(), is(equalTo("hi.txt")));
        assertThat(path, hasProperty("fileName", hasToString("hi.txt")));
    }
}

hakanai avatar Mar 12 '20 05:03 hakanai