Skip to content

Mocked file.getAbsolutePath() NullPointerException #376

@charlesritchea

Description

@charlesritchea

Please provide the following information:

  • Version of JMockit that was used:

1.30

  • Description of the problem:
    Sorry this isn't fleshed out, but imagine you have an interface Bar that has a getFile method that is used to report an error with the file path in the error message. Basically, when file.getAbsolutePath() is called, the Expectation is completely ignored, so that the actual isAbsolutePath() code is run so that tons of stuff are null. I suspect this is more of these filtered out java.* classes which I simply don't understand.
    @Test
    public void shouldFoo(@Mocked Bar bar, @Mocked File file, @Mocked Path path) {
        String pathStr = "/some/test";

        new MockUp<Paths>(Paths.class) {
            @Mock
            Path get(String first, String... more) {
                return path;
            }
        };

        new MockUp<Files>(Files.class) {
            @Mock
            boolean exists(Path path, LinkOption... options) {
                return false;
            }
        };

        new Expectations() {{
            bar.getFile();
            result = file;
            file.getAbsolutePath();
            result = pathStr;
        }};

        assertThat(bar.getMessage(), is(equalTo("baz" + pathStr)));
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions