file/test/unit/src/org/netbeans/modules/jackpot30/file/conditionapi/DefaultRuleUtilitiesTest.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/file/test/unit/src/org/netbeans/modules/jackpot30/file/conditionapi/DefaultRuleUtilitiesTest.java Thu Jul 21 22:51:52 2011 +0200
1.3 @@ -0,0 +1,77 @@
1.4 +/*
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 + * <p/>
1.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
1.8 + * <p/>
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 + * <p/>
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 Development and
1.14 + * Distribution License("CDDL") (collectively, the "License"). You may not use
1.15 + * this file except in compliance with the License. You can obtain a copy of
1.16 + * the License at http://www.netbeans.org/cddl-gplv2.html or
1.17 + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
1.18 + * governing permissions and limitations under the License. When distributing
1.19 + * the software, include this License Header Notice in each file and include
1.20 + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
1.21 + * particular file as subject to the "Classpath" exception as provided by
1.22 + * Oracle in the GPL Version 2 section of the License file that accompanied
1.23 + * this code. If applicable, add the following below the License Header, with
1.24 + * the fields enclosed by brackets [] replaced by your own identifying
1.25 + * information: "Portions Copyrighted [year] [name of copyright owner]"
1.26 + * <p/>
1.27 + * If you wish your version of this file to be governed by only the CDDL or
1.28 + * only the GPL Version 2, indicate your decision by adding "[Contributor]
1.29 + * elects to include this software in this distribution under the [CDDL or GPL
1.30 + * Version 2] license." If you do not indicate a single choice of license, a
1.31 + * recipient has the option to distribute your version of this file under
1.32 + * either the CDDL, the GPL Version 2 or to extend the choice of license to its
1.33 + * licensees as provided above. However, if you add GPL Version 2 code and
1.34 + * therefore, elected the GPL Version 2 license, then the option applies only
1.35 + * if the new code is made subject to such option by the copyright holder.
1.36 + * <p/>
1.37 + * Contributor(s):
1.38 + * <p/>
1.39 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
1.40 + */
1.41 +package org.netbeans.modules.jackpot30.file.conditionapi;
1.42 +
1.43 +import com.sun.source.util.TreePath;
1.44 +import java.util.Collection;
1.45 +import java.util.Collections;
1.46 +import java.util.Map;
1.47 +import java.util.regex.Pattern;
1.48 +import org.netbeans.modules.jackpot30.impl.TestBase;
1.49 +import org.netbeans.modules.jackpot30.spi.HintContext;
1.50 +
1.51 +/**
1.52 + *
1.53 + * @author lahvac
1.54 + */
1.55 +public class DefaultRuleUtilitiesTest extends TestBase {
1.56 +
1.57 + public DefaultRuleUtilitiesTest(String name) {
1.58 + super(name);
1.59 + }
1.60 +
1.61 + public void testEnclosingClasses() throws Exception {
1.62 + String code = "package test; public class Test { public static class X { private int i|i; } }";
1.63 + int pos = code.indexOf("|");
1.64 +
1.65 + code = code.replaceAll(Pattern.quote("|"), "");
1.66 +
1.67 + prepareTest("test/Test.java", code);
1.68 +
1.69 + TreePath tp = info.getTreeUtilities().pathFor(pos);
1.70 + Map<String, TreePath> variables = Collections.<String, TreePath>emptyMap();
1.71 + Map<String, Collection<? extends TreePath>> multiVariables = Collections.<String, Collection<? extends TreePath>>emptyMap();
1.72 + Map<String, String> variables2Names = Collections.emptyMap();
1.73 + Context ctx = new Context(HintContext.create(info, null, tp, variables, multiVariables, variables2Names));
1.74 + DefaultRuleUtilities utils = new DefaultRuleUtilities(ctx, new Matcher(ctx));
1.75 +
1.76 + assertTrue(utils.inClass("test.Test.X"));
1.77 + assertTrue(utils.inClass("test.Test"));
1.78 + assertFalse(utils.inClass("test.TestA"));
1.79 + }
1.80 +}