Merge pull request #4760 from MajewskiKrzysztof/master

BAEL-1912
This commit is contained in:
Tom Hombergs
2018-08-19 16:41:59 +02:00
committed by GitHub
3 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package org.baeldung.java.collections;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
class CollectionsEmpty {
@Test
public void givenArrayList_whenAddingElement_addsNewElement() {
ArrayList<String> mutableList = new ArrayList<>();
mutableList.add("test");
Assert.assertEquals(mutableList.size(), 1);
Assert.assertEquals(mutableList.get(0), "test");
}
@Test(expected = UnsupportedOperationException.class)
public void givenCollectionsEmptyList_whenAddingElement_throwsUnsupportedOperationException() {
List<String> immutableList = Collections.emptyList();
immutableList.add("test");
}
}