mirror of
https://gitee.com/arthas/arthas.git
synced 2024-12-02 12:17:45 +08:00
commit
29eef89b86
@ -1,17 +1,17 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
/**
|
||||
* 检查工具类
|
||||
* Utils for checks
|
||||
* Created by vlinux on 15/5/19.
|
||||
*/
|
||||
public class ArthasCheckUtils {
|
||||
|
||||
/**
|
||||
* 比对某个元素是否在集合中<br/>
|
||||
* check whether a component is in an Array<br/>
|
||||
*
|
||||
* @param e 元素
|
||||
* @param s 元素集合
|
||||
* @param <E> 元素类型
|
||||
* @param e component
|
||||
* @param s array
|
||||
* @param <E> component type
|
||||
* @return <br/>
|
||||
* (1,1,2,3) == true
|
||||
* (1,2,3,4) == false
|
||||
@ -33,11 +33,11 @@ public class ArthasCheckUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对两个对象是否相等<br/>
|
||||
* check whether two components are equal<br/>
|
||||
*
|
||||
* @param src 源对象
|
||||
* @param target 目标对象
|
||||
* @param <E> 对象类型
|
||||
* @param src source component
|
||||
* @param target target component
|
||||
* @param <E> component type
|
||||
* @return <br/>
|
||||
* (null, null) == true
|
||||
* (1L,2L) == false
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class ArrayUtilsTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testEmptyLongArray() {
|
||||
Assert.assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, new long[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToPrimitive() {
|
||||
Assert.assertArrayEquals(ArrayUtils.toPrimitive(null), null);
|
||||
Assert.assertArrayEquals(ArrayUtils.toPrimitive(new Long[0]), new long[0]);
|
||||
Assert.assertArrayEquals(
|
||||
ArrayUtils.toPrimitive(new Long[]{
|
||||
1L,
|
||||
1763L,
|
||||
54769975464L
|
||||
}),
|
||||
new long[]{
|
||||
1L,
|
||||
1763L,
|
||||
54769975464L
|
||||
});
|
||||
//throws NullPointerException if array content is null
|
||||
thrown.expect(NullPointerException.class);
|
||||
Assert.assertArrayEquals(ArrayUtils.toPrimitive(new Long[]{null}), new long[]{1L});
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author earayu
|
||||
*/
|
||||
public class ArthasCheckUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testIsIn(){
|
||||
Assert.assertTrue(ArthasCheckUtils.isIn(1,1,2,3));
|
||||
Assert.assertFalse(ArthasCheckUtils.isIn(1,2,3,4));
|
||||
Assert.assertTrue(ArthasCheckUtils.isIn(null,1,null,2));
|
||||
Assert.assertFalse(ArthasCheckUtils.isIn(1,null));
|
||||
Assert.assertTrue(ArthasCheckUtils.isIn(1L,1L,2L,3L));
|
||||
Assert.assertFalse(ArthasCheckUtils.isIn(1L,2L,3L,4L));
|
||||
Assert.assertTrue(ArthasCheckUtils.isIn("foo","foo","bar"));
|
||||
Assert.assertFalse(ArthasCheckUtils.isIn("foo","bar","goo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIsEquals(){
|
||||
Assert.assertTrue(ArthasCheckUtils.isEquals(1,1));
|
||||
Assert.assertTrue(ArthasCheckUtils.isEquals(1L,1L));
|
||||
Assert.assertTrue(ArthasCheckUtils.isEquals("foo","foo"));
|
||||
Assert.assertFalse(ArthasCheckUtils.isEquals(1,2));
|
||||
Assert.assertFalse(ArthasCheckUtils.isEquals("foo","bar"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user