Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-9081

Make SolrTestCaseJ4.beforeClass() / .afterClass() public so it works with Mockito

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 5.5, 5.5.1, 6.0, 6.0.1
    • Fix Version/s: 6.1
    • Component/s: Tests
    • Labels:
      None

      Description

      SolrTestCaseJ4.beforeClass() / SolrTestCaseJ4.afterClass() are currently defined as private static void. This causes problems with Mockito, which requires all test framework methods (including @BeforeClass / @AfterClass) to be public.

      The following test case will show this:

      MockitoTest.java
      package com.example;
      
      import org.apache.solr.SolrTestCaseJ4;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.mockito.runners.MockitoJUnitRunner;
      
      @RunWith(MockitoJUnitRunner.class)
      public class MockitoTest extends SolrTestCaseJ4 {
      
          @Test
          public void testSomething() {
            /* Nothing to do, the test runner will fail right away */
          }
      }
      

      It will fail with java.lang.Exception: Method beforeClass() should be public

      The very trivial fix is to change both methods to public static void

      1. SOLR-9081.patch
        1 kB
        Alan Woodward

        Activity

        Hide
        romseygeek Alan Woodward added a comment -

        Thanks Georg, this looks like a no-brainer to me.

        Show
        romseygeek Alan Woodward added a comment - Thanks Georg, this looks like a no-brainer to me.
        Hide
        romseygeek Alan Woodward added a comment -

        Lots of subclasses already have a public beforeClass() or afterClass(), so I just changed the names to setupTestCases and teardownTestCases().

        I'll commit tomorrow, unless somebody objects.

        Show
        romseygeek Alan Woodward added a comment - Lots of subclasses already have a public beforeClass() or afterClass(), so I just changed the names to setupTestCases and teardownTestCases(). I'll commit tomorrow, unless somebody objects.
        Hide
        romseygeek Alan Woodward added a comment -

        Thanks Georg!

        Show
        romseygeek Alan Woodward added a comment - Thanks Georg!
        Show
        hossman Hoss Man added a comment - FYI: commits for this issue had incorrect jra # in commit msg... http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/aed3fc11 http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ec40824b
        Hide
        romseygeek Alan Woodward added a comment -

        D'oh, thanks Hoss.

        Show
        romseygeek Alan Woodward added a comment - D'oh, thanks Hoss.

          People

          • Assignee:
            romseygeek Alan Woodward
            Reporter:
            gs Georg Sorst
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development