general java
[Guava] Preconditions 예제
'김용환'
2015. 4. 16. 08:01
Guava의 Preconditions는 java core의 assert() 보다 더 세련된 API이다.
Spring 빈 생성 후 afterPropertiesSet() 에서 체크할 때 사용한다.
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;
import com.google.common.base.Preconditions;
public class GuavaTest {
String rootPath;
@Before
public void before() {
rootPath = "/root/service/";
}
@Test
public void simpleTest() {
Preconditions.checkNotNull(rootPath, "rootPath should be configured");
Preconditions.checkArgument(!StringUtils.isEmpty(rootPath), "rootPath is empty");
}
import org.junit.Before;
import org.junit.Test;
import com.google.common.base.Preconditions;
public class GuavaTest {
String rootPath;
@Before
public void before() {
rootPath = "/root/service/";
}
@Test
public void simpleTest() {
Preconditions.checkNotNull(rootPath, "rootPath should be configured");
Preconditions.checkArgument(!StringUtils.isEmpty(rootPath), "rootPath is empty");
}
}