package org.rapidoid.fluent; import org.junit.Test; import org.rapidoid.test.TestCommons; import java.util.List; import java.util.Map; import java.util.Set; /* * #%L * rapidoid-fluent * %% * Copyright (C) 2014 - 2017 Nikolche Mihajlovski and contributors * %% * 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. * #L% */ /** * @author Nikolche Mihajlovski * @since 5.0.2 */ public class NewTest extends TestCommons { @Test public void testSet() { Set<Integer> set = New.set(1, 3, 5, 8); eq((set.size()), 4); isTrue(set.contains(1)); isTrue(set.contains(3)); isTrue(set.contains(5)); isTrue(set.contains(8)); } @Test public void testList() { List<String> list = New.list("m", "k", "l"); eq((list.size()), 3); eq((list.get(0)), "m"); eq((list.get(1)), "k"); eq((list.get(2)), "l"); } @Test public void testMap() { Map<String, Integer> map = New.map(); isTrue((map.isEmpty())); } @Test public void testMapKV() { Map<String, Integer> map = New.map("a", 1); eq((map.size()), 1); eq((map.get("a").intValue()), 1); } @Test public void testMapKVKV() { Map<String, Integer> map = New.map("a", 1, "b", 2); eq((map.size()), 2); eq((map.get("a").intValue()), 1); eq((map.get("b").intValue()), 2); } @Test public void testMapKVKVKV() { Map<String, Integer> map = New.map("a", 1, "b", 2, "c", 3); eq((map.size()), 3); eq((map.get("a").intValue()), 1); eq((map.get("b").intValue()), 2); eq((map.get("c").intValue()), 3); } @Test public void testMapKVKVKVKV() { Map<String, Integer> map = New.map("a", 1, "b", 2, "c", 3, "d", 4); eq((map.size()), 4); eq((map.get("a").intValue()), 1); eq((map.get("b").intValue()), 2); eq((map.get("c").intValue()), 3); eq((map.get("d").intValue()), 4); } }