sandbox/java.hints/spi.java.hints/test/unit/src/org/netbeans/modules/java/hints/spiimpl/processor/JavaHintsAnnotationProcessorTest.java
branchdonation_review
changeset 1043 57843026e60b
parent 1027 205b7632914c
parent 1040 f7b6892fd754
child 1044 7feb751ba76b
     1.1 --- a/sandbox/java.hints/spi.java.hints/test/unit/src/org/netbeans/modules/java/hints/spiimpl/processor/JavaHintsAnnotationProcessorTest.java	Mon Dec 19 11:37:36 2016 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,149 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
     1.8 - *
     1.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    1.10 - * Other names may be trademarks of their respective owners.
    1.11 - *
    1.12 - * The contents of this file are subject to the terms of either the GNU
    1.13 - * General Public License Version 2 only ("GPL") or the Common
    1.14 - * Development and Distribution License("CDDL") (collectively, the
    1.15 - * "License"). You may not use this file except in compliance with the
    1.16 - * License. You can obtain a copy of the License at
    1.17 - * http://www.netbeans.org/cddl-gplv2.html
    1.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.19 - * specific language governing permissions and limitations under the
    1.20 - * License.  When distributing the software, include this License Header
    1.21 - * Notice in each file and include the License file at
    1.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    1.23 - * particular file as subject to the "Classpath" exception as provided
    1.24 - * by Oracle in the GPL Version 2 section of the License file that
    1.25 - * accompanied this code. If applicable, add the following below the
    1.26 - * License Header, with the fields enclosed by brackets [] replaced by
    1.27 - * your own identifying information:
    1.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    1.29 - *
    1.30 - * If you wish your version of this file to be governed by only the CDDL
    1.31 - * or only the GPL Version 2, indicate your decision by adding
    1.32 - * "[Contributor] elects to include this software in this distribution
    1.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    1.34 - * single choice of license, a recipient has the option to distribute
    1.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    1.36 - * to extend the choice of license to its licensees as provided above.
    1.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    1.38 - * Version 2 license, then the option applies only if the new code is
    1.39 - * made subject to such option by the copyright holder.
    1.40 - *
    1.41 - * Contributor(s):
    1.42 - *
    1.43 - * Portions Copyrighted 2012 Sun Microsystems, Inc.
    1.44 - */
    1.45 -package org.netbeans.modules.java.hints.spiimpl.processor;
    1.46 -
    1.47 -import java.io.ByteArrayOutputStream;
    1.48 -import java.io.File;
    1.49 -import org.netbeans.junit.NbTestCase;
    1.50 -import org.openide.util.test.AnnotationProcessorTestUtils;
    1.51 -import org.openide.util.test.TestFileUtils;
    1.52 -
    1.53 -/**
    1.54 - *
    1.55 - * @author lahvac
    1.56 - */
    1.57 -public class JavaHintsAnnotationProcessorTest extends NbTestCase {
    1.58 -
    1.59 -    public JavaHintsAnnotationProcessorTest(String name) {
    1.60 -        super(name);
    1.61 -    }
    1.62 -
    1.63 -    public void testErrors1() throws Exception {
    1.64 -        File src = new File(getWorkDir(), "src");
    1.65 -        File dest = new File(getWorkDir(), "classes");
    1.66 -        AnnotationProcessorTestUtils.makeSource(src, "p.H",
    1.67 -                "import org.netbeans.spi.java.hints.*;\n",
    1.68 -                "import org.netbeans.spi.editor.hints.*;\n",
    1.69 -                "@Hint(displayName=\"\", description=\"\", category=\"general\")\n",
    1.70 -                "public class H {\n",
    1.71 -                "    @TriggerPattern(\"$1.$2\")\n",
    1.72 -                "    public static String h1(HintContext ctx) { return null;}\n",
    1.73 -                "    @TriggerPattern(\"$1.$2.$3\")\n",
    1.74 -                "    public static ErrorDescription h2() { return null;}\n",
    1.75 -                "    @TriggerPatterns({@TriggerPattern(\"$1.$2.$3.$4\")})\n",
    1.76 -                "    private ErrorDescription h3(HintContext ctx) { return null;}\n",
    1.77 -                "    @TriggerPattern(value=\"$1.isEmpty()\", constraints=@ConstraintVariableType(variable=\"$unknown\", type=\"java.lang.String\"))\n",
    1.78 -                "    public static ErrorDescription h4(HintContext ctx) { return null;}\n",
    1.79 -                "}\n");
    1.80 -        TestFileUtils.writeFile(new File(src, "p/Bundle.properties"), "");
    1.81 -        ByteArrayOutputStream err = new ByteArrayOutputStream();
    1.82 -        assertFalse(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err));
    1.83 -        String errors = err.toString();
    1.84 -        assertTrue(errors.contains("error: The return type must be either org.netbeans.spi.editor.hints.ErrorDescription or java.util.List<org.netbeans.spi.editor.hints.ErrorDescription>"));
    1.85 -        assertTrue(errors.contains("error: The method must have exactly one parameter of type org.netbeans.spi.java.hints.HintContext"));
    1.86 -        assertTrue(errors.contains("error: The method must be static"));
    1.87 -        assertTrue(errors.contains("warning: Variable $unknown not used in the pattern"));
    1.88 -    }
    1.89 -
    1.90 -    public void testErrors2() throws Exception {
    1.91 -        File src = new File(getWorkDir(), "src");
    1.92 -        File dest = new File(getWorkDir(), "classes");
    1.93 -        AnnotationProcessorTestUtils.makeSource(src, "p.H",
    1.94 -                "import org.netbeans.spi.java.hints.*;\n",
    1.95 -                "import org.netbeans.spi.editor.hints.*;\n",
    1.96 -                "import java.util.*;\n",
    1.97 -                "@Hint(displayName=\"#DN_p.H\", description=\"#DESC_p.H\", category=\"general\")\n",
    1.98 -                "public class H {\n",
    1.99 -                "    @TriggerPattern(\"$1.$2.$3\")\n",
   1.100 -                "    public static List<ErrorDescription> hint(HintContext ctx) { return null;}\n",
   1.101 -                "}\n");
   1.102 -        TestFileUtils.writeFile(new File(src, "p/Bundle.properties"), "DN_p.H=DN_p.H\nDESC_p.H=DESC_p.H\n");
   1.103 -        ByteArrayOutputStream err = new ByteArrayOutputStream();
   1.104 -        assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err));
   1.105 -    }
   1.106 -
   1.107 -    public void testCustomizerProvider() throws Exception {
   1.108 -        File src = new File(getWorkDir(), "src");
   1.109 -        File dest = new File(getWorkDir(), "classes");
   1.110 -        AnnotationProcessorTestUtils.makeSource(src, "p.H",
   1.111 -                "import org.netbeans.spi.java.hints.*;\n",
   1.112 -                "import org.netbeans.spi.editor.hints.*;\n",
   1.113 -                "import java.util.*;\n",
   1.114 -                "import java.util.prefs.*;\n",
   1.115 -                "import javax.swing.*;\n",
   1.116 -                "@Hint(displayName=\"dn\", description=\"desc\", category=\"general\", customizerProvider=H.Customizer.class)\n",
   1.117 -                "public class H {\n",
   1.118 -                "    @TriggerPattern(\"$1.$2.$3\")\n",
   1.119 -                "    public static List<ErrorDescription> hint(HintContext ctx) { return null;}\n",
   1.120 -                "    static final class Customizer implements CustomizerProvider {\n",
   1.121 -                "        @Override public JComponent getCustomizer(Preferences prefs) {\n",
   1.122 -                "            return new JPanel();\n",
   1.123 -                "        }\n",
   1.124 -                "    }\n",
   1.125 -                "}\n");
   1.126 -        TestFileUtils.writeFile(new File(src, "p/Bundle.properties"), "DN_p.H=DN_p.H\nDESC_p.H=DESC_p.H\n");
   1.127 -        ByteArrayOutputStream err = new ByteArrayOutputStream();
   1.128 -        assertFalse(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err));
   1.129 -        String errors = err.toString();
   1.130 -        assertTrue(errors.contains("error: Customizer provider must be public"));
   1.131 -        assertTrue(errors.contains("error: Customizer provider must provide a public default constructor"));
   1.132 -    }
   1.133 -
   1.134 -    public void testErrorsMessagesOnMethod() throws Exception {
   1.135 -        File src = new File(getWorkDir(), "src");
   1.136 -        File dest = new File(getWorkDir(), "classes");
   1.137 -        AnnotationProcessorTestUtils.makeSource(src, "p.H",
   1.138 -                "import org.netbeans.spi.java.hints.*;\n",
   1.139 -                "import org.netbeans.spi.editor.hints.*;\n",
   1.140 -                "import org.openide.util.NbBundle.Messages;\n",
   1.141 -                "import java.util.*;\n",
   1.142 -                "public class H {\n",
   1.143 -                "    @Hint(displayName=\"#DN_p.H\", description=\"#DESC_p.H\", category=\"general\")\n",
   1.144 -                "    @TriggerPattern(\"$1.$2.$3\")\n",
   1.145 -                "    @Messages({\"DN_p.H=1\", \"DESC_p.H=2\"})\n",
   1.146 -                "    public static List<ErrorDescription> hint(HintContext ctx) { return null;}\n",
   1.147 -                "}\n");
   1.148 -        ByteArrayOutputStream err = new ByteArrayOutputStream();
   1.149 -        boolean result = AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err);
   1.150 -        assertTrue(err.toString(), result);
   1.151 -    }
   1.152 -}