package core.arraylist;

import org.junit.After;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class AddTest {

	private List<String> list = new ArrayList<>();

	@After
	public void clear() {
		list.clear();
	}

	@Test
	public void addTest() {
		assertTrue(list.add("AAPL"));
		assertEquals(list, Collections.singletonList("AAPL"));
	}

	@Test
	public void addAtIndexTest() {
		list.add("AAPL");

		list.add(0, "GOOG");
		assertEquals(list, Arrays.asList("GOOG", "AAPL"));

		list.add(2, "IBM");
		assertEquals(list, Arrays.asList("GOOG", "AAPL", "IBM"));
	}

	@Test(expected = IndexOutOfBoundsException.class)
	public void addAtNegativeIndex() {
		list.add(-1, "AAPL");
	}

	@Test(expected = IndexOutOfBoundsException.class)
	public void addAtExceedingIndex() {
		list.add(1, "AAPL");
	}
}

@@ -409,20 +409,16 @@
 void add
-Test
 () %7B%0A%09%09a
@@ -537,20 +537,16 @@
 dAtIndex
-Test
 () %7B%0A%09%09l

test refactoring