??xml version="1.0" encoding="utf-8" standalone="yes"?>
orted major.minor version 50.0).
一q行报main 函数出错?jin),意思是没有扑ֈmain 函数的入口。可是代码正啊。到Eclipse 下试试,一切正常,看来不是它的问题?br />
命o(h)行下输入Qjavac -version 昄Qjavac 1.4.2...
java -version 昄Qjava 1.6...
~译和运行环境的版本怎么不一PJDK 不是明明1.6 吗?装的是jdk 1.6 的怎么变?.4 ?jin)?br />
报错原来是用低版本的JDK~译高版本的.class׃(x)报这个错
到环境变量查看了(jin)半天也没发现问题Q忽然发现PATH中oracle中怎么?.4.2 ?jin)?img alt="" src="/CuteSoft_Client/CuteEditor/images/face7.gif" align="absMiddle" border="0" />
C:\Program Files\MySQL\MySQL Server 5.0\bin;D:\oracle\product\10.1.0\Db_4\bin;D:\oracle\product\10.1.0\Db_4\jre\1.4.2\bin\client;D:\oracle\product\10.1.0\Db_4\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\TortoiseSVN\bin;%JAVA_HOME%\bin;%Path%
改ؓ(f)Q在PATH 最前面加上 %JAVA_HOME%\
%JAVA_HOME%\bin;C:\Program Files\MySQL\MySQL Server 5.0\bin;D:\oracle\product\10.1.0\Db_4\bin;D:\oracle\product\10.1.0\Db_4\jre\1.4.2\bin\client;D:\oracle\product\10.1.0\Db_4\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\TortoiseSVN\bin;
再到DOS 下试?QOK Q运行通过?br />
C:\Documents and Settings\joan>javac -version
javac 1.6.0_02
C:\Documents and Settings\joan>java -version
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
C:\Documents and Settings\joan>javac test.java
C:\Documents and Settings\joan>java test
C:\Documents and Settings\joan>
JDK 配置 egQ?br />
set JAVA_HOME= C:\Program Files\Java\jdk1.6.0_02
set PATH=%JAVA_HOME%\bin;%PATH%
set CLASSPATH=.;%JAVA_HOME%\lib
2、Action层难以模拟httph传递参敎ͼ需要依赖web容器Q因此给单元试~写带来一定的隑ֺ?/p>
下面是一个简单的Action单元试用例Q供大家参考。基于struts的mock和webwork的ActionProxyFactory都可以进行Action的单元测试。我个h比较們与ActionProxyFactory做单元测试。其实写action单元试非常单,大致分ؓ(f)三步可以完成单元测试:(x)
一、设|ActionContext上下文参?/p>
表单传递的h参数d到map?/p>
二、创建Action动态代理对?/p>
通过public abstract ActionProxy createActionProxy(String namespace, String actionName, Map extraContext) throws Exception 创徏action代理对象?/p>
三、junit断言执行l果
详细用例参?
public class TestActionTest extends BaseCaseTest{
private ActionProxy proxy = null;
private IVoucherService voucherService;
@Before
public void setUp() throws Exception {
IMocksControl control = EasyMock.createControl();
voucherService = control.createMock(IVoucherService.class);
Map<String, Object> params = new HashMap<String, Object>();
params.put(”loginId”,”test”);
params.put(”password”,”111111″);
params.put(”voucherService”, voucherService);
Map extraContext = new HashMap();
extraContext.put(ActionContext.PARAMETERS,params);
try {
proxy = ActionProxyFactory.getFactory().createActionProxy(”/user”, “testAction”, extraContext);
proxy.setExecuteResult(false);
assertEquals(proxy.execute(),”success”);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testLogin() {
TestAction testAction = (TestAction) proxy.getAction();
assertEquals(testAction.login(),”success”);
}
}
注:(x)创徏代理action一定要执行proxy.execute()Ҏ(gu)Q否则参C能够增加到actionContext上下文中。因?proxy.execute()中会(x)执行 invocation.invoke()核心(j)Ҏ(gu)Q遍历执行action中所有的拦截器,包括其中的参数拦截器?br /> Q{载)(j)Qtestage.net
@Override
public String toSting() { // 注意Ҏ(gu)名拼写错?br /> return "[" + super.toString() + "]";
}
下面是一D用@Deprecated的代码:(x)
/**
* q里是javadoc的@deprecated声明.
* @deprecated No one has players for this format any more. Use VHS instead.
*/
@Deprecated public class Betamax { ... }
@SuppressWarnings(value={"unchecked","fallthrough"})
public void lintTrap() { /* sloppy method body omitted */ }
@SuppressWarnings({"unchecked","fallthrough"})
@SuppressWarnings("unchecked")
@Reviews({ // Single-value annotation, so "value=" is omitted here
@Review(grade=Review.Grade.EXCELLENT,
reviewer="df"),
@Review(grade=Review.Grade.UNSATISFACTORY,
reviewer="eg",
comment="This method needs an @Override annotation")
})
@UncheckedExceptions({
IllegalArgumentException.class, StringIndexOutOfBoundsException.class
})
/**
* This package holds my custom annotation types.
*/
@com.davidflanagan.annotations.Author("David Flanagan")
package com.davidflanagan.annotations;
import java.lang.reflect.*;
Class c = WhizzBangClass.class;
Method m = c.getMethod("whizzy", int.class, int.class);
boolean unstable = m.isAnnotationPresent(Unstable.class);
AnnotatedElement target = WhizzBangClass.class; //获得被查询的AnnotatedElement
// 查询AnnotatedElement的@Reviews annotation信息
Reviews annotation = target.getAnnotation(Reviews.class);
// 因ؓ(f)@Reviews annotationcd的成员(sh)ؓ(f)@Review annotationcd的数l,
// 所以下面声明了(jin)Review[] reviews保存@Reviews annotationcd的value成员倹{?br /> Review[] reviews = annotation.value();
// 查询每个@Review annotation的成员(sh)?br /> for(Review r : reviews) {
Review.Grade grade = r.grade();
String reviewer = r.reviewer();
String comment = r.comment();
System.out.printf("%s assigned a grade of %s and comment '%s'%n",
reviewer, grade, comment);
}
package com.davidflanagan.annotations;
import java.lang.annotation.*;
/**
* 使用annotation来描q那些被标注的成员是不稳定的Q需要更?br /> */
@Retention(RetentionPolicy.RUNTIME)
public @interface Unstable {}
/**
* 使用Authorq个annotation定义在程序中指出代码的作?br /> */
public @interface Author {
/** q回作者名 */
String value();
}
import java.lang.annotation.*;
/**
* Reviews annotationcd只有一个成员,
* 但是q个成员的类型是复杂的:(x)由Review annotationl成的数l?br /> */
@Retention(RetentionPolicy.RUNTIME)
public @interface Reviews {
Review[] value();
}
/**
* Review annotationcd?个成员:(x)
* 枚Dcd成员grade?br /> * 表示Review名称的字W串cd成员Reviewer?br /> * h默认值的字符串类型成员Comment?br /> */
public @interface Review {
// 内嵌的枚丄?br /> public static enum Grade { EXCELLENT, SATISFACTORY, UNSATISFACTORY };
// 下面的方法定义了(jin)annotation的成?br /> Grade grade();
String reviewer();
String comment() default "";
}
public @interface UncheckedExceptions {
Class<? extends RuntimeException>[] value();
}