转载请保留作者信息:
作者:88250
Blog:http:/blog.csdn.net/DL88250
MSN & Gmail & QQ:[email protected]
NetBeans IDE 是基于NetBeans Platform搭建的,它的所有功能都是以插件的方式实现的。我们也可以基于NetBeans Platform实现自己的应用,这一点,与Eclipse RCP是等同的。首先,我们先来熟悉一下NetBeans Module的开发 :-)。这个例子是一个用于配置NetBeans启动参数的插件,用它可以使用图形界面配置NetBeans启动参数。当然了,这这是一个例子,Bugs比较多,要使用同种功能的插件,看这里!
准备 点此访问NetBeans下载站点。下载最新的Java基本开发套件就可以了。开始 1. 创建工程 新建工程,选择模块开发:
工程命名为CustomStartup,其他的使用默认配置。
2. 编写测试用例 插件随小,无脏俱全哦~ 再说,本着TDD的原则,我们还是先编写一下测试用例吧。
测试代码如下:
* @(#)NBConfFileJUnitTest.java
* Author: 88250 <[email protected]>, http://blog.csdn.net/DL88250
* Created on May 17, 2008, 11:19:21 AM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package cn.edu.ynu.sei.customstartup.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openide.util.Exceptions;
import static org.junit.Assert.*;
/**
* NBConfFile Test Case.
* @author 88250 <[email protected]>, http://blog.csdn.net/DL88250
* @version 1.0.0.0, May 17, 2008
*/
public class NBConfFileJUnitTest {
private static cn.edu.ynu.sei.customstartup.NBConfFile instance;
public NBConfFileJUnitTest() {
instance = new cn.edu.ynu.sei.customstartup.NBConfFile();
}
@BeforeClass
public static void setUpClass() throws Exception {
// simulate the NetBeans luncher to set system property
System.setProperty("netbeans.home",
"/home/daniel/Work/netbeans-6.1/platform8");
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void getLocation() {
System.out.println("getLocation");
assertEquals("/home/daniel/Work/netbeans-6.1/etc/netbeans.conf",
instance.getLocation());
}
@Test
public void getFile() {
System.out.println("getFile");
File netbeans_conf = instance.getFile();
assertTrue(netbeans_conf.exists());
assertEquals("netbeans.conf", netbeans_conf.getName());
BufferedReader reader;
//String expect =
// "# ${HOME} will be replaced by JVM user.home system property";
String expect = "### properties written by CustomStartup module";
String actual = null;
try {
reader = new BufferedReader(new FileReader(netbeans_conf));
actual = reader.readLine();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
assertEquals(expect, actual);
}
@Test
public void backupConfFile() {
System.out.println("backupConfFile");
instance.backupConfFile();
assertTrue(instance.getBackupFile().exists());
}
@Test
public void getBackupFile() {
System.out.println("getBackupFile");
File actual = instance.getBackupFile();
assertEquals("netbeans.conf.backup", actual.getName());
}
@Test
public void getParameters() {
System.out.println("getParameters");
Properties paras = instance.getParameters();
Enumeration<?> keys = paras.propertyNames();
while (keys.hasMoreElements()) {
String key = keys.nextElement().toString();
String value = paras.getProperty(key);
System.out.println(key + "=" + value);
}
assertEquals(""${HOME}/.netbeans/6.1"",
paras.getProperty("netbeans_default_userdir"));
}
@Test
public void getNetBeansDefaultOptions() {
System.out.println("getNetBeansDefaultOptions");
List<String> options = instance.getNetBeansDefaultOptions();
for (String option : options) {
System.out.println(option);
}
assertEquals("-J-client", options.get(0));
assertEquals("--fontsize 10", options.get(options.size() - 1));
}
@Test
public void getNetBeansJDKHome() {
System.out.println("getNetBeansJDKHome");
String expect = "/usr/lib/jvm/java-6-sun/";
String actual = instance.getNetBeansJDKHome();
assertEquals(expect, actual);
}
@Test
public void setNetBeansJDKHome() {
System.out.println("setNetBeansJDKHome");
String jdkHome = "/usr/lib/jvm/java-6-sun/";
instance.setNetBeansJDKHome(jdkHome);
assertEquals(jdkHome, instance.getNetBeansJDKHome());
}
@Test
public void addNetBeansDefaultOptions() {
System.out.println("addNetBeansDefaultOptions");
String para = "--fontsize 15";
instance.addNetBeansDefaultOptions(para);
assertEquals(para, instance.getNetBeansDefaultOptions().get(instance.
getNetBeansDefaultOptions().
size() - 1));
}
@Test
public void removeNetBeansDefaultOptions() {
System.out.println("removeNetBeansDefaultOptions");
instance.removeNetBeansDefaultOptions(0);
assertEquals("-J-Xss16m", instance.getNetBeansDefaultOptions().get(0));
}
@Test
public void editNetBeansDefaultOptions() {
System.out.println("editNetBeansDefaultOptions");
instance.editNetBeansDefaultOptions(0, "--test 10");
assertEquals("--test 10", instance.getNetBeansDefaultOptions().get(0));
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)