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");
}
}


'general java' 카테고리의 다른 글

[Guava] Monitor 예제  (0) 2015.04.21
[Guava] Futures 예제  (0) 2015.04.17
[Guava] CacheBuilder, CachLoader 예제  (0) 2015.04.15
[Guava] Collections2.filter  (0) 2015.04.14
[Guava] Multimap 예제  (0) 2015.04.11
Posted by '김용환'
,