Skip to content

Instantly share code, notes, and snippets.

@yangwansu
Last active August 29, 2015 13:57
Show Gist options
  • Save yangwansu/9476016 to your computer and use it in GitHub Desktop.
Save yangwansu/9476016 to your computer and use it in GitHub Desktop.
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();
}
}
}
@yangwansu
Copy link
Author

중복인 눈에 들어왔고 일단 중복단위로 경계를 나누어 보았음 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment