From f2079bc5df0bef644cc9ac18e8cf874cd2b7ca78 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 30 Jan 2024 22:58:05 +0100 Subject: [PATCH] Fix various tests so that they can run on JDK 17 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix CanProxyToLocalhostTest: Proxy#toString changed slightly fix JavaCompletionTask121FeaturesTest: add Record to test data fix ConvertToRecordPatternTest and ConvertToNestedRecordPatternTest - enforce parsable source level for hint tests - update record patern syntax in tests Stabilize JS Test testIssue215777 by Matthias - split golden files into two NbTestCase method ordering is always using "natural" order - ClassLoader fields can not be accessed via reflection on JDK 12+ - test method ordering options are not used anywhere atm - disable tests Co-authored-by: Matthias Bläsing --- .../src/org/netbeans/junit/MethodOrder.java | 4 + .../src/org/netbeans/junit/OrderAZTest.java | 3 + .../src/org/netbeans/junit/OrderTest.java | 2 +- .../src/org/netbeans/junit/OrderZATest.java | 3 + ...letion_CaseBody_PatternMatchingSwitch.pass | 1 + ...pletion_Guard_PatternMatchingSwitch_1.pass | 1 + .../modules/java/hints/test/api/HintTest.java | 152 +++++++++--------- .../jdk/ConvertSwitchToRuleSwitchTest.java | 62 +++---- .../jdk/ConvertTextBlockToStringTest.java | 24 +-- .../jdk/ConvertToNestedRecordPatternTest.java | 42 ++--- .../hints/jdk/ConvertToRecordPatternTest.java | 31 ++-- .../hints/jdk/ConvertToTextBlockTest.java | 8 +- .../core/CanProxyToLocalhostTest.java | 5 +- .../{issue215777.js => issue215777_01.js} | 1 - ...15777_01.js.testIssue215777_01.completion} | 0 .../testfiles/completion/issue215777_02.js | 1 + ...15777_02.js.testIssue215777_02.completion} | 1 - .../editor/JsCodeCompletionGeneralTest.java | 4 +- 18 files changed, 173 insertions(+), 172 deletions(-) rename webcommon/javascript2.editor/test/unit/data/testfiles/completion/{issue215777.js => issue215777_01.js} (52%) rename webcommon/javascript2.editor/test/unit/data/testfiles/completion/{issue215777.js.testIssue215777_01.completion => issue215777_01.js.testIssue215777_01.completion} (100%) create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js rename webcommon/javascript2.editor/test/unit/data/testfiles/completion/{issue215777.js.testIssue215777_02.completion => issue215777_02.js.testIssue215777_02.completion} (98%) diff --git a/harness/nbjunit/src/org/netbeans/junit/MethodOrder.java b/harness/nbjunit/src/org/netbeans/junit/MethodOrder.java index ae0c9bd6914b..858e1b4b19aa 100644 --- a/harness/nbjunit/src/org/netbeans/junit/MethodOrder.java +++ b/harness/nbjunit/src/org/netbeans/junit/MethodOrder.java @@ -43,6 +43,9 @@ static void initialize() { String orderS = findOrder(); if (!"natural".equals(orderS)) { // NOI18N try { + // TODO: ClassLoader fields can not be accessed via reflection on JDK 12+ + // see jdk.internal.reflect.Reflection#fieldFilterMap + // this won't work Field classesF = ClassLoader.class.getDeclaredField("classes"); // NOI18N classesF.setAccessible(true); @SuppressWarnings("unchecked") @@ -53,6 +56,7 @@ static void initialize() { } } } catch (Exception x) { + System.err.println("WARNING: test method ordering disabled"); x.printStackTrace(); } } diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderAZTest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderAZTest.java index 569a8b19c12a..cf2ce07dd182 100644 --- a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderAZTest.java +++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderAZTest.java @@ -22,6 +22,7 @@ import junit.framework.TestResult; import junit.framework.TestSuite; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; /** Check the a-z behaviour. @@ -33,6 +34,8 @@ public class OrderAZTest { System.setProperty("NbTestCase.order", "a-z"); } + // method order isn't working, see comment in org.netbeans.junit.MethodOrder + @Ignore @Test public void shuffleTest() throws ClassNotFoundException { Class load = Class.forName("org.netbeans.junit.OrderHid"); TestSuite ts = new TestSuite(load); diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderTest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderTest.java index 97d5f0b1dfe8..fb2644805224 100644 --- a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderTest.java +++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderTest.java @@ -32,7 +32,7 @@ public class OrderTest { static { System.setProperty("NbTestCase.order", "1314372086210"); } - + @Test public void shuffleTest() throws ClassNotFoundException { Class load = Class.forName("org.netbeans.junit.OrderHid"); TestSuite ts = new TestSuite(load); diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderZATest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderZATest.java index a11bde5204e6..ec88e288ad85 100644 --- a/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderZATest.java +++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/OrderZATest.java @@ -22,6 +22,7 @@ import junit.framework.TestResult; import junit.framework.TestSuite; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; /** Check the z-a behaviour. @@ -33,6 +34,8 @@ public class OrderZATest { System.setProperty("NbTestCase.order", "z-a"); } + // method order isn't working, see comment in org.netbeans.junit.MethodOrder + @Ignore @Test public void shuffleTest() throws ClassNotFoundException { Class load = Class.forName("org.netbeans.junit.OrderHid"); TestSuite ts = new TestSuite(load); diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_CaseBody_PatternMatchingSwitch.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_CaseBody_PatternMatchingSwitch.pass index 615e4fb668e5..ab6c90ee2a5a 100644 --- a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_CaseBody_PatternMatchingSwitch.pass +++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_CaseBody_PatternMatchingSwitch.pass @@ -115,6 +115,7 @@ Process ProcessBuilder ProcessHandle Readable +Record ReflectiveOperationException Runnable Runtime diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_Guard_PatternMatchingSwitch_1.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_Guard_PatternMatchingSwitch_1.pass index 572d58bebaf1..315c11c6d36d 100644 --- a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_Guard_PatternMatchingSwitch_1.pass +++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/AutoCompletion_Guard_PatternMatchingSwitch_1.pass @@ -96,6 +96,7 @@ Process ProcessBuilder ProcessHandle Readable +Record ReflectiveOperationException Runnable Runtime diff --git a/java/java.hints.test/src/org/netbeans/modules/java/hints/test/api/HintTest.java b/java/java.hints.test/src/org/netbeans/modules/java/hints/test/api/HintTest.java index 02beebcf0753..7efea72a98fc 100644 --- a/java/java.hints.test/src/org/netbeans/modules/java/hints/test/api/HintTest.java +++ b/java/java.hints.test/src/org/netbeans/modules/java/hints/test/api/HintTest.java @@ -80,13 +80,11 @@ import org.netbeans.modules.java.hints.providers.code.FSWrapper; import org.netbeans.modules.java.hints.providers.code.FSWrapper.ClassWrapper; import org.netbeans.modules.java.hints.providers.spi.HintDescription; -import org.netbeans.modules.java.hints.providers.spi.HintDescription.Worker; import org.netbeans.modules.java.hints.providers.spi.HintDescriptionFactory; import org.netbeans.modules.java.hints.providers.spi.HintMetadata; import org.netbeans.modules.java.hints.providers.spi.HintMetadata.Options; import org.netbeans.modules.java.hints.spiimpl.JavaFixImpl; import org.netbeans.modules.java.hints.spiimpl.JavaFixImpl.Accessor; -import org.netbeans.modules.java.hints.spiimpl.MessageImpl; import org.netbeans.modules.java.hints.spiimpl.SyntheticFix; import org.netbeans.modules.java.hints.spiimpl.batch.BatchUtilities; import org.netbeans.modules.java.hints.spiimpl.hints.HintsInvoker; @@ -98,7 +96,6 @@ import org.netbeans.modules.parsing.api.indexing.IndexingManager; import org.netbeans.modules.parsing.impl.indexing.CacheFolder; import org.netbeans.modules.parsing.impl.indexing.MimeTypes; -import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; import org.netbeans.spi.editor.hints.ErrorDescription; import org.netbeans.spi.editor.hints.Fix; import org.netbeans.spi.editor.hints.Severity; @@ -177,7 +174,7 @@ public class HintTest { private final FileObject cache; private final Preferences testPreferences; private final HintsSettings hintSettings; - private final List checkCompilable = new ArrayList(); + private final List checkCompilable = new ArrayList<>(); private String sourceLevel = "1.5"; private List extraOptions = new ArrayList<>(); private Character caretMarker; @@ -187,7 +184,7 @@ public class HintTest { private ClassPath compileClassPath = ClassPathSupport.createClassPath(new URL[0]); private HintTest() throws Exception { - List layers = new LinkedList(); + List layers = new LinkedList<>(); for (String layer : new String[] {"META-INF/generated-layer.xml"}) { boolean found = false; @@ -222,9 +219,9 @@ private HintTest() throws Exception { Set amt = MimeTypes.getAllMimeTypes(); if (amt == null) { - amt = new HashSet(); + amt = new HashSet<>(); } else { - amt = new HashSet(amt); + amt = new HashSet<>(amt); } amt.add("text/x-java"); MimeTypes.setAllMimeTypes(amt); @@ -381,12 +378,27 @@ private void ensureCompilable(FileObject file) throws IOException, AssertionErro } } + /**Sets a source level for all Java files used in this test. + * + * @param sourceLevel the source level to use while parsing Java files + * @return itself + */ + public HintTest sourceLevel(int sourceLevel) { + assertTrue(sourceLevel >= 8); + return this.sourceLevel(Integer.toString(sourceLevel)); + } + /**Sets a source level for all Java files used in this test. * * @param sourceLevel the source level to use while parsing Java files * @return itself */ public HintTest sourceLevel(String sourceLevel) { + try { + int valid = sourceLevel.startsWith("1.") ? Integer.parseInt(sourceLevel.substring(2)) : Integer.parseInt(sourceLevel); + } catch (NumberFormatException ex) { + throw new IllegalArgumentException(ex); + } this.sourceLevel = sourceLevel; return this; } @@ -459,8 +471,8 @@ public HintOutput run(Class hint, String hintCode) throws Exception { ensureCompilable(file); } - Map> hints = new HashMap>(); - List found = new ArrayList(); + Map> hints = new HashMap<>(); + List found = new ArrayList<>(); for (ClassWrapper w : FSWrapper.listClasses()) { if (hint.getCanonicalName().equals(w.getName().replace('$', '.'))) { @@ -474,8 +486,8 @@ public HintOutput run(Class hint, String hintCode) throws Exception { CodeHintProviderImpl.processClass(w, hints); } - List total = new LinkedList(); - final Set requiresJavaFix = Collections.newSetFromMap(new IdentityHashMap()); + List total = new LinkedList<>(); + final Set requiresJavaFix = Collections.newSetFromMap(new IdentityHashMap<>()); for (final Entry> e : hints.entrySet()) { if (null != hintCode && !e.getKey().id.equals(hintCode)) { @@ -493,20 +505,16 @@ public HintOutput run(Class hint, String hintCode) throws Exception { .setMetadata(e.getKey()) .setAdditionalConstraints(hd.getAdditionalConstraints()) .addOptions(hd.getOptions().toArray(new Options[0])) - .setWorker(new Worker() { - @Override public Collection createErrors(HintContext ctx) { - Collection errors = hd.getWorker().createErrors(ctx); - - if (errors != null) { - for (ErrorDescription ed : errors) { - requiresJavaFix.add(ed); - } - } - - return errors; - } - }) - .produce()); + .setWorker((HintContext ctx) -> { + Collection errors = hd.getWorker().createErrors(ctx); + if (errors != null) { + for (ErrorDescription ed : errors) { + requiresJavaFix.add(ed); + } + } + return errors; + }) + .produce()); } } @@ -514,7 +522,7 @@ public HintOutput run(Class hint, String hintCode) throws Exception { assertNotNull(info); - List result = new ArrayList(); + List result = new ArrayList<>(); Handler h = new Handler() { @Override public void publish(LogRecord record) { @@ -534,10 +542,10 @@ public HintOutput run(Class hint, String hintCode) throws Exception { result.addAll(e.getValue()); } - Collections.sort(result, ERRORS_COMPARATOR); + result.sort(ERRORS_COMPARATOR); - Reference infoRef = new WeakReference(info); - Reference cut = new WeakReference(info.getCompilationUnit()); + Reference infoRef = new WeakReference<>(info); + Reference cut = new WeakReference<>(info.getCompilationUnit()); info = null; @@ -551,7 +559,7 @@ public HintOutput run(Class hint, String hintCode) throws Exception { //must keep the error descriptions (and their Fixes through them) in a field //so that assertGC is able to provide a useful trace of references: - private static Set> DEBUGGING_HELPER = Collections.newSetFromMap(new IdentityHashMap, Boolean>()); + private static Set> DEBUGGING_HELPER = Collections.newSetFromMap(new IdentityHashMap<>()); private CompilationInfo parse(FileObject file) throws DataObjectNotFoundException, IllegalArgumentException, IOException { DataObject od = DataObject.find(file); @@ -576,7 +584,7 @@ private CompilationInfo parse(FileObject file) throws DataObjectNotFoundExceptio } private Map> computeErrors(CompilationInfo info, Iterable hints, AtomicBoolean cancel) { - return new HintsInvoker(hintSettings, caret, cancel).computeHints(info, new TreePath(info.getCompilationUnit()), hints, new LinkedList()); + return new HintsInvoker(hintSettings, caret, cancel).computeHints(info, new TreePath(info.getCompilationUnit()), hints, new LinkedList<>()); } FileObject getSourceRoot() { @@ -596,28 +604,36 @@ private TempPreferences(TempPreferences parent, String name) { newNode = true; } + @Override protected final String getSpi(String key) { return properties().getProperty(key); } + @Override protected final String[] childrenNamesSpi() throws BackingStoreException { return new String[0]; } + @Override protected final String[] keysSpi() throws BackingStoreException { return properties().keySet().toArray(new String[0]); } + @Override protected final void putSpi(String key, String value) { properties().put(key,value); } + @Override protected final void removeSpi(String key) { properties().remove(key); } + @Override protected final void removeNodeSpi() throws BackingStoreException {} + @Override protected void flushSpi() throws BackingStoreException {} + @Override protected void syncSpi() throws BackingStoreException { properties().clear(); } @@ -643,6 +659,7 @@ Properties properties() { return properties; } + @Override protected AbstractPreferences childSpi(String name) { return new TempPreferences(this, name); } @@ -659,22 +676,21 @@ protected AbstractPreferences childSpi(String name) { private class TestSourceForBinaryQuery implements SourceForBinaryQueryImplementation { + @Override public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { FileObject f = URLMapper.findFileObject(binaryRoot); if (buildRoot.equals(f)) { return new SourceForBinaryQuery.Result() { + @Override public FileObject[] getRoots() { return new FileObject[] { sourceRoot, }; } - public void addChangeListener(ChangeListener l) { - } - - public void removeChangeListener(ChangeListener l) { - } + @Override public void addChangeListener(ChangeListener l) {} + @Override public void removeChangeListener(ChangeListener l) {} }; } @@ -687,6 +703,7 @@ public void removeChangeListener(ChangeListener l) { private class TestProxyClassPathProvider implements ClassPathProvider { + @Override public ClassPath findClassPath(FileObject file, String type) { try { if (ClassPath.BOOT == type) { @@ -776,6 +793,7 @@ public DeadlockTask(Phase phase) { this.phase = phase; } + @Override public void run( CompilationController info ) { try { info.toPhase(this.phase); @@ -826,8 +844,8 @@ public HintOutput assertWarnings(String... warnings) { * @throws AssertionError if the given warnings do not match the actual warnings */ public HintOutput assertContainsWarnings(String... warnings) { - Set goldenSet = new HashSet(Arrays.asList(warnings)); - List errorsNames = new LinkedList(); + Set goldenSet = new HashSet<>(Arrays.asList(warnings)); + List errorsNames = new LinkedList<>(); for (ErrorDescription d : errors) { goldenSet.remove(d.toString()); @@ -849,8 +867,8 @@ public HintOutput assertContainsWarnings(String... warnings) { * @throws AssertionError if the given warnings contain the actual warnings */ public HintOutput assertNotContainsWarnings(String... warnings) { - Set goldenSet = new HashSet(Arrays.asList(warnings)); - List errorsNames = new LinkedList(); + Set goldenSet = new HashSet<>(Arrays.asList(warnings)); + List errorsNames = new LinkedList<>(); for (String warning : goldenSet) { if (warning.split(":").length >= 5) { @@ -942,7 +960,7 @@ public AppliedFix applyFix(String fix) throws Exception { assertTrue("Must be computed", warning.getFixes().isComputed()); List fixes = warning.getFixes().getFixes(); - List fixNames = new LinkedList(); + List fixNames = new LinkedList<>(); Fix toApply = null; for (Fix f : fixes) { @@ -989,19 +1007,15 @@ private void doApplyFix(Fix f) throws Exception { private ModificationResult runJavaFix(final JavaFix jf) throws IOException { FileObject file = Accessor.INSTANCE.getFile(jf); JavaSource js = JavaSource.forFileObject(file); - final Map> changes = new HashMap>(); - - ModificationResult mr = js.runModificationTask(new Task() { - public void run(WorkingCopy wc) throws Exception { - if (wc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { - return; - } + final Map> changes = new HashMap<>(); - Map resourceContentChanges = new HashMap(); - Accessor.INSTANCE.process(jf, wc, true, resourceContentChanges, /*Ignored for now:*/new ArrayList()); - BatchUtilities.addResourceContentChanges(resourceContentChanges, changes); - + ModificationResult mr = js.runModificationTask((WorkingCopy wc) -> { + if (wc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { + return; } + Map resourceContentChanges = new HashMap<>(); + Accessor.INSTANCE.process(jf, wc, true, resourceContentChanges, /*Ignored for now:*/new ArrayList<>()); + BatchUtilities.addResourceContentChanges(resourceContentChanges, changes); }); changes.putAll(JavaSourceAccessor.getINSTANCE().getDiffsFromModificationResult(mr)); @@ -1018,7 +1032,7 @@ public void run(WorkingCopy wc) throws Exception { public HintWarning assertFixes(String... expectedFixes) throws Exception { assertTrue("Must be computed", warning.getFixes().isComputed()); - List fixNames = new LinkedList(); + List fixNames = new LinkedList<>(); for (Fix f : warning.getFixes().getFixes()) { if (f instanceof SyntheticFix) continue; @@ -1040,7 +1054,7 @@ public HintWarning assertFixes(String... expectedFixes) throws Exception { public HintWarning assertFixesNotPresent(String... bannedFixes) throws Exception { assertTrue("Must be computed", warning.getFixes().isComputed()); - List fixNames = new LinkedList(); + List fixNames = new LinkedList<>(); for (Fix f : warning.getFixes().getFixes()) { if (f instanceof SyntheticFix) continue; fixNames.add(f.getText()); @@ -1269,11 +1283,8 @@ public String getOutput(String fileName) throws Exception { } } - private static final Comparator ERRORS_COMPARATOR = new Comparator () { - - public int compare (ErrorDescription e1, ErrorDescription e2) { - return e1.getRange ().getBegin ().getOffset () - e2.getRange ().getBegin ().getOffset (); - } + private static final Comparator ERRORS_COMPARATOR = (ErrorDescription e1, ErrorDescription e2) -> { + return e1.getRange().getBegin().getOffset() - e2.getRange().getBegin().getOffset(); }; static { @@ -1369,7 +1380,7 @@ private static String getWorkDirPath() { return realP; } - private static Set usedPaths = new HashSet(); + private static Set usedPaths = new HashSet<>(); private static String abbrevDots(String dotted) { StringBuilder sb = new StringBuilder(); @@ -1417,17 +1428,11 @@ private static String getWorkDirPathFromManager() { private static Properties readProperties() { Properties result = new Properties(); - try { - File propFile = getPreferencesFile(); - FileInputStream is = new FileInputStream(propFile); - try { - result.load(is); - } finally { - is.close(); - } + File propFile = getPreferencesFile(); + try (FileInputStream is = new FileInputStream(propFile)) { + result.load(is); } catch (IOException e) { } - return result; } @@ -1474,11 +1479,10 @@ private static void deleteSubFiles(File file) throws IOException { } } - private static FileObject copyStringToFile (FileObject f, String content) throws Exception { - OutputStream os = f.getOutputStream(); - os.write(content.getBytes(StandardCharsets.UTF_8)); - os.close (); - + private static FileObject copyStringToFile(FileObject f, String content) throws Exception { + try (OutputStream os = f.getOutputStream()) { + os.write(content.getBytes(StandardCharsets.UTF_8)); + } return f; } diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertSwitchToRuleSwitchTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertSwitchToRuleSwitchTest.java index 3323573ea75f..3e763142cc7d 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertSwitchToRuleSwitchTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertSwitchToRuleSwitchTest.java @@ -60,7 +60,7 @@ public void testSwitch2RuleSwitch() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -91,7 +91,7 @@ public void testLastNotBreak() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -122,7 +122,7 @@ public void testMultipleCases() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -153,7 +153,7 @@ public void testFallThrough() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -173,7 +173,7 @@ public void testMissingLastBreak() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -204,7 +204,7 @@ public void testDefault() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -244,7 +244,7 @@ public void testVariables1() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -284,7 +284,7 @@ public void testFallThroughDefault1() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -304,7 +304,7 @@ public void testFallThroughDefault2() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -326,7 +326,7 @@ public void testTrailingEmptyCase() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -362,7 +362,7 @@ public void testNeedsPreview() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -381,7 +381,7 @@ public void testBreakInside1() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -402,7 +402,7 @@ public void testBreakInside2() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("4:9-4:15:verifier:Convert switch to rule switch") .applyFix() @@ -437,7 +437,7 @@ public void testContinueInside1() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .assertWarnings(); } @@ -460,7 +460,7 @@ public void testContinueInside2() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("5:13-5:19:verifier:Convert switch to rule switch") .applyFix() @@ -501,7 +501,7 @@ public void testSwitch2SwitchExpression() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -536,7 +536,7 @@ public void testSwitch2SwitchExpressionMultiCase() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:8-3:14:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -570,7 +570,7 @@ public void testSwitch2SwitchExpressionMultiCase2() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:8-3:14:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -601,7 +601,7 @@ public void testSwitch2SwitchExpressionOnlyDefault() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:8-3:14:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -636,7 +636,7 @@ public void testSwitch2SwitchExpressionNestedInnerSwitchExpression() throws Exce " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("4:9-4:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -671,7 +671,7 @@ public void testSwitch2SwitchExpressionReturnValue() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("2:9-2:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -701,7 +701,7 @@ public void testSwitch2SwitchExpressionTypeCast() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -731,7 +731,7 @@ public void testSwitch2SwitchExpressionTypeCastReturn() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("2:9-2:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -764,7 +764,7 @@ public void testSwitch2SwitchExpressionNestedSwitchExpression() throws Exception " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -806,7 +806,7 @@ public void testSwitch2SwitchExpressionNestedOuterSwitchStatement() throws Excep " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("4:9-4:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -851,7 +851,7 @@ public void testSwitch2SwitchExpressionNestedInnerSwitchStatement() throws Excep " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("6:16-6:22:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() @@ -893,7 +893,7 @@ public void testSwitchToRuleSwitchFormattingMultiple() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -924,7 +924,7 @@ public void testSwitchToRuleSwitchFormattingSimple() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -959,7 +959,7 @@ public void testSwitchToRuleSwitchBindingPattern() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel("21") + .sourceLevel(21) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -994,7 +994,7 @@ public void testSwitchToRuleSwitchGuardedPattern() throws Exception { " }\n" + " }\n" + "}\n") - .sourceLevel("21") + .sourceLevel(21) .run(ConvertSwitchToRuleSwitch.class) .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch()) .applyFix() @@ -1030,7 +1030,7 @@ public void testSwitchExpressionGuardedPattern() throws Exception { + " }\n" + " }\n" + "}") - .sourceLevel("21") + .sourceLevel(21) .run(ConvertSwitchToRuleSwitch.class) .findWarning("2:8-2:14:verifier:" + Bundle.ERR_ConvertSwitchToSwitchExpression()) .applyFix() diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertTextBlockToStringTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertTextBlockToStringTest.java index 8d37b5c6c39f..83667f51d00e 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertTextBlockToStringTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertTextBlockToStringTest.java @@ -46,7 +46,7 @@ public void newLineAtEnd() throws Exception { + " \"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -69,7 +69,7 @@ public void simpleTest() throws Exception { + " abc\"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -98,7 +98,7 @@ public void multipleNewLine() throws Exception { + " \"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -126,7 +126,7 @@ public void newLineAfter() throws Exception { + " ;\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -160,7 +160,7 @@ public void manyLineTextBlock() throws Exception { + " wxyz\"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -184,7 +184,7 @@ public void twoLineTextBlock() throws Exception { + " def\"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -209,7 +209,7 @@ public void twoNewLines() throws Exception { + " \"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -232,7 +232,7 @@ public void slashConvert() throws Exception { + " \\\\\"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -256,7 +256,7 @@ public void escapeCharTextBlock() throws Exception { + " \"def\"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -284,7 +284,7 @@ public void escapeCharTextBlock2() throws Exception { + " \"\"\";\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("3:18-3:21:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -308,7 +308,7 @@ public void textBlockAsParameter1() throws Exception { + " abc\"\"\");\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("4:27-4:30:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() @@ -333,7 +333,7 @@ public void textBlockAsParameter2() throws Exception { + " ghi\"\"\");\n" + " }\n" + "}") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertTextBlockToString.class) .findWarning("2:27-2:30:hint:" + Bundle.ERR_ConvertTextBlockToString()) .applyFix() diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToNestedRecordPatternTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToNestedRecordPatternTest.java index 28583a4a57de..566ef10c672f 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToNestedRecordPatternTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToNestedRecordPatternTest.java @@ -22,6 +22,8 @@ import org.netbeans.modules.java.hints.test.api.HintTest; import javax.lang.model.SourceVersion; +import static org.junit.Assume.assumeTrue; + /** * * @author mjayan @@ -33,9 +35,8 @@ public ConvertToNestedRecordPatternTest(String name) { } public void testSimple() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Rect(ColoredPoint upperLeft,ColoredPoint lr) {}\n" @@ -50,8 +51,7 @@ public void testSimple() throws Exception { + " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToNestedRecordPattern.class) .findWarning("7:25-7:63:verifier:" + Bundle.ERR_ConvertToNestedRecordPattern()) .applyFix() @@ -71,9 +71,8 @@ public void testSimple() throws Exception { } public void testRecordNameUsed() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Rect(ColoredPoint upperLeft,ColoredPoint lr) {}\n" @@ -88,16 +87,14 @@ public void testRecordNameUsed() throws Exception { + " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToNestedRecordPattern.class) .assertWarnings(); } public void testNameClash() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Rect(ColoredPoint upperLeft,ColoredPoint lr) {}\n" @@ -119,8 +116,7 @@ public void testNameClash() throws Exception { + " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToNestedRecordPattern.class) .findWarning("7:25-7:63:verifier:Convert to nested record pattern") .applyFix() @@ -147,9 +143,8 @@ public void testNameClash() throws Exception { } public void testMultipleNested() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Rect(ColoredPoint upperLeft) {}\n" @@ -164,8 +159,7 @@ public void testMultipleNested() throws Exception { + " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToNestedRecordPattern.class) .findWarning("7:25-7:61:verifier:" + Bundle.ERR_ConvertToNestedRecordPattern()) .applyFix() @@ -185,9 +179,8 @@ public void testMultipleNested() throws Exception { } public void testUserVar() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Rect(ColoredPoint upperLeft,ColoredPoint lr,ColoredPoint ur) {}\n" @@ -204,8 +197,7 @@ public void testUserVar() throws Exception { + " }\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToNestedRecordPattern.class) .findWarning("7:25-7:112:verifier:" + Bundle.ERR_ConvertToNestedRecordPattern()) .applyFix() diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToRecordPatternTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToRecordPatternTest.java index 72cd50c080ce..a4b3a5e6ce99 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToRecordPatternTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToRecordPatternTest.java @@ -21,6 +21,7 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.modules.java.hints.test.api.HintTest; import javax.lang.model.SourceVersion; +import static org.junit.Assume.assumeTrue; /** * @@ -33,9 +34,8 @@ public ConvertToRecordPatternTest(String name) { } public void testSimple() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Person(String name, String place){}\n" @@ -48,8 +48,7 @@ public void testSimple() throws Exception { + " return -1;\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToRecordPattern.class) .findWarning("4:8-4:10:verifier:" + Bundle.ERR_ConvertToRecordPattern()) .applyFix() @@ -58,7 +57,7 @@ public void testSimple() throws Exception { + "record Person(String name, String place){}\n" + "public class Test {\n" + " private int test(Object o) {\n" - + " if (o instanceof Person(String name, String place) p) {\n" + + " if (o instanceof Person(String name, String place)) {\n" + " return name.length();\n" + " }\n" + " return -1;\n" @@ -67,9 +66,8 @@ public void testSimple() throws Exception { } public void testDuplicateVarName() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Person(String name, int s){}\n" @@ -82,8 +80,7 @@ public void testDuplicateVarName() throws Exception { + " return -1;\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToRecordPattern.class) .findWarning("4:8-4:10:verifier:" + Bundle.ERR_ConvertToRecordPattern()) .applyFix() @@ -92,7 +89,7 @@ public void testDuplicateVarName() throws Exception { + "record Person(String name, int s){}\n" + "public class Test {\n" + " private int test(Object s) {\n" - + " if (s instanceof Person(String name, int s1) p) {\n" + + " if (s instanceof Person(String name, int s1)) {\n" + " return name.length();\n" + " }\n" + " return -1;\n" @@ -101,9 +98,8 @@ public void testDuplicateVarName() throws Exception { } public void testUsingUserVar() throws Exception { - if (!isRecordClassPresent()) { - return; - } + assumeTrue(isRecordClassPresent()); + assumeTrue(SourceVersion.latest().ordinal() >= 21); HintTest.create() .input("package test;\n" + "record Person(String name, int s){}\n" @@ -116,8 +112,7 @@ public void testUsingUserVar() throws Exception { + " return -1;\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) - .options("--enable-preview") + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToRecordPattern.class) .findWarning("4:8-4:10:verifier:" + Bundle.ERR_ConvertToRecordPattern()) .applyFix() @@ -126,7 +121,7 @@ public void testUsingUserVar() throws Exception { + "record Person(String name, int s){}\n" + "public class Test {\n" + " private int test(Object s) {\n" - + " if (s instanceof Person(String userName, int s1) p) {\n" + + " if (s instanceof Person(String userName, int s1)) {\n" + " return userName.length();\n" + " }\n" + " return -1;\n" diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java index 9289ec2ec40b..8b1720ab1219 100644 --- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java +++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToTextBlockTest.java @@ -41,7 +41,7 @@ public void testFixWorking() throws Exception { " \"}\");\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToTextBlock.class) .findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock()) .applyFix() @@ -75,7 +75,7 @@ public void testNewLineAtEnd() throws Exception { " \"}\\n\");\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToTextBlock.class) .findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock()) .applyFix() @@ -110,7 +110,7 @@ public void testNewLinesAtEnd() throws Exception { " \"}\\n\\n\");\n" + " }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToTextBlock.class) .findWarning("3:30-3:37:verifier:" + Bundle.ERR_ConvertToTextBlock()) .applyFix() @@ -144,7 +144,7 @@ public void testOnlyLiterals() throws Exception { " }\n" + " private int c() { return 0; }\n" + "}\n") - .sourceLevel(SourceVersion.latest().name()) + .sourceLevel(SourceVersion.latest().ordinal()) .run(ConvertToTextBlock.class) .assertWarnings(); } diff --git a/platform/o.n.core/test/unit/src/org/netbeans/core/CanProxyToLocalhostTest.java b/platform/o.n.core/test/unit/src/org/netbeans/core/CanProxyToLocalhostTest.java index 18ef6cabf0ec..6c4136ae8968 100644 --- a/platform/o.n.core/test/unit/src/org/netbeans/core/CanProxyToLocalhostTest.java +++ b/platform/o.n.core/test/unit/src/org/netbeans/core/CanProxyToLocalhostTest.java @@ -29,7 +29,6 @@ import java.util.Locale; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNotNull; -import org.netbeans.core.ProxySettings; import org.netbeans.junit.NbTestCase; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -83,13 +82,13 @@ public void testProxyForLocalhost() { String staticNonProxyHosts = NbBundle.getMessage(ProxySettings.class, "StaticNonProxyHosts"); // NOI18N assertNotNull(staticNonProxyHosts); assertEquals("The default non proxy hosts", "", staticNonProxyHosts); - assertEquals("Connect TO_LOCALHOST provided by MyPS", "HTTP @ my.webcache:8080", selector.select(TO_LOCALHOST).get(0).toString()); + assertEquals("Connect TO_LOCALHOST provided by MyPS", "HTTP @ my.webcache/:8080", selector.select(TO_LOCALHOST).get(0).toString()); assertEquals("One call to my ps", 1, MY_PS.called); } public void testAlwaysProxyForNonLocalhost() { Locale.setDefault(Locale.US); - assertEquals("Connect TO_NB provided by MyPS", "HTTP @ my.webcache:8080", selector.select(TO_NB).get(0).toString()); + assertEquals("Connect TO_NB provided by MyPS", "HTTP @ my.webcache/:8080", selector.select(TO_NB).get(0).toString()); assertEquals("One call to my ps", 1, MY_PS.called); } diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_01.js similarity index 52% rename from webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js rename to webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_01.js index cc2e957847d4..9014bb2b2575 100644 --- a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_01.js @@ -1,2 +1 @@ var x= Math. -var x=Math. diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js.testIssue215777_01.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_01.js.testIssue215777_01.completion similarity index 100% rename from webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js.testIssue215777_01.completion rename to webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_01.js.testIssue215777_01.completion diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js new file mode 100644 index 000000000000..e4c1f60fb5b3 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js @@ -0,0 +1 @@ +var x=Math. diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js.testIssue215777_02.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js.testIssue215777_02.completion similarity index 98% rename from webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js.testIssue215777_02.completion rename to webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js.testIssue215777_02.completion index d83304fab8c2..f0f5da242571 100644 --- a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777.js.testIssue215777_02.completion +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/issue215777_02.js.testIssue215777_02.completion @@ -80,5 +80,4 @@ FIELD SQRT2: Number [PUBLIC, JS Platform FIELD caller: Function [PUBLIC] JS Platform FIELD length: Number [PUBLIC] JS Platform FIELD name: String [PUBLIC] JS Platform -FIELD var: Math [PUBLIC] issue215777.js VARIABLE arguments: Object [PUBLIC] JS Platform diff --git a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionGeneralTest.java b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionGeneralTest.java index 23d429f01679..111009235600 100644 --- a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionGeneralTest.java +++ b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionGeneralTest.java @@ -61,11 +61,11 @@ public void testIssue215861_02() throws Exception { } public void testIssue215777_01() throws Exception { - checkCompletion("testfiles/completion/issue215777.js", "var x= Math.^", false); + checkCompletion("testfiles/completion/issue215777_01.js", "var x= Math.^", false); } public void testIssue215777_02() throws Exception { - checkCompletion("testfiles/completion/issue215777.js", "var x=Math.^", false); + checkCompletion("testfiles/completion/issue215777_02.js", "var x=Math.^", false); } public void testIssue217100_01() throws Exception {