package study.hard.javalib.nativelib;

import org.junit.Before;
import org.junit.Test;

public class ArrayTest {

	Integer[] intArray = new Integer[11];

	@Before
	public void setUp() {
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = (int)(Math.random() * 100);
		}
	}

	@Test
	public void findTheAverageOfNumbersInArray() {
		for (Integer num : intArray) {
			System.out.print(num + ", ");
		}

		Integer sum = 0;
		for (Integer num : intArray) {
			sum += num;
		}
		System.out.println("sum: " + sum);

		System.out.print("average: ");
		System.out.println(sum.floatValue() / intArray.length);
	}

	@Test(expected = java.lang.ArrayIndexOutOfBoundsException.class)
	public void testLengthOfEmptyArray() {
		String[] array = {};

		if (array == null) {
			System.out.println("array is null");
		} else {
			System.out.println("array is not null, but...");
			String temp = array[0];
			System.out.println(temp);
		}
	}
}

@@ -32,16 +32,93 @@
 velib;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A
 import o
@@ -681,24 +681,53 @@
 ength);%0A%09%7D%0A%0A
+%09@SuppressWarnings(%22unused%22)%0A
 %09@Test(expec
@@ -906,16 +906,45 @@
  null%22);
+ // This is unreachable code.
 %0A%09%09%7D els
@@ -1029,41 +1029,482 @@
 %5B0%5D;
-%0A%09%09%09System.out.println(temp);%0A%09%09%7D
+ // This code will make ArrayIndexOutOfBoundsException...%0A%09%09%09System.out.println(temp);%0A%09%09%7D%0A%09%7D%0A%0A%09@Test(expected = java.lang.NullPointerException.class)%0A%09public void makeArrayListFromArray() %7B%0A%09%09String%5B%5D array = %7B%7D;%0A%09%09List%3CObject%3E arrayList = new ArrayList%3CObject%3E(Arrays.asList(array));%0A%09%09System.out.println(arrayList);%0A%0A%09%09array = null;%0A%09%09arrayList = new ArrayList%3CObject%3E(Arrays.asList(array)); // This code will make NullPointerException...%0A%09%09System.out.println(arrayList);
 %0A%09%7D%0A

Add a test case that has a possibility of occurring NullPointerException when using Array.