@Test public void shouldAllowArraysOfMapsToBeAddedToTheMapWithAndMaps() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> map = new HashMap<String, Integer>(); map.put("five", 5); map.put("ten", 10); Map<String, Integer> secondMap = new HashMap<String, Integer>(); secondMap.put("fifteen", 15); Map<String, Integer> thirdMap = new HashMap<String, Integer>(); thirdMap.put("twenty", 20); @SuppressWarnings("unchecked") Map<String, Integer>[] mapArray = new Map[] {secondMap, thirdMap}; Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("five", 5); expectedMap.put("ten", 10); expectedMap.put("fifteen", 15); expectedMap.put("twenty", 20); // When Map<String, Integer> actualMap = mapBuilder.with(map).andMaps(mapArray).build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowIterablesOfMapsToBeAddedToTheMapWithAndMaps() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> firstMap = new HashMap<String, Integer>(); firstMap.put("third", 3); firstMap.put("fourth", 4); Map<String, Integer> secondMap = new HashMap<String, Integer>(); firstMap.put("fifth", 5); Iterable<Map<String, Integer>> maps = iterableWith(firstMap, secondMap); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("first", 1); expectedMap.put("second", 2); expectedMap.put("third", 3); expectedMap.put("fourth", 4); expectedMap.put("fifth", 5); // When Map<String, Integer> actualMap = mapBuilder.withKeyValuePairs("first", 1, "second", 2).andMaps(maps).build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowArraysOfMapEntryInstancesToBeAddedToTheMapWithWithEntries() throws Exception { // Given Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("five", 5); expectedMap.put("ten", 10); expectedMap.put("fifteen", 15); expectedMap.put("twenty", 20); @SuppressWarnings("unchecked") Map.Entry<String, Integer>[] firstMapEntryArray = new Map.Entry[] {mapEntryFor("five", 5), mapEntryFor("ten", 10)}; @SuppressWarnings("unchecked") Map.Entry<String, Integer>[] secondMapEntryArray = new Map.Entry[] {mapEntryFor("fifteen", 15), mapEntryFor("twenty", 20)}; // When Map<String, Integer> actualMap = mapBuilder(String.class, Integer.class) .withEntries(firstMapEntryArray) .withEntries(secondMapEntryArray) .build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowMapsToBeAddedToTheMapWithAndMaps() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> firstMap = new HashMap<String, Integer>(); firstMap.put("second", 2); Map<String, Integer> secondMap = new HashMap<String, Integer>(); secondMap.put("third", 3); secondMap.put("fourth", 4); Map<String, Integer> expected = new HashMap<String, Integer>(); expected.put("first", 1); expected.put("second", 2); expected.put("third", 3); expected.put("fourth", 4); // When Map<String, Integer> actual = mapBuilder.with(tuple("first", 1)).and(firstMap, secondMap).build(); // Then assertThat(actual, is(expected)); }
@Test public void shouldAllowTuplesToBeAddedToTheMapWithWithPairs() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expected = new HashMap<String, Integer>(); expected.put("first", 1); expected.put("second", 2); expected.put("third", 3); // When Map<String, Integer> actual = mapBuilder.with(tuple("first", 1)).with(tuple("second", 2), tuple("third", 3)).build(); // Then assertThat(actual, is(expected)); }
@Test public void shouldAllowIterablesOfTuplesToBeAddedToTheMapWithWithPairs() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("one", 1); expectedMap.put("two", 2); expectedMap.put("three", 3); expectedMap.put("four", 4); Iterable<Pair<String, Integer>> firstInputIterable = listWith(tuple("one", 1), tuple("two", 2)); Iterable<Pair<String, Integer>> secondInputIterable = listWith(tuple("three", 3), tuple("four", 4)); // When Map<String, Integer> actualMap = mapBuilder.withPairs(firstInputIterable).withPairs(secondInputIterable).build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowMapEntryInstancesToBeAddedToTheMapWithAndEntries() { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("five", 5); expectedMap.put("ten", 10); expectedMap.put("fifteen", 15); expectedMap.put("twenty", 20); // When Map<String, Integer> actualMap = mapBuilder .with(mapEntryFor("five", 5)) .and(mapEntryFor("ten", 10), mapEntryFor("fifteen", 15)) .and(mapEntryFor("twenty", 20)) .build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowKeysAndValuesToBeAddedToTheMapWithAndKeyValuePairs() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expected = new HashMap<String, Integer>(); expected.put("zeroth", 0); expected.put("first", 1); expected.put("second", 2); expected.put("third", 3); // When Map<String, Integer> actual = mapBuilder .withKeyValuePair("zeroth", 0) .andKeyValuePairs("first", 1, "second", 2) .andKeyValuePair("third", 3) .build(); // Then assertThat(actual, is(expected)); }
@Test public void shouldAllowIterablesOfTuplesToBeAddedToTheMapWithAndPairs() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("first", 1); expectedMap.put("second", 2); expectedMap.put("third", 3); expectedMap.put("fourth", 4); Iterable<Pair<String, Integer>> iterableOfTuples = listWith(tuple("third", 3), tuple("fourth", 4)); // When Map<String, Integer> actualMap = mapBuilder .with(mapEntryFor("first", 1), mapEntryFor("second", 2)) .andPairs(iterableOfTuples) .build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowArraysOfTuplesToBeAddedToTheMapWithAndPairs() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("five", 5); expectedMap.put("ten", 10); expectedMap.put("fifteen", 15); expectedMap.put("twenty", 20); @SuppressWarnings("unchecked") Pair<String, Integer>[] tupleArray = new Pair[] {tuple("fifteen", 15), tuple("twenty", 20)}; // When Map<String, Integer> actualMap = mapBuilder .with(mapEntryFor("five", 5), mapEntryFor("ten", 10)) .andPairs(tupleArray) .build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowIterablesOfMapEntryInstancesToBeAddedToTheMapWithAndEntries() throws Exception { // Given MapBuilder<String, Integer> mapBuilder = mapBuilder(); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("first", 1); expectedMap.put("second", 2); expectedMap.put("third", 3); expectedMap.put("fourth", 4); Iterable<Map.Entry<String, Integer>> someOtherElements = listWith(mapEntryFor("third", 3), mapEntryFor("fourth", 4)); // When Map<String, Integer> actualMap = mapBuilder .with(mapEntryFor("first", 1), mapEntryFor("second", 2)) .andEntries(someOtherElements) .build(); // Then assertThat(actualMap, is(expectedMap)); }
@Test public void shouldAllowArraysOfTuplesToBeAddedToTheMapWithWithPairs() throws Exception { // Given Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("five", 5); expectedMap.put("ten", 10); expectedMap.put("fifteen", 15); expectedMap.put("twenty", 20); @SuppressWarnings("unchecked") Pair<String, Integer>[] firstTupleArray = new Pair[] {tuple("five", 5), tuple("ten", 10)}; @SuppressWarnings("unchecked") Pair<String, Integer>[] secondTupleArray = new Pair[] {tuple("fifteen", 15), tuple("twenty", 20)}; // When Map<String, Integer> actualMap = mapBuilder(String.class, Integer.class) .withPairs(firstTupleArray) .withPairs(secondTupleArray) .build(); // Then assertThat(actualMap, is(expectedMap)); }