Skip to content

Commit

Permalink
[#noissue] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed May 26, 2023
1 parent 39e5384 commit 888bb62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static <T> T getArgument(Object[] args, int index, Class<T> type) {

@SuppressWarnings("unchecked")
public static <T> T getArgument(Object[] args, int index, Class<T> type, T defaultValue) {
if (args == null) {
if (ArrayUtils.isEmpty(args)) {
return defaultValue;
}
final Object arg = getArg(args, index);
Expand All @@ -21,8 +21,7 @@ public static <T> T getArgument(Object[] args, int index, Class<T> type, T defau
}

private static Object getArg(Object[] args, int index) {
final int length = args.length;
if (index >= 0 && length > index) {
if (index >= 0 && index < args.length) {
return args[index];
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class ArrayArgumentUtilsTest {

@Test
public void getTest() {
public void getArgument() {
Object[] args = {"0", "1"};
String arg0 = ArrayArgumentUtils.getArgument(args, 0, String.class);
assertEquals("0", arg0);
Expand All @@ -18,15 +18,15 @@ public void getTest() {
}

@Test
public void getTest_array() {
public void getArgument_array() {
Object[] args = {new Object[]{"0-0"}, new Object[]{"1-0"}};

Object[] arg0 = ArrayArgumentUtils.getArgument(args, 0, Object[].class);
assertArrayEquals(new Object[]{"0-0"}, arg0);
}

@Test
public void getTest_typecast() {
public void getArgument_typecast() {
Object[] args = {"0", 1};
String arg0 = ArrayArgumentUtils.getArgument(args, 0, String.class);
assertEquals("0", arg0);
Expand All @@ -35,33 +35,46 @@ public void getTest_typecast() {
}

@Test
public void getTest_typecast_error() {
public void getArgument_typecast_error() {
Object[] args = {"0", 1};
String arg0 = ArrayArgumentUtils.getArgument(args, 0, String.class);
assertEquals("0", arg0);
String arg1 = ArrayArgumentUtils.getArgument(args, 1, String.class);
assertNull(arg1);
}


@Test
public void getTest_NPE() {
public void getArgument_NPE() {
Object[] args = null;
String arg2 = ArrayArgumentUtils.getArgument(args, 0, String.class);
assertNull(arg2);
}

@Test
public void getTest_negative() {
public void getArgument_negative() {
Object[] args = {"0", "1"};
String arg2 = ArrayArgumentUtils.getArgument(args, -1, String.class);
assertNull(arg2);
}

@Test
public void getTest_OOB() {
public void getArgument_OOB() {
Object[] args = {"0", "1"};
String arg2 = ArrayArgumentUtils.getArgument(args, 2, String.class);
assertNull(arg2);
}

@Test
public void getArgument_empty() {
Object[] args = {};
Object arg0 = ArrayArgumentUtils.getArgument(args, 0, Object.class);
assertNull(arg0);
}

@Test
public void getArgument_null() {
Object[] args = {null};
Object arg0 = ArrayArgumentUtils.getArgument(args, 0, Object.class, "empty");
assertEquals("empty", arg0);
}
}

0 comments on commit 888bb62

Please sign in to comment.