alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.test.refactoring.changesignature;

import java.lang.reflect.Modifier;
import junit.textui.TestRunner;
import org.netbeans.junit.NbTestSuite;




/**
 * Change method signature refactoring simple tests
 * @author  Emanuel Hucka
 */
public class SimpleTest extends ChangeSignatureTestCase {
    
    private static final String CLASS_NAME_1 = "org.netbeans.tests.examples.packa.Bean";
    private static final String CLASS_NAME_2 = "org.netbeans.tests.examples.packb.BeanC";
    private static final String CLASS_NAME_3 = "org.netbeans.tests.examples.Test";
    private static final String CLASS_NAME_4 = "org.netbeans.tests.examples.packc.AbstractBean";
    private static final String CLASS_NAME_5 = "org.netbeans.tests.examples.packc.AFrame";
    private static final String CLASS_NAME_6 = "org.netbeans.tests.examples.packb.BeansD.BeanDA";
    
    private static final String IFACE_NAME_1 = "org.netbeans.tests.examples.packc.Makable";
    private static final String IFACE_NAME_2 = "org.netbeans.tests.examples.packa.Testable";
    
    
    /** Creates a new instance of Signature1Test */
    public SimpleTest(String name) {
        super(name);
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        //undo
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod1"));
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod2"));
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod3"));
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod4"));
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod5"));
        suite.addTest(new SimpleTest("testUndoChangeParametersClassMethod6"));
        suite.addTest(new SimpleTest("testUndoChangeParametersInterfaceMethod1"));
        suite.addTest(new SimpleTest("testUndoChangeParametersInterfaceMethod2"));
        
        suite.addTest(new SimpleTest("testClassMethod1"));
        suite.addTest(new SimpleTest("testClassMethod2"));
        suite.addTest(new SimpleTest("testClassMethod3"));
        suite.addTest(new SimpleTest("testClassMethod4"));
        suite.addTest(new SimpleTest("testClassMethod5"));
        suite.addTest(new SimpleTest("testClassMethod6"));
        suite.addTest(new SimpleTest("testInterfaceMethod1"));
        suite.addTest(new SimpleTest("testInterfaceMethod2"));
        return suite;
    }
    
    public void testUndoChangeParametersClassMethod1() {
        changeSignature(CLASS_NAME_1, "abc", new String[0], new String[][] {{"ab", "java.lang.String", "\"\""}}, Modifier.PUBLIC, true);
    }
    
    public void testUndoChangeParametersClassMethod2() {
        log("static method");
        changeSignature(CLASS_NAME_3, "makeTest", new String[] {},
        new String[][] {{"publish", "boolean", "false"}}, Modifier.PUBLIC, true);
    }
    
    public void testUndoChangeParametersClassMethod3() {//change accesor which cannot be changed
        log("bad accessor - method is called as public from another package");
        changeSignature(CLASS_NAME_3, "runTest", new String[] {},
        new String[][] {{"index", "int", "0"}}, Modifier.PROTECTED, true);
    }
    
    public void testUndoChangeParametersClassMethod4() {
        log("method of abstract class");
        changeSignature(CLASS_NAME_4, "methodBean", new String[0],
        new String[][] {{"names","java.lang.String[]","new String[] {}"}, {"data", "Object[][]", "new Object[0][0]"}}, Modifier.PUBLIC, true);
    }
    
    public void testUndoChangeParametersClassMethod5() {//error arguments
        log("same argument's name");
        changeSignature(CLASS_NAME_2, "setSign", new String[] {"boolean"},
        new String[][] {{"sign", "int", "0"}}, Modifier.PUBLIC, true);
        log("wrong argument's name - just exists in the method");
        changeSignature(CLASS_NAME_3, "test1", new String[] {},
        new String[][] {{"a", "java.beans.PropertyChangeListener", "null"}}, Modifier.PUBLIC, true);
    }
    
    public void testUndoChangeParametersClassMethod6() {
        log("guarded method");
        changeSignature(CLASS_NAME_5, "buttonActionPerformed", new String[] {"java.awt.event.ActionEvent"},
        new String[][] {{"int", "action", "0"}}, Modifier.PROTECTED, true);
    }
    
    public void testUndoChangeParametersInterfaceMethod1() {
        changeSignature(IFACE_NAME_1, "make", new String[] {"int","java.lang.String","org.netbeans.tests.examples.packa.Bean"},
        new String[][] {{"check","boolean","false"}, {"date","java.util.Date","new Date()"}}, Modifier.PUBLIC, true);
    }
    
    public void testUndoChangeParametersInterfaceMethod2() {
        changeSignature(IFACE_NAME_2, "test", new String[0],
        new String[][] {{"testName", "java.lang.String", "null"}, {"testFolder", "java.io.File", "new File(\"/tmp/test\")"}}, Modifier.PUBLIC, true);
    }
    
    public void testClassMethod1() {
        changeSignature(CLASS_NAME_1, "abc", new String[0], new String[][] {{"ab", "java.lang.String", "\"\""}}, Modifier.PUBLIC, false);
    }
    
    public void testClassMethod2() {
        log("static method");
        changeSignature(CLASS_NAME_3, "makeTest", new String[] {},
        new String[][] {{"publish", "boolean", "false"}}, Modifier.PUBLIC, false);
    }
    
    public void testClassMethod3() {//change accesor which cannot be changed
        log("bad accessor - method is called as public from another package");
        changeSignature(CLASS_NAME_3, "runTest", new String[] {},
        new String[][] {{"index", "int", "0"}}, Modifier.PROTECTED, false);
    }
    
    public void testClassMethod4() {
        log("method of abstract class");
        changeSignature(CLASS_NAME_4, "methodBean", new String[0],
        new String[][] {{"names","java.lang.String[]","new String[] {}"}, {"data", "Object[][]", "new Object[0][0]"}}, Modifier.PUBLIC, false);
    }
    
    public void testClassMethod5() {//error arguments
        log("same argument's name");
        changeSignature(CLASS_NAME_2, "setSign", new String[] {"boolean"},
        new String[][] {{"sign", "int", "0"}}, Modifier.PUBLIC, false);
        log("wrong argument's name - just exists in the method");
        changeSignature(CLASS_NAME_3, "test1", new String[] {},
        new String[][] {{"a", "java.beans.PropertyChangeListener", "null"}}, Modifier.PUBLIC, false);
    }
    
    public void testClassMethod6() {
        log("guarded method");
        changeSignature(CLASS_NAME_5, "buttonActionPerformed", new String[] {"java.awt.event.ActionEvent"},
        new String[][] {{"int", "action", "0"}}, Modifier.PROTECTED, false);
    }
    
    public void testInterfaceMethod1() {
        changeSignature(IFACE_NAME_1, "make", new String[] {"int","java.lang.String","org.netbeans.tests.examples.packa.Bean"},
        new String[][] {{"check","boolean","false"}, {"date","java.util.Date","new Date()"}}, Modifier.PUBLIC, false);
    }
    
    public void testInterfaceMethod2() {
        changeSignature(IFACE_NAME_2, "test", new String[0],
        new String[][] {{"testName", "java.lang.String", "null"}, {"testFolder", "java.io.File", "new File(\"/tmp/test\")"}}, Modifier.PUBLIC, false);
    }
    
    /**
     * Used for running test from inside the IDE by internal execution.
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        TestRunner.run(suite());
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.