diff --git a/pom.xml b/pom.xml index 04a2a60..ecdc295 100644 --- a/pom.xml +++ b/pom.xml @@ -23,27 +23,11 @@ UTF-8 UTF-8 - RELEASE82 + RELEASE150 ${netbeans.run.params.ide} -J-Dnetbeans.full.hack=true - - - - netbeans - NetBeans - http://bits.netbeans.org/nexus/content/groups/netbeans - - false - - - - - - - org.netbeans.modules - org-netbeans-modules-projectapi-nb - ${netbeans.version} - test - - - - org.netbeans.modules - org-netbeans-modules-parsing-nb - ${netbeans.version} - test - org.netbeans.modules @@ -360,31 +340,19 @@ org.hamcrest hamcrest-all - 1.3 + 1.3 test junit junit - 4.10 + 4.13.2 test org.mockito - mockito-all - 1.9.5 - test - - - org.powermock - powermock-module-junit4 - 1.5.1 - test - - - org.powermock - powermock-api-mockito - 1.5.1 + mockito-core + 4.8.0 test @@ -421,21 +389,21 @@ - org.codehaus.mojo + org.apache.netbeans.utilities nbm-maven-plugin - 4.1 + 4.8 org.apache.maven.plugins maven-surefire-plugin - 2.18.1 + 3.0.0-M7 - org.codehaus.mojo + org.apache.netbeans.utilities nbm-maven-plugin true @@ -443,7 +411,7 @@ LICENSE.txt - org.netbeans.modules:org-netbeans-modules-gsf-testrunner + org.netbeans.api:org-netbeans-modules-gsf-testrunner impl @@ -457,21 +425,20 @@ org.apache.maven.plugins maven-jar-plugin - 2.4 + 3.3.0 - - true + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + - org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.10.1 - 1.8 - 1.8 + 17 true -Xlint:unchecked @@ -480,7 +447,7 @@ org.codehaus.mojo javacc-maven-plugin - 2.6 + 3.0.1 generate-parser @@ -495,14 +462,14 @@ net.java.dev.javacc javacc - 7.0.2 + 7.0.12 org.codehaus.mojo exec-maven-plugin - 1.5.0 + 3.1.0 map-tokens @@ -525,7 +492,7 @@ org.codehaus.mojo build-helper-maven-plugin - 1.9.1 + 3.3.0 compile-build-addon @@ -568,11 +535,18 @@ maven-surefire-plugin - -Djava.awt.headless=true -Djna.nosys=true -noverify + java.awt.headless=true: Stop tests hijacking UI on development machine + jna.nosys=true: Don't try to load JNA from the host system, use our dependency instead (needed for Appveyor, which has an old JNA on it) + noverify: Fix for JDK bug with PowerMock + --> + + -Djava.awt.headless=true + -Djna.nosys=true + --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED + --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED + --add-opens=java.base/java.net=ALL-UNNAMED + --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED + 1 false @@ -585,7 +559,7 @@ org.apache.maven.plugins maven-resources-plugin - 2.6 + 3.3.0 set-up-unit-test-data @@ -635,7 +609,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.15 + 3.0.0-M7 @@ -663,7 +637,7 @@ org.apache.maven.plugins maven-resources-plugin - 2.6 + 3.3.0 @@ -685,9 +659,9 @@ - com.mycila.maven-license-plugin - maven-license-plugin - 1.9.0 + com.mycila + license-maven-plugin + 4.2.rc3 @@ -746,8 +720,8 @@ org.jasig.maven - maven-notice-plugin - 1.0.4 + notice-maven-plugin + 2.0.0 license-mappings.xml diff --git a/src/test/java/com/github/drrb/rust/netbeans/cargo/CargoTest.java b/src/test/java/com/github/drrb/rust/netbeans/cargo/CargoTest.java index 89b760e..f245faa 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/cargo/CargoTest.java +++ b/src/test/java/com/github/drrb/rust/netbeans/cargo/CargoTest.java @@ -16,23 +16,21 @@ */ package com.github.drrb.rust.netbeans.cargo; +import static com.github.drrb.rust.netbeans.cargo.Cargo.*; import com.github.drrb.rust.netbeans.commandrunner.CommandFuture; import com.github.drrb.rust.netbeans.commandrunner.CommandRunner; import com.github.drrb.rust.netbeans.commandrunner.HumbleCommandFuture; import com.github.drrb.rust.netbeans.commandrunner.Shell; import com.github.drrb.rust.netbeans.configuration.RustConfiguration; import com.github.drrb.rust.netbeans.project.RustProject; +import static com.github.drrb.rust.netbeans.test.Matchers.isProcess; import com.github.drrb.rust.netbeans.test.TemporaryPreferences; +import java.io.File; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Rule; import org.junit.Test; - -import java.io.File; - -import static com.github.drrb.rust.netbeans.cargo.Cargo.*; -import static com.github.drrb.rust.netbeans.test.Matchers.isProcess; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/src/test/java/com/github/drrb/rust/netbeans/classpath/ClasspathSettingProjectOpenedHookTest.java b/src/test/java/com/github/drrb/rust/netbeans/classpath/ClasspathSettingProjectOpenedHookTest.java index 07faa25..a8ddbfd 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/classpath/ClasspathSettingProjectOpenedHookTest.java +++ b/src/test/java/com/github/drrb/rust/netbeans/classpath/ClasspathSettingProjectOpenedHookTest.java @@ -1,18 +1,13 @@ /** - * Copyright (C) 2017 drrb - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * Copyright (C) 2017 drrb This program is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program. If not, see + * . */ package com.github.drrb.rust.netbeans.classpath; @@ -26,33 +21,32 @@ import org.hamcrest.TypeSafeMatcher; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import org.mockito.Mock; +import static org.mockito.ArgumentMatchers.eq; +import org.mockito.Mockito; import static org.mockito.Mockito.verify; +import static org.mockito.hamcrest.MockitoHamcrest.argThat; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(GlobalPathRegistry.class) +// public class ClasspathSettingProjectOpenedHookTest { private RustProject project; - @Mock + private GlobalPathRegistry globalPathRegistry; + private ClasspathSettingProjectOpenedHook hook; @Before public void setUp() { - FileObject projectDirectory = FileUtil.toFileObject(getData("ClasspathSettingProjectOpenedHookTest/testrustproject")); + FileObject projectDirectory = FileUtil + .toFileObject(getData("ClasspathSettingProjectOpenedHookTest/testrustproject")); + globalPathRegistry = Mockito.mock(GlobalPathRegistry.class); project = new RustProject(projectDirectory, null); hook = new ClasspathSettingProjectOpenedHook(project, globalPathRegistry); } @@ -61,7 +55,8 @@ public void setUp() { public void shouldRegisterSourceDirectoryAsClasspathRoot() { hook.projectOpened(); - verify(globalPathRegistry).register(eq(SOURCE_CLASSPATH_ID), argThat(hasItemInArray(classpathWithRootThat(matchesRegex(".*testrustproject/src$"))))); + verify(globalPathRegistry).register(eq(SOURCE_CLASSPATH_ID), + argThat(hasItemInArray(classpathWithRootThat(matchesRegex(".*testrustproject/src$"))))); } private ClasspathWithRoot classpathWithRootThat(Matcher folder) { diff --git a/src/test/java/com/github/drrb/rust/netbeans/indexing/IndexItemSerializerTest.java b/src/test/java/com/github/drrb/rust/netbeans/indexing/IndexItemSerializerTest.java index 2569091..c94a5bb 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/indexing/IndexItemSerializerTest.java +++ b/src/test/java/com/github/drrb/rust/netbeans/indexing/IndexItemSerializerTest.java @@ -16,26 +16,17 @@ */ package com.github.drrb.rust.netbeans.indexing; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.netbeans.modules.parsing.spi.indexing.support.IndexDocument; import org.netbeans.modules.parsing.spi.indexing.support.IndexResult; import org.openide.filesystems.FileObject; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import static com.github.drrb.rust.netbeans.test.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.mock; -/** - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({IndexDocument.class, IndexResult.class}) public class IndexItemSerializerTest { private IndexItemSerializer serializer; diff --git a/src/test/java/com/github/drrb/rust/netbeans/keypress/RustBracketCompleterTest.java b/src/test/java/com/github/drrb/rust/netbeans/keypress/RustBracketCompleterTest.java index b3e3f31..66ca9ed 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/keypress/RustBracketCompleterTest.java +++ b/src/test/java/com/github/drrb/rust/netbeans/keypress/RustBracketCompleterTest.java @@ -17,27 +17,23 @@ package com.github.drrb.rust.netbeans.keypress; import com.github.drrb.rust.netbeans.RustDocument; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import org.junit.Test; -import static org.junit.Assert.*; import org.junit.Before; -import org.junit.runner.RunWith; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor.Context; import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor.MutableContext; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * @todo Try to test this with CslTestBase/golden files instead */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(MutableContext.class) + public class RustBracketCompleterTest { private RustBracketCompleter interceptor; diff --git a/src/test/java/com/github/drrb/rust/netbeans/project/RustProjectFactoryTest.java b/src/test/java/com/github/drrb/rust/netbeans/project/RustProjectFactoryTest.java index ec6aa6c..de084eb 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/project/RustProjectFactoryTest.java +++ b/src/test/java/com/github/drrb/rust/netbeans/project/RustProjectFactoryTest.java @@ -16,15 +16,15 @@ */ package com.github.drrb.rust.netbeans.project; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.openide.filesystems.FileObject; -import static org.junit.Assert.*; -import static org.hamcrest.Matchers.*; -import static org.mockito.Mockito.*; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.spi.project.ProjectState; @@ -32,13 +32,10 @@ /** * */ -@RunWith(MockitoJUnitRunner.class) public class RustProjectFactoryTest { - @Mock - private FileObject projectFolder; - @Mock - private ProjectState projectState; + private FileObject projectFolder = mock(FileObject.class); + private ProjectState projectState=mock(ProjectState.class); private RustProjectFactory factory; @Before @@ -65,7 +62,7 @@ public void shouldIdentifyAProjectWithACargoFile() { public void shouldNotLoadAProjectIfItIsntARustProjectDirectory() throws Exception { Project project = factory.loadProject(projectFolder, projectState); - assertNull(project); + assertThat(project, is(nullValue())); } @Test @@ -73,7 +70,7 @@ public void shouldLoadAProjectFromAProjectDirectory() throws Exception { projectFolder = aProject(); Project project = factory.loadProject(projectFolder, projectState); - assertNotNull(project); + assertThat(project, is(not(nullValue()))); } @Test diff --git a/src/test/java/com/github/drrb/rust/netbeans/test/Matchers.java b/src/test/java/com/github/drrb/rust/netbeans/test/Matchers.java index fc13f29..66fbd77 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/test/Matchers.java +++ b/src/test/java/com/github/drrb/rust/netbeans/test/Matchers.java @@ -1,18 +1,13 @@ /** - * Copyright (C) 2017 drrb - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * Copyright (C) 2017 drrb This program is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program. If not, see + * . */ package com.github.drrb.rust.netbeans.test; @@ -26,7 +21,6 @@ import javax.swing.ImageIcon; import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; import org.hamcrest.TypeSafeMatcher; import org.mockito.ArgumentMatcher; import org.netbeans.modules.csl.api.CompletionProposal; @@ -42,6 +36,7 @@ public class Matchers extends org.hamcrest.Matchers { public static Matcher matchesRegex(final String regex) { return new TypeSafeMatcher() { + @Override public boolean matchesSafely(String item) { return item.matches(regex); @@ -78,6 +73,7 @@ public void describeTo(Description description) { public Matcher> mappedToValueThat(final Matcher expectedValueMatcher) { return new TypeSafeMatcher>() { + @Override public boolean matchesSafely(Map item) { if (item.containsKey(expectedKey)) { @@ -101,8 +97,10 @@ public void describeTo(Description description) { } } - public static Matcher structureItem(final String name, final OffsetRange offsetRange, final ElementKind elementKind, final Modifier... modifiers) { + public static Matcher structureItem(final String name, final OffsetRange offsetRange, + final ElementKind elementKind, final Modifier... modifiers) { return new TypeSafeMatcher() { + @Override public boolean matchesSafely(StructureItem item) { return name.equals(item.getName()) @@ -122,12 +120,14 @@ public void describeTo(Description description) { }; } - public static CompletionProposalMatcher completionProposal(final String name, final ElementKind kind, final Modifier... modifiers) { + public static CompletionProposalMatcher completionProposal(final String name, final ElementKind kind, + final Modifier... modifiers) { return new CompletionProposalMatcher(name, kind, modifiers); } public static Matcher hasDimensions(final int width, final int height) { return new TypeSafeMatcher() { + @Override public boolean matchesSafely(ImageIcon item) { return item.getIconWidth() == width @@ -144,8 +144,11 @@ public void describeTo(Description description) { public static class CompletionProposalMatcher extends TypeSafeMatcher { private final String name; + private final ElementKind kind; + private final Modifier[] modifiers; + private Matcher iconMatcher = is(nullValue()); public CompletionProposalMatcher(String name, ElementKind kind, Modifier[] modifiers) { @@ -180,9 +183,12 @@ public static ProcessMatcher isProcess(String... commandParts) { return new ProcessMatcher(commandParts); } - public static class ProcessMatcher extends ArgumentMatcher { + public static class ProcessMatcher implements ArgumentMatcher { + private final List expectedCommandParts; + private final Map expectedEnvVars = new HashMap<>(); + private Matcher expectedWorkingDir = anything(); private ProcessMatcher(String... commandParts) { @@ -200,8 +206,7 @@ public ProcessMatcher withEnvVar(String key, String value) { } @Override - public boolean matches(Object argument) { - ProcessBuilder pb = (ProcessBuilder) argument; + public boolean matches(ProcessBuilder pb) { if (!pb.command().equals(expectedCommandParts)) { System.out.println("Commands differ"); System.out.println("expected = " + expectedCommandParts); @@ -227,5 +232,4 @@ public boolean matches(Object argument) { return true; } } - } diff --git a/src/test/java/com/github/drrb/rust/netbeans/test/TestData.java b/src/test/java/com/github/drrb/rust/netbeans/test/TestData.java index d89ab8c..54622e4 100644 --- a/src/test/java/com/github/drrb/rust/netbeans/test/TestData.java +++ b/src/test/java/com/github/drrb/rust/netbeans/test/TestData.java @@ -19,9 +19,6 @@ import java.io.File; import java.nio.file.FileSystems; -/** - * - */ public class TestData { public static File getData(String path) { diff --git a/src/test/java/org/netbeans/api/editor/mimelookup/test/MockMimeLookup.java b/src/test/java/org/netbeans/api/editor/mimelookup/test/MockMimeLookup.java index 8d8fc63..33835bc 100644 --- a/src/test/java/org/netbeans/api/editor/mimelookup/test/MockMimeLookup.java +++ b/src/test/java/org/netbeans/api/editor/mimelookup/test/MockMimeLookup.java @@ -33,9 +33,9 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.spi.editor.mimelookup.MimeDataProvider; import org.openide.util.Lookup; @@ -57,7 +57,7 @@ */ public final class MockMimeLookup implements MimeDataProvider { - private static final Map MAP = new HashMap(); + private static final Map MAP = new ConcurrentHashMap<>(); /** * Sets the lookup for mimePath with zero or more delegate lookups. @@ -66,17 +66,7 @@ public final class MockMimeLookup implements MimeDataProvider { * @param lookups The delegate lookups. */ public static void setLookup(MimePath mimePath, Lookup... lookups) { - Lkp toUpdate = null; - - synchronized (MAP) { - Lkp lkp = MAP.get(mimePath); - if (lkp == null) { - lkp = new Lkp(lookups); - MAP.put(mimePath, lkp); - } else { - toUpdate = lkp; - } - } + Lkp toUpdate = MAP.computeIfAbsent(mimePath, id -> new Lkp(lookups)); if (toUpdate != null) { toUpdate.set(lookups); diff --git a/src/test/java/org/netbeans/modules/csl/api/test/CslTestBase.java b/src/test/java/org/netbeans/modules/csl/api/test/CslTestBase.java index 1f7ea67..8690c53 100644 --- a/src/test/java/org/netbeans/modules/csl/api/test/CslTestBase.java +++ b/src/test/java/org/netbeans/modules/csl/api/test/CslTestBase.java @@ -64,76 +64,37 @@ import java.lang.reflect.Method; import java.net.URL; import java.nio.CharBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import java.util.prefs.Preferences; -import javax.swing.Action; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; -import javax.swing.text.BadLocationException; -import javax.swing.text.Caret; -import org.netbeans.api.lexer.Language; -import org.netbeans.api.lexer.TokenSequence; -import org.netbeans.junit.NbTestCase; -import org.netbeans.lib.lexer.LanguageManager; -import org.netbeans.modules.csl.api.CodeCompletionContext; -import org.netbeans.modules.csl.api.Error; -import org.netbeans.modules.csl.api.HintFix; -import org.netbeans.modules.csl.api.KeystrokeHandler; -import org.netbeans.modules.csl.api.ColoringAttributes; -import org.netbeans.modules.csl.api.CodeCompletionHandler; -import org.netbeans.modules.csl.api.CodeCompletionHandler.QueryType; -import org.netbeans.modules.csl.api.CodeCompletionResult; -import org.netbeans.modules.csl.api.CompletionProposal; -import org.netbeans.modules.csl.api.ElementKind; -import org.netbeans.modules.csl.api.Formatter; -import org.netbeans.modules.csl.api.GsfLanguage; -import org.netbeans.modules.csl.api.Hint; -import org.netbeans.modules.csl.api.HintsProvider; -import org.netbeans.modules.csl.api.HtmlFormatter; -import org.netbeans.modules.csl.api.InstantRenamer; -import org.netbeans.modules.csl.api.OccurrencesFinder; -import org.netbeans.modules.csl.api.SemanticAnalyzer; -import org.netbeans.modules.csl.api.StructureItem; -import org.netbeans.modules.csl.api.StructureScanner; -import org.netbeans.modules.csl.api.HintSeverity; -import org.netbeans.modules.csl.api.Rule; -import org.netbeans.modules.csl.api.Rule.AstRule; -import org.netbeans.modules.csl.api.Rule.ErrorRule; -import org.netbeans.modules.csl.api.Rule.SelectionRule; -import org.netbeans.modules.csl.api.Rule.UserConfigurableRule; -import org.netbeans.modules.csl.api.RuleContext; -import org.netbeans.modules.csl.spi.DefaultLanguageConfig; -import org.netbeans.modules.parsing.api.ResultIterator; -import org.netbeans.modules.parsing.spi.indexing.Indexable; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileSystem; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.logging.Handler; import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import java.util.prefs.Preferences; +import javax.swing.Action; import javax.swing.JEditorPane; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent.ElementChange; import javax.swing.event.DocumentEvent.EventType; import javax.swing.event.DocumentListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; import javax.swing.text.Element; @@ -145,25 +106,55 @@ import org.netbeans.api.editor.settings.SimpleValueNames; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.lexer.Language; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenHierarchyEvent; import org.netbeans.api.lexer.TokenHierarchyListener; +import org.netbeans.api.lexer.TokenSequence; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.BaseKit; import org.netbeans.editor.Utilities; import org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.netbeans.lib.lexer.LanguageManager; +import org.netbeans.modules.csl.api.CodeCompletionContext; +import org.netbeans.modules.csl.api.CodeCompletionHandler; +import org.netbeans.modules.csl.api.CodeCompletionHandler.QueryType; import org.netbeans.modules.csl.api.CodeCompletionHandler2; -import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; +import org.netbeans.modules.csl.api.CodeCompletionResult; +import org.netbeans.modules.csl.api.ColoringAttributes; +import org.netbeans.modules.csl.api.CompletionProposal; import org.netbeans.modules.csl.api.DeclarationFinder; import org.netbeans.modules.csl.api.DeclarationFinder.DeclarationLocation; import org.netbeans.modules.csl.api.Documentation; import org.netbeans.modules.csl.api.EditHistory; import org.netbeans.modules.csl.api.EditList; +import org.netbeans.modules.csl.api.ElementKind; +import org.netbeans.modules.csl.api.Error; +import org.netbeans.modules.csl.api.Formatter; +import org.netbeans.modules.csl.api.GsfLanguage; +import org.netbeans.modules.csl.api.Hint; +import org.netbeans.modules.csl.api.HintFix; +import org.netbeans.modules.csl.api.HintSeverity; +import org.netbeans.modules.csl.api.HintsProvider; +import org.netbeans.modules.csl.api.HtmlFormatter; +import org.netbeans.modules.csl.api.InstantRenamer; +import org.netbeans.modules.csl.api.KeystrokeHandler; +import org.netbeans.modules.csl.api.OccurrencesFinder; import org.netbeans.modules.csl.api.OffsetRange; import org.netbeans.modules.csl.api.PreviewableFix; +import org.netbeans.modules.csl.api.Rule; +import org.netbeans.modules.csl.api.Rule.AstRule; +import org.netbeans.modules.csl.api.Rule.ErrorRule; +import org.netbeans.modules.csl.api.Rule.SelectionRule; +import org.netbeans.modules.csl.api.Rule.UserConfigurableRule; +import org.netbeans.modules.csl.api.RuleContext; +import org.netbeans.modules.csl.api.SemanticAnalyzer; import org.netbeans.modules.csl.api.Severity; +import org.netbeans.modules.csl.api.StructureItem; +import org.netbeans.modules.csl.api.StructureScanner; import org.netbeans.modules.csl.core.CslEditorKit; import org.netbeans.modules.csl.core.GsfIndentTaskFactory; import org.netbeans.modules.csl.core.GsfReformatTaskFactory; @@ -172,13 +163,16 @@ import org.netbeans.modules.csl.hints.infrastructure.GsfHintsManager; import org.netbeans.modules.csl.hints.infrastructure.HintsSettings; import org.netbeans.modules.csl.spi.DefaultError; +import org.netbeans.modules.csl.spi.DefaultLanguageConfig; import org.netbeans.modules.csl.spi.GsfUtilities; import org.netbeans.modules.csl.spi.ParserResult; import org.netbeans.modules.editor.NbEditorKit; import org.netbeans.modules.editor.bracesmatching.api.BracesMatchingTestUtils; import org.netbeans.modules.editor.indent.api.Reformat; +import org.netbeans.modules.editor.indent.spi.CodeStylePreferences; import org.netbeans.modules.parsing.api.Embedding; import org.netbeans.modules.parsing.api.ParserManager; +import org.netbeans.modules.parsing.api.ResultIterator; import org.netbeans.modules.parsing.api.Snapshot; import org.netbeans.modules.parsing.api.Source; import org.netbeans.modules.parsing.api.UserTask; @@ -192,16 +186,22 @@ import org.netbeans.modules.parsing.spi.indexing.Context; import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer; import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory; +import org.netbeans.modules.parsing.spi.indexing.Indexable; import org.netbeans.modules.parsing.spi.indexing.PathRecognizer; import org.netbeans.spi.editor.bracesmatching.BracesMatcher; import org.netbeans.spi.editor.bracesmatching.BracesMatcherFactory; import org.netbeans.spi.editor.bracesmatching.MatcherContext; import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; import org.openide.filesystems.MultiFileSystem; import org.openide.filesystems.Repository; import org.openide.filesystems.XMLFileSystem; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; +import org.openide.util.Exceptions; import org.openide.util.Pair; import org.openide.util.test.MockLookup; diff --git a/src/test/java/org/netbeans/modules/csl/api/test/CslTestHelper.java b/src/test/java/org/netbeans/modules/csl/api/test/CslTestHelper.java index dcf99e8..c1594d5 100644 --- a/src/test/java/org/netbeans/modules/csl/api/test/CslTestHelper.java +++ b/src/test/java/org/netbeans/modules/csl/api/test/CslTestHelper.java @@ -1,22 +1,30 @@ /** - * Copyright (C) 2017 drrb - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * Copyright (C) 2017 drrb This program is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program. If not, see + * . */ package org.netbeans.modules.csl.api.test; import com.google.common.base.Strings; +import java.awt.*; +import java.io.File; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.swing.*; +import javax.swing.text.Caret; +import javax.swing.text.DefaultEditorKit; +import javax.swing.text.Document; import org.junit.internal.AssumptionViolatedException; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -38,36 +46,26 @@ import org.openide.filesystems.FileUtil; import org.openide.nodes.Node; -import javax.swing.*; -import javax.swing.text.Caret; -import javax.swing.text.DefaultEditorKit; -import javax.swing.text.Document; -import java.awt.*; -import java.io.File; -import java.lang.annotation.Retention; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * */ public class CslTestHelper extends CslTestBase implements TestRule { + @Retention(RUNTIME) public @interface RunInEventQueueThread { } + @Retention(RUNTIME) public @interface Classpath { + String id(); + String[] value(); } private boolean runInEventQueueThread = false; + protected Map classpaths = null; public static CslTestHelper forLanguage(DefaultLanguageConfig language) { @@ -75,6 +73,7 @@ public static CslTestHelper forLanguage(DefaultLanguageConfig language) { } private final DefaultLanguageConfig language; + public CslTestHelper(DefaultLanguageConfig language) { super(""); this.language = language; @@ -83,6 +82,7 @@ public CslTestHelper(DefaultLanguageConfig language) { @Override public Statement apply(final Statement base, final Description description) { return new Statement() { + @Override public void evaluate() throws Throwable { Classpath definedClasspath = description.getAnnotation(Classpath.class); @@ -104,6 +104,7 @@ public void evaluate() throws Throwable { runInEventQueueThread = true; try { EventQueue.invokeAndWait(new Runnable() { + @Override public void run() { try { @@ -157,11 +158,16 @@ private Object[] mimeObjects(MimePath mimePath, String... mimeRoots) { for (String mimeRoot : mimeRoots) { String mimeFilePath = "Editors/" + mimePath.getPath() + mimeRoot; FileObject mimeDir = FileUtil.getConfigFile(mimeFilePath); - assertNotNull(String.format("Tried to load files from config dir '%s', but it did not exist.", mimeFilePath), mimeDir); + assertNotNull(String.format("Tried to load files from config dir '%s', but it did not exist.", + mimeFilePath), mimeDir); FileObject[] mimeFiles = mimeDir.getChildren(); for (FileObject mimeFile : mimeFiles) { if (mimeFile.isData()) { - mimeObjects.add(FileUtil.getConfigObject(mimeFile.getPath(), Object.class)); + final Object configObject = FileUtil.getConfigObject(mimeFile.getPath(), Object.class); + if (configObject != null) { + // config object at path Editors/org-netbeans-modules-java-source-indexing-JavaBinaryIndexer$Factory-register.instance is null. why? + mimeObjects.add(configObject); + } } } } @@ -193,7 +199,8 @@ public FileObject getTestFile(String relFilePath) { } @Override - protected void configureIndenters(Document document, Formatter formatter, boolean indentOnly, String mimeType) { + protected void configureIndenters(Document document, Formatter formatter, boolean indentOnly, + String mimeType) { // Parent implementation messes with the MimeLookup, so don't call it } @@ -214,7 +221,8 @@ public TokenSequence tokenize(String text) { } @Override - public void assertDescriptionMatches(String relFilePath, String description, boolean includeTestName, String ext) throws Exception { + public void assertDescriptionMatches(String relFilePath, String description, boolean includeTestName, + String ext) throws Exception { super.assertDescriptionMatches(relFilePath, description, includeTestName, ext); } @@ -285,7 +293,9 @@ public void checkIndexer(String relFilePath) throws Exception { } protected static class TreeView { + private final Node root; + private StringBuilder view; public TreeView(Node root) { diff --git a/src/test/java/org/netbeans/modules/csl/api/test/HeadlessDelegatingToolkit.java b/src/test/java/org/netbeans/modules/csl/api/test/HeadlessDelegatingToolkit.java new file mode 100644 index 0000000..51b47ff --- /dev/null +++ b/src/test/java/org/netbeans/modules/csl/api/test/HeadlessDelegatingToolkit.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2022 alexander.kronenwett + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package org.netbeans.modules.csl.api.test; + +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.HeadlessException; +import java.awt.Image; +import java.awt.PrintJob; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.font.TextAttribute; +import java.awt.im.InputMethodHighlight; +import java.awt.image.ColorModel; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.net.URL; +import java.util.Map; +import java.util.Properties; + +/** + * A wrapper around a default {@link Toolkit} whose only purpose is to surpass + * the {@link HeadlessException} that is thrown by + * {@link Toolkit#getSystemSelection()}. The default Toolkit is headless and we + * are in headless mode in the tests so that the NB UI is not captured all the + * time. + */ +public class HeadlessDelegatingToolkit extends Toolkit { + + private final Toolkit wrapped; + + public HeadlessDelegatingToolkit(Toolkit wrapped) { + this.wrapped = wrapped; + } + + @Override + public Dimension getScreenSize() throws HeadlessException { + return wrapped.getScreenSize(); + } + + @Override + public int getScreenResolution() throws HeadlessException { + return wrapped.getScreenResolution(); + } + + @Override + public ColorModel getColorModel() throws HeadlessException { + return wrapped.getColorModel(); + } + + @Override + public String[] getFontList() { + return wrapped.getFontList(); + } + + @Override + public FontMetrics getFontMetrics(Font font) { + return wrapped.getFontMetrics(font); + } + + @Override + public void sync() { + wrapped.sync(); + } + + @Override + public Image getImage(String filename) { + return wrapped.getImage(filename); + } + + @Override + public Image getImage(URL url) { + return wrapped.getImage(url); + } + + @Override + public Image createImage(String filename) { + return wrapped.createImage(filename); + } + + @Override + public Image createImage(URL url) { + return wrapped.createImage(url); + } + + @Override + public Image createImage(byte[] imagedata) { + return wrapped.createImage(imagedata); + } + + @Override + public boolean prepareImage(Image image, int width, int height, ImageObserver observer) { + return wrapped.prepareImage(image, width, height, observer); + } + + @Override + public int checkImage(Image image, int width, int height, ImageObserver observer) { + return wrapped.checkImage(image, width, height, observer); + } + + @Override + public Image createImage(byte[] imagedata, int imageoffset, int imagelength) { + return wrapped.createImage(imagedata, imageoffset, imagelength); + } + + @Override + public Image createImage(ImageProducer producer) { + return wrapped.createImage(producer); + } + + @Override + public PrintJob getPrintJob(Frame frame, String jobtitle, Properties props) { + return wrapped.getPrintJob(frame, jobtitle, props); + } + + @Override + public void beep() { + wrapped.beep(); + } + + @Override + public Clipboard getSystemClipboard() throws HeadlessException { + return wrapped.getSystemClipboard(); + } + + @Override + public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { + return wrapped.isModalityTypeSupported(modalityType); + } + + @Override + public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType) { + return wrapped.isModalExclusionTypeSupported(modalExclusionType); + } + + @Override + public Map mapInputMethodHighlight(InputMethodHighlight highlight) + throws HeadlessException { + return wrapped.mapInputMethodHighlight(highlight); + } + + @Override + public Clipboard getSystemSelection() throws HeadlessException { + // The original method throws a HeadlessException, which we don't want in tests + return null; + } + + @Override + protected EventQueue getSystemEventQueueImpl() { + return wrapped.getSystemEventQueue(); + } +} diff --git a/src/test/java/org/netbeans/modules/csl/api/test/JEditorPaneThatWorksWithHeadlessToolkit.java b/src/test/java/org/netbeans/modules/csl/api/test/JEditorPaneThatWorksWithHeadlessToolkit.java index c784739..7eb5b97 100644 --- a/src/test/java/org/netbeans/modules/csl/api/test/JEditorPaneThatWorksWithHeadlessToolkit.java +++ b/src/test/java/org/netbeans/modules/csl/api/test/JEditorPaneThatWorksWithHeadlessToolkit.java @@ -1,36 +1,23 @@ /** - * Copyright (C) 2017 drrb - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * Copyright (C) 2017 drrb This program is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program. If not, see + * . */ package org.netbeans.modules.csl.api.test; -import sun.awt.HeadlessToolkit; - -import javax.swing.*; -import java.awt.*; -import java.awt.datatransfer.Clipboard; +import java.awt.Toolkit; +import javax.swing.JEditorPane; class JEditorPaneThatWorksWithHeadlessToolkit extends JEditorPane { + @Override public Toolkit getToolkit() { - Toolkit originalToolkit = super.getToolkit(); - return new HeadlessToolkit(originalToolkit) { - @Override - public Clipboard getSystemSelection() throws HeadlessException { - return null; // The default implementation raises a HeadlessException in tests. - } - }; + return new HeadlessDelegatingToolkit(Toolkit.getDefaultToolkit()); } -} +} \ No newline at end of file diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000..ca6ee9c --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file