java string 변수 switch, junit test

■ java에서 string 변수 switch문은 1.8버전부터 지원한다. 1.7에서 string switch문을 사용하면 다음과 같은 메세지를 보낸다.
// Cannot switch on a value of type String for source level below 1.7.
// Only convertible int values or enum variables are permitted
 
 
 

■ string switch 예제 코드

package net.iotinfra.pilot.switchtest;
public class Switch {
	
  public static String stringSwitch(String param) {
    String result = "";
		
    // Cannot switch on a value of type String for source level below 1.7. 
    // Only convertible int values or enum variables are permitted
    switch( param ) {
      case "aaa" :
        result = "AAA";
	break;
      case "bbb" :
        result = "BBB";
        break;
      case "ccc" :
        result = "CCC";
        break;
      default : 
        result = "XXX";
    }		
    return result;		
  }
}

 
 
 

■ 테스트 코드

package net.iotinfra.pilot.switchtest;

import static org.junit.Assert.assertSame;
import org.junit.Test;

public class StringSwitchTest {

  @Test
  public void testStringSwitchAAA() {
    assertSame(Switch.stringSwitch("aaa"), "AAA");
  }
	
  @Test
  public void testStringSwitchBBB() {
    assertSame("BBB", Switch.stringSwitch("bbb"));
  }
	
  @Test
  public void testStringSwitchXXX() {
    assertSame("XXX", Switch.stringSwitch("eee"));
  }
}

 
 
 

■ 이클립스테서 Junit 테스트 실행결과(F11)