001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.utils;
042:
043: import junit.framework.TestCase;
044:
045: /**
046: * TestCase for Method Name formatter class.
047: *
048: * @author Ian Formanek
049: */
050: public final class MethodNameFormatterTest extends TestCase {
051: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
052:
053: private static final String[] patternSources = {
054: "java/lang/String", "concat",
055: "(Ljava.lang.String;)Ljava.lang.String;",
056: "java/lang/String", "getBytes", "()[B",
057: "classNameInDefaultPackage", "doIt", "()V",
058: "foo/bar/LongArrays", "createArray",
059: "([[[[[[[[I)[[[[[[[[[F", "foo/bar/Constr", "", "()V",
060: "foo/bar/Constr", "<init>", "()V", "foo/bar/Constr", null,
061: null, "foo/bar/Constr", "<clinit>", null, };
062: private static final String[] patternResults = {
063: "java.lang.String", // formattedClass
064: "java.lang.String.concat(java.lang.String)", // formattedClassAndMethod
065: "concat(java.lang.String)", // formattedMethod
066: "java.lang.String.concat(java.lang.String) : java.lang.String", // fullFormattedClassAndMethod
067: "concat(java.lang.String) : java.lang.String", // fullFormattedMethod
068: "java.lang.String", // paramsString
069: "java.lang.String", // returnType
070: "java.lang.String", // formattedClass
071: "java.lang.String.getBytes()", // formattedClassAndMethod
072: "getBytes()", // formattedMethod
073: "java.lang.String.getBytes() : byte[]", // fullFormattedClassAndMethod
074: "getBytes() : byte[]", // fullFormattedMethod
075: "", // paramsString
076: "byte[]", // returnType
077: "classNameInDefaultPackage", // formattedClass
078: "classNameInDefaultPackage.doIt()", // formattedClassAndMethod
079: "doIt()", // formattedMethod
080: "classNameInDefaultPackage.doIt() : void", // fullFormattedClassAndMethod
081: "doIt() : void", // fullFormattedMethod
082: "", // paramsString
083: "void", // returnType
084: "foo.bar.LongArrays", // formattedClass
085: "foo.bar.LongArrays.createArray(int[][][][][][][][])", // formattedClassAndMethod
086: "createArray(int[][][][][][][][])", // formattedMethod
087: "foo.bar.LongArrays.createArray(int[][][][][][][][]) : float[][][][][][][][][]", // fullFormattedClassAndMethod
088: "createArray(int[][][][][][][][]) : float[][][][][][][][][]", // fullFormattedMethod
089: "int[][][][][][][][]", // paramsString
090: "float[][][][][][][][][]", // returnType
091: "foo.bar.Constr", // formattedClass
092: "foo.bar.Constr.<init>()", // formattedClassAndMethod
093: "<init>()", // formattedMethod
094: "foo.bar.Constr.<init>()", // fullFormattedClassAndMethod
095: "<init>()", // fullFormattedMethod
096: "", // paramsString
097: "", // returnType
098: "foo.bar.Constr", // formattedClass
099: "foo.bar.Constr.<init>()", // formattedClassAndMethod
100: "<init>()", // formattedMethod
101: "foo.bar.Constr.<init>()", // fullFormattedClassAndMethod
102: "<init>()", // fullFormattedMethod
103: "", // paramsString
104: "", // returnType
105: "foo.bar.Constr", // formattedClass
106: "foo.bar.Constr", // formattedClassAndMethod
107: "", // formattedMethod
108: "foo.bar.Constr", // fullFormattedClassAndMethod
109: "", // fullFormattedMethod
110: "", // paramsString
111: "", // returnType
112: "foo.bar.Constr", // formattedClass
113: "foo.bar.Constr.<clinit>", // formattedClassAndMethod
114: "<clinit>", // formattedMethod
115: "foo.bar.Constr.<clinit>", // fullFormattedClassAndMethod
116: "<clinit>", // fullFormattedMethod
117: "", // paramsString
118: "", // returnType
119: };
120:
121: //~ Methods ------------------------------------------------------------------------------------------------------------------
122:
123: /**
124: * Test to ensure that the formatting of test methods is as expected.
125: */
126: public void testFormatting() {
127: MethodNameFormatter mnf;
128:
129: int count = 0;
130:
131: for (int i = 0; (i + 2) < patternSources.length; i += 3) {
132: mnf = new MethodNameFormatter(patternSources[i],
133: patternSources[i + 1], patternSources[i + 2]);
134:
135: assertEquals("Wrong results for getFormattedClass " + mnf,
136: patternResults[count++], mnf.getFormattedClass());
137: assertEquals(
138: "Wrong results for getFormattedClassAndMethod "
139: + mnf, patternResults[count++], mnf
140: .getFormattedClassAndMethod());
141: assertEquals("Wrong results for getFormattedMethod " + mnf,
142: patternResults[count++], mnf.getFormattedMethod());
143: assertEquals(
144: "Wrong results for getFullFormattedClassAndMethod "
145: + mnf, patternResults[count++], mnf
146: .getFullFormattedClassAndMethod());
147: assertEquals("Wrong results for getFullFormattedMethod "
148: + mnf, patternResults[count++], mnf
149: .getFullFormattedMethod());
150: assertEquals("Wrong results for getParamsString " + mnf,
151: patternResults[count++], mnf.getParamsString());
152: assertEquals("Wrong results for getReturnType " + mnf,
153: patternResults[count++], mnf.getReturnType());
154: }
155: }
156:
157: protected void setUp() throws Exception {
158: }
159: }
|