Java Enum类型定义的方法(二)

package com.abin.info.service;

public interface TeamService {

public static enum TeamType {
  TeamName("NameOfTeam"), TeamNumber("NumberOfTeam"), TeamArea(
    "AreaOfTeam"), TeamTrue("TrueOfTeam"), TeamFalse("FalseOfTeam"), TeamInitialize(
    "InitializeOfTeam");

  private String TeamInfo;

  private TeamType(String _TeamInfo) {
   this.TeamInfo = _TeamInfo;
  }

  public String toString() {
   return TeamInfo;
  }

}

int compare(TeamType obj);

String insert(TeamType obj);
}








package com.abin.info.service;

public class TeamServiceImpl implements TeamService{
private TeamType type=TeamType.TeamInitialize;
public int compare(TeamType obj) {
  System.out.println(type.toString());
  if(obj.equals(TeamType.TeamNumber)){
   return 1;
  }
  return 0;
}

public String insert(TeamType obj) {
  System.out.println(type.toString());
  if(obj.equals(TeamType.TeamArea)){
   return "area";
  }
  return "notarea";
}


}










package com.abin.inter.test;

import junit.framework.TestCase;

import com.abin.info.service.TeamService;
import com.abin.info.service.TeamServiceImpl;
import com.abin.info.service.TeamService.TeamType;

public class TestTeam extends TestCase{

public void test(){
  TeamType team=TeamType.TeamNumber;
  TeamService service=new TeamServiceImpl();
  int result=service.compare(team);
  assertEquals(1, result);
  System.out.println("compare 's result="+result);
 
  TeamType team1=TeamType.TeamArea;
  TeamService service1=new TeamServiceImpl();
  String result1=service1.insert(team1);
  assertEquals("area",result1);
  System.out.println("insert 's result="+result1);
}
}



你可能感兴趣的:(enum,JUnit,interface)