■ 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)
- Java에서 properties파일 읽기 2019년 4월 3일
- weblogic.jdbc.wrapper.clob_oracle_sql_clob cannot be cast to oracle.sql.clob 2019년 3월 21일
- Java keytool 사용법 2019년 3월 14일
- Tomcat 시작시 ServletContextListener를 통한 mySQL 접속 2018년 5월 8일
- spring mybatis mysql 연결 예제 2018년 5월 4일
- apache commons StringUtils 예제 2018년 5월 3일
- 자바 래퍼 클래스(Java Wrapper Class)? 2018년 2월 13일
- java string 변수 switch, junit test 2018년 2월 12일
- 단정문 assertEquals와 assertSame의 차이점 2017년 4월 12일
- java continue, break 키워드 2017년 3월 25일
- spring service junit test 2016년 5월 25일
- mybatis mapper junit test 2016년 5월 2일
- JUnit Controller Test java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig 2016년 3월 22일
- java eclipse static import 2016년 3월 15일
- junit 단정문 – Assertions 2016년 3월 14일
- junit & spring-test maven dependency 2016년 3월 14일
- Java String, 자바 문자열 2016년 3월 3일