-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: remove usage of deprecated methods
- Loading branch information
Showing
8 changed files
with
71 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 30 additions & 25 deletions
55
src/test/java/org/antlr/intellij/plugin/ANTLRv4ExternalAnnotatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,50 @@ | ||
package org.antlr.intellij.plugin; | ||
|
||
import com.google.common.collect.Iterables; | ||
import com.intellij.lang.annotation.Annotation; | ||
import com.intellij.lang.annotation.HighlightSeverity; | ||
import com.intellij.psi.PsiFile; | ||
import org.antlr.intellij.plugin.validation.CreateRuleFix; | ||
import com.intellij.codeInsight.daemon.impl.HighlightInfo; | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase; | ||
import org.antlr.intellij.plugin.validation.AddTokenDefinitionFix; | ||
import org.antlr.intellij.plugin.validation.GrammarIssue; | ||
import org.antlr.v4.tool.ANTLRMessage; | ||
import org.antlr.v4.tool.ErrorType; | ||
import org.antlr.intellij.plugin.validation.CreateRuleFix; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class ANTLRv4ExternalAnnotatorTest { | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Test | ||
public void shouldRegisterTokenDefinitionQuickFix() { | ||
public class ANTLRv4ExternalAnnotatorTest extends BasePlatformTestCase { | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
TestUtils.tearDownIgnoringObjectNotDisposedException(super::tearDown); | ||
} | ||
|
||
public void testShouldRegisterTokenDefinitionQuickFix() { | ||
// given: | ||
Annotation annotation = new Annotation(0,0, HighlightSeverity.WARNING, "msg", "tooltip"); | ||
myFixture.configureByText("test.g4", "grammar test; rule: TOKEN;"); | ||
|
||
// when: | ||
ANTLRv4ExternalAnnotator.registerFixForAnnotation(annotation, new GrammarIssue(new ANTLRMessage(ErrorType.IMPLICIT_TOKEN_DEFINITION)), null); | ||
List<HighlightInfo> result = myFixture.doHighlighting(); | ||
|
||
// then: | ||
Annotation.QuickFixInfo quickFix = Iterables.getOnlyElement(annotation.getQuickFixes()); | ||
Assert.assertTrue(quickFix.quickFix instanceof AddTokenDefinitionFix); | ||
var quickFix = result.stream() | ||
.map(el -> el.findRegisteredQuickFix((action, range) -> action)) | ||
.filter(Objects::nonNull) | ||
.findFirst().orElseThrow(); | ||
|
||
Assert.assertTrue(quickFix.getAction() instanceof AddTokenDefinitionFix); | ||
} | ||
|
||
@Test | ||
public void shouldRegisterCreateRuleQuickFix() { | ||
public void testShouldRegisterCreateRuleQuickFix() { | ||
// given: | ||
Annotation annotation = new Annotation(0,0, HighlightSeverity.WARNING, "msg", "tooltip"); | ||
PsiFile file = Mockito.mock(PsiFile.class); | ||
Mockito.when(file.getText()).thenReturn("sample text"); | ||
myFixture.configureByText("test.g4", "grammar test; rule: undefined_rule;"); | ||
|
||
// when: | ||
ANTLRv4ExternalAnnotator.registerFixForAnnotation(annotation, new GrammarIssue(new ANTLRMessage(ErrorType.UNDEFINED_RULE_REF)), file); | ||
List<HighlightInfo> result = myFixture.doHighlighting(); | ||
|
||
// then: | ||
Annotation.QuickFixInfo quickFix = Iterables.getOnlyElement(annotation.getQuickFixes()); | ||
Assert.assertTrue(quickFix.quickFix instanceof CreateRuleFix); | ||
var quickFix = result.stream() | ||
.map(el -> el.findRegisteredQuickFix((action, range) -> action)) | ||
.filter(Objects::nonNull) | ||
.findFirst().orElseThrow(); | ||
|
||
Assert.assertTrue(quickFix.getAction() instanceof CreateRuleFix); | ||
} | ||
} |