阅读更多
//枚举接口
package com.abin.info.service;
public interface UserService {
public static enum UserType{
Basic("基本信息"),
UserName("用户姓名"),
UserAge("用户年龄"),
UserSex("用户性别");
private String info;
UserType(String _info){
this.info=_info;
}
public String toString() {
// TODO Auto-generated method stub
return info;
}
}
public static enum UserStatus{
Bed("睡觉"),
Walk("散步"),
Read("读文章"),
Write("写文章");
private String status;
private UserStatus(String _status){
this.status=_status;
}
public String toString(){
return status;
}
}
int init(UserType ask);
}
//枚举接口实现类
package com.abin.info.service;
public class UserServiceImpl implements UserService{
public int init(UserType ask) {
if(ask.equals(UserType.Basic)){
return 0;
}else{
return 1;
}
}
}
//枚举接口测试类
package com.abin.inter.test;
import junit.framework.TestCase;
import com.abin.info.service.UserService;
import com.abin.info.service.UserServiceImpl;
import com.abin.info.service.UserService.UserType;
public class testUser extends TestCase{
// public static enum Other{
// Basic("basic"),
// Name("name"),
// Age("age"),
// Sex("sex");
//
// private String sp;
// private Other(String spl){
// this.sp=spl;
// }
//
// }
public void testUser(){
UserService service=new UserServiceImpl();
int result=service.init(UserType.Basic);
assertEquals(0, result);
System.out.println();
}
}