Uploaded image for project: 'Unitils'
  1. Unitils
  2. UNI-238

Improve exception message when trying to mock a static method

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.1
    • Fix Version/s: None
    • Component/s: mock
    • Labels:
      None
    • Environment:
      linux x64, java 1.6 (64-bit jvm), JUnit 4.4

      Description

      If I have a test that uses tries to cause an exception on a static method of a mock, I get an exception at runtime.

      Here is a code snippet that would cause this (It mocks the FileUtils class from apache commons):

          // Mock declaration
          private Mock<FileUtils> mockFileUtils;


          @Test(expected = IOException.class)
          public void testMockedFileUtilsThrows() throws IOException {
                  mockFileUtils.raises(IOException.class).deleteDirectory(null);
          }

      When the test runs, I get this message in the exception:
      mockFileUtils.raises() must be followed by a method invocation on the returned proxy. E.g. mockFileUtils.raises().myMethod();

      If you look at the code, it is followed by deleteDirectory, but the code doesn't understand this at runtime.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              davija James Davis
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: