Junit Test 중인데...
Dictionary.java
package study;
public class Dictionary {
String[] input = new String[2];
String[] output = new String[2];
public boolean isEmpty(){
for(int i=0; i<2; i++){
if(this.input[i]==null && this.output[i]==null){
return true;
}
}
return false;
}
public void addTranslation(String input, String output) {
for(int i=0; i<2; i++){
this.input[i]=input;
this.output[i]=output;
}
}
public String getTranslation(String trans){
for(int i=0; i<2;i++){
if(this.input[i]==trans){
trans=output[i];
}
}
return trans;
}
}
============================================================================
package study;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class DictionaryTeststdd {
private Dictionary dict;
@Before
public void setUp() throws Exception {
dict = new Dictionary();
}
@Test1
public void testCreation() {
assertTrue(dict.isEmpty());
//fail("Not yet implemented");
}
@Test2
public void testAddTranslation(){
dict.addTranslation("book","책");
assertFalse("dict not empty",dict.isEmpty());
}
@Test3
public void testOneTranslation(){
dict.addTranslation("book","책");
dict.addTranslation("car","자동차");
assertFalse("dict not empty",dict.isEmpty());
String trans = dict.getTranslation("book");
assertEquals("Translation book","책",trans);
}
}
Dictionary.java 작성중인데.. Test3의 trans에 자꾸 자동차가 들어가네요...
처음에 필드에 배열을 선언하지 않고 구현하려 했었고, Test3을 보니 2개를 입력받고 필드에 넣어야 될것같아서 배열을 생각하게 됬습니다.
그런데 Run 해본 결과 trans값에는 제 기대와 달리 "자동차" String 값이 들어가 있었습니다..
해결 방법 없을까요..? 질문드립니다!
땔감은 비추천