Skip to content

Commit

Permalink
Pull checkstyle#6424: solved pitest issues with ImportOrderCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Feb 15, 2019
1 parent b550198 commit a8bd568
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@
import static org.junit.Assert.fail;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import antlr.CommonHiddenStreamToken;
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

@RunWith(PowerMockRunner.class)
@PrepareForTest(ImportOrderOption.class)
public class ImportOrderCheckTest extends AbstractModuleTestSupport {

@Override
Expand Down Expand Up @@ -654,7 +648,7 @@ public void testMultiplePatternMatches() throws Exception {

// -@cs[ForbidAnnotationElementValue] Will examine turkish failure
@Test(expected = IllegalStateException.class)
public void testVisitTokenSwitchReflection() {
public void testVisitTokenSwitchReflection() throws Exception {
// Create mock ast
final DetailAST astImport = mockAST(TokenTypes.IMPORT, "import", "mockfile", 0, 0);
final DetailAST astIdent = mockAST(TokenTypes.IDENT, "myTestImport", "mockfile", 0, 0);
Expand All @@ -664,10 +658,7 @@ public void testVisitTokenSwitchReflection() {

// Set unsupported option
final ImportOrderCheck mock = new ImportOrderCheck();
final ImportOrderOption importOrderOptionMock = PowerMockito.mock(ImportOrderOption.class);
Whitebox.setInternalState(importOrderOptionMock, "name", "NEW_OPTION_FOR_UT");
Whitebox.setInternalState(importOrderOptionMock, "ordinal", 5);
Whitebox.setInternalState(mock, "option", importOrderOptionMock);
TestUtil.getClassDeclaredField(ImportOrderCheck.class, "option").set(mock, null);

// expecting IllegalStateException
mock.visitToken(astImport);
Expand Down

0 comments on commit a8bd568

Please sign in to comment.