Testing Array Utility Operations and Primitive Conversions in Alibaba Arthas
This test suite evaluates the ArrayUtils class functionality in the Arthas core utilities, focusing on array manipulation and primitive type conversions. The tests verify empty array handling and Long to primitive long array conversion operations with various edge cases.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
alibaba/arthas
core/src/test/java/com/taobao/arthas/core/util/ArrayUtilsTest.java
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});
}
}