You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Georg Sorst (JIRA)" <ji...@apache.org> on 2016/05/06 21:57:12 UTC

[jira] [Updated] (SOLR-9081) Make SolrTestCaseJ4.beforeClass() / .afterClass() public so it works with Mockito

     [ https://issues.apache.org/jira/browse/SOLR-9081?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Sorst updated SOLR-9081:
------------------------------
    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:

{code:title=MockitoTest.java|borderStyle=solid}
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 */
    }
}
{code}

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}}

  was:
{{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:

{code:title=MockitoTest.java|borderStyle=solid}
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 */
    }
}
{code}

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


> Make SolrTestCaseJ4.beforeClass() / .afterClass() public so it works with Mockito
> ---------------------------------------------------------------------------------
>
>                 Key: SOLR-9081
>                 URL: https://issues.apache.org/jira/browse/SOLR-9081
>             Project: Solr
>          Issue Type: Bug
>          Components: Tests
>    Affects Versions: 6.0
>            Reporter: Georg Sorst
>            Priority: Blocker
>
> {{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:
> {code:title=MockitoTest.java|borderStyle=solid}
> 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 */
>     }
> }
> {code}
> 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}}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org