package jdk.statement;

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * 
 * @since 2017-07-27
 * @author fixalot
 */
public class SwitchTest {
	private static final Logger logger = LoggerFactory.getLogger(SwitchTest.class);

	/**
	 * switch 안의 로컬 변수는 마치 자바스크립트의 끌어올림처럼 작동함.
	 * 
	 * @author fixalot
	 */
	@Test
	public void whenVariableInitialize() {
		int a = 2;
		switch (a) {
			case 1:
				int b = 0; // 여기는 오지 않는걸로 보이지만
				logger.debug(String.valueOf(b));
				break;
			case 2:
//				b; // 이렇게 하면 컴파일 에러: Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
				b = 3;
				logger.debug(String.valueOf(b));
				Assert.assertEquals(3, b);
				break;
		}
	}

	/**
	 * switch의 인수가 null이면 어떻게 될까요?
	 * 
	 * @author fixalot
	 */
	@Test
	@SuppressWarnings("null")
	public void howAboutActualArgumentIsNull() {
		String imNull = null;
		try {
			switch (imNull) {
				case "a":
					logger.debug("it is 'a'");
					break;
				default:
					logger.debug("it is null");
					break;
			}
		} catch (NullPointerException e) {
			logger.debug("에러 났습니당.");
		}
	}
}

@@ -1072,16 +1072,46 @@
 k;%0A%09%09%09%7D%0A
+%09%09%09Assert.assertTrue(1 == 2);%0A
 %09%09%7D catc
@@ -1166,19 +1166,568 @@
  %EB%82%AC%EC%8A%B5%EB%8B%88%EB%8B%B9.%22);%0A%09%09
-%7D
+%09Assert.assertFalse(1 == 2);%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * static final %EC%A0%9C%EC%96%B4%EC%9E%90%EA%B0%80 %EB%B6%99%EC%9D%80 %EB%B3%80%EC%88%98%EC%97%AC%EB%8F%84 %EC%8B%A4%EC%A0%9C %EA%B0%92%EC%9D%B4 %EB%9F%B0%ED%83%80%EC%9E%84%EC%97%90 %EA%B2%B0%EC%A0%95%EB%90%98%EB%A9%B4 case %ED%91%9C%ED%98%84%EC%8B%9D%EC%97%90 %EC%82%AC%EC%9A%A9%ED%95%A0 %EC%88%98 %EC%97%86%EB%8B%A4%0A%09 * %0A%09 * @author noritersand%0A%09 */%0A%09@Test%0A%09public void shouldBeCompileError() %7B%0A%09%09switch (myS) %7B%0A%09%09%09case (1):%0A//%09%09%09case (myS + 0): // case expressions must be constant expressions%0A//%09%09%09case (myS + 1): // case expressions must be constant expressions%0A%09%09%09%09logger.debug(%22%EC%A0%95%EC%83%81%EA%B0%92 %EC%9E%85%EB%A0%A5%22);%0A%09%09%09%09break;%0A%09%09%09default:%0A%09%09%09%09logger.debug(%22%ED%97%88%EC%9A%A9 %EC%88%98%EC%B9%98%EB%A5%BC %EB%B2%97%EC%96%B4%EB%82%A8%22);%0A%09%09%09%09break;%0A%09%09%7D%0A%09%7D%0A%0A%09public static final int myS = getData();%0A%0A%09public static final int getData() %7B%0A%09%09return 1;
 %0A%09%7D%0A%7D%0A

add test case