@Test
public void testCheckNotNull(){
checkNotNull(null);
}
private void checkNotNull(final List<String> list){
Preconditions.checkNotNull(list);
}
@Test
public void testCheckNotNull1(){
try{
checkNotNull1(null);
}catch (Exception e){
assertThat(e,is(NullPointerException.class));
assertThat(e.getMessage(),equalTo("this list should not be null."));
}
}
private void checkNotNull1(final List<String> list){
Preconditions.checkNotNull(list,"this list should not be null.");
}
@Test
public void testCheckNotNull2(){
try{
checkNotNull2(null);
}catch (Exception e){
assertThat(e,is(NullPointerException.class));
assertThat(e.getMessage(),equalTo("this list should not be null and the size must be 2"));
}
}
private void checkNotNull2(final List<String> list){
Preconditions.checkNotNull(list,"this list should not be null and the size must be %s",2);
}
@Test
public void testcheckNotNull3(){
final String type="A";
try {
Preconditions.checkArgument(type.equals("B"));
}catch (Exception e){
assertThat(e,is(IllegalArgumentException.class));
}
}
@Test
public void testcheckNotNull4(){
final String state="A";
try {
Preconditions.checkArgument(state.equals("B"),"this state is illegal.");
}catch (Exception e){
assertThat(e,is(IllegalStateException.class));
}
}
@Test
public void testcheckNotNull5(){
try {
List<String> list= ImmutableList.of();
Preconditions.checkElementIndex(10,list.size());
}catch (Exception e){
assertThat(e,is(IndexOutOfBoundsException.class));
}
}
@Test
public void testcheckNotNull6(){
Objects.requireNonNull(null);
}
Guava 断言
最新推荐文章于 2024-09-11 11:27:49 发布