Last active
August 29, 2015 13:57
-
-
Save yangwansu/9476016 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(); | |
printHeader("preconditions.checkNotNull"); | |
try{ | |
test1.testForNonNullArgument(null); | |
}catch(NullPointerException npe) | |
{ | |
npe.printStackTrace(); | |
} | |
printHeader("precondition.checkArgument"); | |
try{ | |
test1.testDivisorNotZero(0); | |
}catch(IllegalArgumentException illArgEx){ | |
illArgEx.printStackTrace(); | |
} | |
printHeader("Preconditions.checkElementIndex"); | |
try{ | |
test1.testArrayElement(new String[]{"Dustin","java"},3 ); | |
}catch(IndexOutOfBoundsException ioobEx){ | |
ioobEx.printStackTrace(); | |
} | |
printHeader("Preconditions.checkPositionIndex"); | |
try{ | |
test1.testarrayPosition(new String[]{"Dustin","java"},3); | |
}catch(IndexOutOfBoundsException ioobex){ | |
ioobex.printStackTrace(); | |
} | |
printHeader("Preconditions.checkState"); | |
try{ | |
test1.testState(); | |
}catch(IllegalStateException illStateEx){ | |
illStateEx.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
중복인 눈에 들어왔고 일단 중복단위로 경계를 나누어 보았음 ..