나는 다음과 같은 정보를 JUnit 테스트 케이스에서이 함수를 호출하고있어 경우 :문 OR 논리 이상한
// abbr = "US";
// Countries = array of two objects one with iso2 = "us"
public Country getCountryFromAbbr(String abbr) {
abbr = abbr.toLowerCase();
for (int i = 0; i < Countries.size(); i++) {
Country country = Countries.get(i);
String iso2 = country.ISO2.toLowerCase();
String iso3 = country.ISO3.toLowerCase();
if (iso2.equals(abbr) || iso3.equals(abbr)) {
return country;
}
}
return null;
}
내가 디버깅, ISO2
iso2.equals(abbr)
us
의와 두 번째 목적은 사실이고, 다른 하나는 false
입니다 . 그러나 국가 반환 된 및 디버거가 루프를 완료하고 null
을 반환합니다.
저는 사실로 혼동하고 있습니다. || 거짓이 사실입니다. 내가 놓친 게 있니?
다음은 국가의 모형이다 :
List<Country> Countries = new ArrayList<Country>();
Country country = new Country();
country.CountryId = 1;
country.CountryName = "Great Britian";
country.ISO2 = "GB";
country.ISO3 = "GBR";
Countries.add(country);
Country usa = new Country();
usa.CountryId = Studio.USA_COUNTRY_ID;
usa.CountryName = "United States of America";
usa.ISO2 = "US";
usa.ISO3 = "USA";
Countries.add(usa);
return Countries;
편집 : 내가 사용 이클립스 디버깅을 사용하고 내 2.3.3 X 이드
iso2를 소문자로 변환하면 abbr도 소문자입니까? –
예,'abbr = abbr.toLowerCase()' – Joe
arg가 정확한지 확인하기 위해''.equals (abbr)'을 단정 할 수도 있습니다. –