Java tutorial
/* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package io.github.carlomicieli.footballdb.starter.utils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Test; import java.util.Map; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; public class MapUtilsTests { @Test public void shouldCreateNewPairs() { ImmutablePair<Integer, String> pair = MapUtils.pair(1, "one"); assertThat(pair).isNotNull(); assertThat(pair.getLeft()).isEqualTo(1); assertThat(pair.getRight()).isEqualTo("one"); } @Test public void shouldCreateNewMapsFromStreamOfPairs() { Map<Integer, String> map = MapUtils .newMap(Stream.of(MapUtils.pair(1, "one"), MapUtils.pair(2, "two"), MapUtils.pair(3, "three"))); assertThat(map).isNotNull(); assertThat(map).hasSize(3); } @Test(expected = UnsupportedOperationException.class) public void shouldCreateImmutableMaps() { Map<Integer, Integer> map = MapUtils.newMap(Stream.of(MapUtils.pair(1, 2))); map.put(2, 3); } @Test public void shouldCreateSingletonMaps() { Map<Integer, Integer> map = MapUtils.asMap(1, 2); assertThat(map).isNotNull(); assertThat(map).containsEntry(1, 2); } }