Created
March 10, 2014 23:01
-
-
Save yangwansu/9476261 to your computer and use it in GitHub Desktop.
각각의 블럭을 의도가 들어나도록 메서드 추출함..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.springapp.mvc; | |
import static com.google.common.base.Preconditions.*; | |
import static java.lang.System.err; | |
public class GuavaTest1 { | |
private final boolean initialzed = false; | |
public void testForNonNullArgument(final String parameter) | |
{ | |
final String localPrameter = checkNotNull(parameter, "null값은" | |
+ "허용되지 않습니다."); | |
} | |
public void testDivisorNotZero(final int divisor){ | |
checkArgument(divisor != 0, "0으로 나눌 수 없습니다."); | |
} | |
public void testArrayElement(final String[] strArray, | |
final int indexNumber){ | |
final int index = checkElementIndex(indexNumber, strArray.length, | |
"지정된 Array 요소 위치가 벗어났습니다."); | |
} | |
public void testarrayPosition(final String[] strarray, final int indexNumber){ | |
final int index = checkPositionIndex(indexNumber, strarray.length, | |
"지정된 Array 요소 위치가 벗어났습니다."); | |
} | |
public void testState(){ | |
checkState(this.initialzed, "초기화 되지 않았습니다."); | |
} | |
public static void printHeader(final String newHeaderText){ | |
err.println("\n====================="); | |
err.println("===" + newHeaderText); | |
err.println("======================="); | |
} | |
public static void main(String[] args) { | |
final GuavaTest1 test1 = new GuavaTest1(); | |
test1(test1, "preconditions.checkNotNull"); | |
test2(test1, "precondition.checkArgument"); | |
test3(test1, "Preconditions.checkElementIndex"); | |
test4(test1, "Preconditions.checkPositionIndex"); | |
test5(test1, "Preconditions.checkState"); | |
} | |
private static void test5(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
test1.testState(); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test4(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
test1.testarrayPosition(new String[]{"Dustin","java"},3); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test3(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
test1.testArrayElement(new String[]{"Dustin","java"},3 ); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test2(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
test1.testDivisorNotZero(0); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test1(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
test1.testForNonNullArgument(null); | |
}catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment