1.1 --- a/java.hints/java.hints.test/nbproject/project.xml Thu Jul 30 19:21:28 2015 +0200
1.2 +++ b/java.hints/java.hints.test/nbproject/project.xml Sat Aug 01 22:41:24 2015 +0200
1.3 @@ -254,6 +254,20 @@
1.4 </run-dependency>
1.5 </dependency>
1.6 </module-dependencies>
1.7 + <test-dependencies>
1.8 + <test-type>
1.9 + <name>unit</name>
1.10 + <test-dependency>
1.11 + <code-name-base>org.netbeans.modules.parsing.nb</code-name-base>
1.12 + <recursive/>
1.13 + <compile-dependency/>
1.14 + </test-dependency>
1.15 + <test-dependency>
1.16 + <code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
1.17 + <compile-dependency/>
1.18 + </test-dependency>
1.19 + </test-type>
1.20 + </test-dependencies>
1.21 <public-packages>
1.22 <package>org.netbeans.modules.java.hints.test.api</package>
1.23 </public-packages>
2.1 --- a/java.hints/java.hints.test/test/unit/src/org/netbeans/modules/java/hints/test/api/HintTestTest.java Thu Jul 30 19:21:28 2015 +0200
2.2 +++ b/java.hints/java.hints.test/test/unit/src/org/netbeans/modules/java/hints/test/api/HintTestTest.java Sat Aug 01 22:41:24 2015 +0200
2.3 @@ -64,6 +64,7 @@
2.4 import org.netbeans.spi.java.hints.JavaFix;
2.5 import org.netbeans.spi.java.hints.JavaFix.TransformationContext;
2.6 import org.netbeans.spi.java.hints.TriggerTreeKind;
2.7 +import org.openide.LifecycleManager;
2.8 import org.openide.cookies.EditorCookie;
2.9 import org.openide.filesystems.FileObject;
2.10 import org.openide.filesystems.FileUtil;
2.11 @@ -104,22 +105,26 @@
2.12
2.13 @Test
2.14 public void testNonJavaChangesOpenedInEditor() throws Exception {
2.15 - HintTest ht = HintTest.create()
2.16 - .input("package test;\n" +
2.17 - "public class Test { }\n")
2.18 - .input("test/test.txt", "1\n2\n", false);
2.19 - FileObject resource = ht.getSourceRoot().getFileObject("test/test.txt");
2.20 - DataObject od = DataObject.find(resource);
2.21 - EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
2.22 - Document doc = ec.openDocument();
2.23 - doc.remove(0, doc.getLength());
2.24 - doc.insertString(0, "5\n6\n", null);
2.25 - ht.run(NonJavaChanges.class)
2.26 - .findWarning("1:13-1:17:verifier:Test")
2.27 - .applyFix(false)
2.28 - .assertVerbatimOutput("test/test.txt", "6\n7\n");
2.29 - Assert.assertEquals("1\n2\n", resource.asText("UTF-8"));
2.30 - Assert.assertEquals("6\n7\n", doc.getText(0, doc.getLength()));
2.31 + try {
2.32 + HintTest ht = HintTest.create()
2.33 + .input("package test;\n" +
2.34 + "public class Test { }\n")
2.35 + .input("test/test.txt", "1\n2\n", false);
2.36 + FileObject resource = ht.getSourceRoot().getFileObject("test/test.txt");
2.37 + DataObject od = DataObject.find(resource);
2.38 + EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
2.39 + Document doc = ec.openDocument();
2.40 + doc.remove(0, doc.getLength());
2.41 + doc.insertString(0, "5\n6\n", null);
2.42 + ht.run(NonJavaChanges.class)
2.43 + .findWarning("1:13-1:17:verifier:Test")
2.44 + .applyFix(false)
2.45 + .assertVerbatimOutput("test/test.txt", "6\n7\n");
2.46 + Assert.assertEquals("1\n2\n", resource.asText("UTF-8"));
2.47 + Assert.assertEquals("6\n7\n", doc.getText(0, doc.getLength()));
2.48 + } finally {
2.49 + LifecycleManager.getDefault().saveAll();
2.50 + }
2.51 }
2.52
2.53 @Hint(displayName="testingNonJavaChanges", description="testingNonJavaChanges", category="test")
3.1 --- a/java.hints/spi.java.hints/test/unit/src/org/netbeans/spi/java/hints/JavaFixUtilitiesTest.java Thu Jul 30 19:21:28 2015 +0200
3.2 +++ b/java.hints/spi.java.hints/test/unit/src/org/netbeans/spi/java/hints/JavaFixUtilitiesTest.java Sat Aug 01 22:41:24 2015 +0200
3.3 @@ -430,7 +430,9 @@
3.4 "try { } catch $catches$ => try { new Object(); } catch $catches$",
3.5 "package test;\n" +
3.6 "public class Test {\n" +
3.7 - " { try { new Object();\n } catch {NullPointerException ex} { } }\n" +
3.8 + //XXX: whitespaces:
3.9 + " { try {new Object();\n } catch {NullPointerException ex} { } }\n" +
3.10 +// " { try { new Object();\n } catch {NullPointerException ex} { } }\n" +
3.11 "}\n");
3.12 }
3.13
3.14 @@ -442,9 +444,7 @@
3.15 "switch ($v) { case $p$ case 2: $stmts$; } => switch ($v) { case $p$ case 3: $stmts$; }",
3.16 "package test;\n" +
3.17 "public class Test {\n" +
3.18 - //XXX: whitespaces:
3.19 -// " { int i = 0; switch (i) {case 0: System.err.println(1); break; case 1: System.err.println(2); break; case 3: System.err.println(3); break; }\n" +
3.20 - " { int i = 0; switch (i) {case 0: System.err.println(1); break; case 1: System.err.println(2); break; case 3: System.err.println(3); break; }\n" +
3.21 + " { int i = 0; switch (i) {case 0: System.err.println(1); break; case 1: System.err.println(2); break; case 3: System.err.println(3); break; }\n" +
3.22 "}\n");
3.23 }
3.24
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/java.hints/spi.java.hints/test/unit/src/org/netbeans/spi/java/hints/TestUtils.java Sat Aug 01 22:41:24 2015 +0200
4.3 @@ -0,0 +1,69 @@
4.4 +/*
4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 + *
4.7 + * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
4.8 + *
4.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
4.10 + * Other names may be trademarks of their respective owners.
4.11 + *
4.12 + * The contents of this file are subject to the terms of either the GNU
4.13 + * General Public License Version 2 only ("GPL") or the Common
4.14 + * Development and Distribution License("CDDL") (collectively, the
4.15 + * "License"). You may not use this file except in compliance with the
4.16 + * License. You can obtain a copy of the License at
4.17 + * http://www.netbeans.org/cddl-gplv2.html
4.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.19 + * specific language governing permissions and limitations under the
4.20 + * License. When distributing the software, include this License Header
4.21 + * Notice in each file and include the License file at
4.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
4.23 + * particular file as subject to the "Classpath" exception as provided
4.24 + * by Oracle in the GPL Version 2 section of the License file that
4.25 + * accompanied this code. If applicable, add the following below the
4.26 + * License Header, with the fields enclosed by brackets [] replaced by
4.27 + * your own identifying information:
4.28 + * "Portions Copyrighted [year] [name of copyright owner]"
4.29 + *
4.30 + * If you wish your version of this file to be governed by only the CDDL
4.31 + * or only the GPL Version 2, indicate your decision by adding
4.32 + * "[Contributor] elects to include this software in this distribution
4.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.34 + * single choice of license, a recipient has the option to distribute
4.35 + * your version of this file under either the CDDL, the GPL Version 2 or
4.36 + * to extend the choice of license to its licensees as provided above.
4.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
4.38 + * Version 2 license, then the option applies only if the new code is
4.39 + * made subject to such option by the copyright holder.
4.40 + *
4.41 + * Contributor(s):
4.42 + *
4.43 + * Portions Copyrighted 2015 Sun Microsystems, Inc.
4.44 + */
4.45 +package org.netbeans.spi.java.hints;
4.46 +
4.47 +import org.netbeans.api.editor.mimelookup.MimePath;
4.48 +import org.netbeans.modules.editor.impl.DocumentFactoryImpl;
4.49 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
4.50 +import org.openide.util.Lookup;
4.51 +import org.openide.util.lookup.Lookups;
4.52 +import org.openide.util.lookup.ServiceProvider;
4.53 +
4.54 +/**
4.55 + *
4.56 + * @author lahvac
4.57 + */
4.58 +public class TestUtils {
4.59 +
4.60 + @ServiceProvider(service = MimeDataProvider.class)
4.61 + public static final class MimeDataProviderImpl implements MimeDataProvider {
4.62 +
4.63 + private final Lookup l = Lookups.singleton(new DocumentFactoryImpl());
4.64 +
4.65 + @Override
4.66 + public Lookup getLookup(MimePath mimePath) {
4.67 + return "text/x-java".equals(mimePath.getPath()) ? l : Lookup.EMPTY;
4.68 + }
4.69 +
4.70 + }
4.71 +
4.72 +}