1 package uk.org.lidalia.slf4jtest; 2 3 import com.google.common.base.Supplier; 4 import com.google.common.collect.ImmutableMap; 5 import org.junit.Test; 6 7 import java.util.List; 8 import java.util.Map; 9 10 import static java.util.Arrays.asList; 11 import static org.hamcrest.Matchers.is; 12 import static org.hamcrest.Matchers.not; 13 import static org.hamcrest.Matchers.sameInstance; 14 import static org.junit.Assert.assertThat; 15 import static uk.org.lidalia.slf4jtest.Suppliers.makeEmptyMutableList; 16 import static uk.org.lidalia.slf4jtest.Suppliers.makeEmptyMutableMap; 17 import static uk.org.lidalia.test.Assert.isNotInstantiable; 18 19 public class SuppliersTests { 20 21 @Test 22 public void makeEmptyMutableListAlwaysMakesANewList() { 23 Supplier<List<String>> listSupplier = makeEmptyMutableList(); 24 List<String> list1 = listSupplier.get(); 25 List<String> list2 = listSupplier.get(); 26 assertThat(list1, is(not(sameInstance(list2)))); 27 } 28 29 @Test 30 public void makeEmptyMutableListMakesAMutableList() { 31 List<String> list = Suppliers.<String>makeEmptyMutableList().get(); 32 list.add("value"); 33 assertThat(list, is(asList("value"))); 34 } 35 36 @Test 37 public void makeEmptyMutableMapAlwaysMakesANewMap() { 38 Supplier<Map<String, String>> mapSupplier = makeEmptyMutableMap(); 39 Map<String, String> map1 = mapSupplier.get(); 40 Map<String, String> map2 = mapSupplier.get(); 41 assertThat(map1, is(not(sameInstance(map2)))); 42 } 43 44 @Test 45 public void makeEmptyMutableMapMakesAMutableMap() { 46 Map<String, String> map = Suppliers.<String, String>makeEmptyMutableMap().get(); 47 map.put("key", "value"); 48 Map<String, String> expected = ImmutableMap.of("key", "value"); 49 assertThat(map, is(expected)); 50 } 51 52 @Test 53 public void notInstantiable() { 54 assertThat(Suppliers.class, isNotInstantiable()); 55 } 56 }