Created
March 10, 2014 23:15
-
-
Save yangwansu/9476436 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.testArrayElement(new String[]{"Dustin","java"},3 ); | |
test1.testDivisorNotZero(0); | |
test1.testForNonNullArgument(null); | |
test(test1, "preconditions.checkNotNull"); | |
test(test1, "precondition.checkArgument"); | |
test(test1, "Preconditions.checkElementIndex"); | |
test(new TestCase() { | |
@Override | |
public void run() { | |
test1.testarrayPosition(new String[]{"Dustin","java"},3); | |
} | |
}, "Preconditions.checkPositionIndex"); | |
test(new TestCase() { | |
@Override | |
public void run() { | |
test1.testState(); | |
} | |
}, "Preconditions.checkState"); | |
} | |
private static void test(TestCase testcase, String message) { | |
printHeader(message); | |
try{ | |
testcase.run(); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test4(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test3(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test2(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
private static void test1(GuavaTest1 test1, String message) { | |
printHeader(message); | |
try{ | |
}catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
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; | |
public interface TestCase { | |
void run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment