/*
 * Copyright 2011-2015 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * 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 com.b2international.commons.test;

import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.assertTrue;

import java.util.Set;

import org.junit.Test;

import com.b2international.collections.ints.IntIterator;
import com.b2international.commons.collect.IntKeySetMultimap;

/**
 * Test for {@link IntKeySetMultimap}.
 */
public class IntKeySetMultimapTest {

	@Test(expected = NullPointerException.class)
	public void putNullValueTest() {
		new IntKeySetMultimap<>().put(0, null);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void putInvalidValueTest() {
		new IntKeySetMultimap<>().put(0, Integer.valueOf(111));
	}
	
	@Test
	public void putValidValueTest() {
		new IntKeySetMultimap<>().put(0, Integer.valueOf(111));
		new IntKeySetMultimap<>().put(0, Integer.valueOf(111));
		new IntKeySetMultimap<>().put(0, Integer.valueOf(111));
	}
	
	@Test
	public void putAndCheckDistinctValues() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.put(2, "Two_1");
		multimap.put(2, "Two_2");
		multimap.put(2, "Two_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_2");
		multimap.put(3, "Three_3");
		assertTrue(multimap.get(1).size() == 1);
		assertTrue(multimap.get(2).size() == 2);
		assertTrue(multimap.get(3).size() == 3);
	}
	
	@Test
	public void checkNotExistingValues() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		assertTrue(multimap.get(-1) instanceof Set);
	}
	
	@Test(expected = UnsupportedOperationException.class)
	public void checkViewOfValues() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.get(1).add("Must fail");
	}
	
	@Test
	public void putAndCheckValues() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.put(2, "Two_1");
		multimap.put(2, "Two_2");
		multimap.put(2, "Two_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_2");
		multimap.put(3, "Three_3");
		assertTrue(multimap.values().size() == 3);
	}
	
	@Test
	public void putAndCheckFlatValues() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.put(2, "Two_1");
		multimap.put(2, "Two_2");
		multimap.put(2, "Two_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_2");
		multimap.put(3, "Three_3");
		assertTrue(newHashSet(concat(multimap.values())).size() == 6);
	}
	
	@Test
	public void putAndCheckSize() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.put(2, "Two_1");
		multimap.put(2, "Two_2");
		multimap.put(2, "Two_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_2");
		multimap.put(3, "Three_3");
		assertTrue(multimap.size() == 3);
	}
	
	@Test
	public void putAndCheckIterator() {
		final IntKeySetMultimap<String> multimap = new IntKeySetMultimap<>();
		multimap.put(1, "One_1");
		multimap.put(2, "Two_1");
		multimap.put(2, "Two_2");
		multimap.put(2, "Two_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_1");
		multimap.put(3, "Three_2");
		multimap.put(3, "Three_3");

		final IntIterator keys = multimap.keySet().iterator();
		while (keys.hasNext()) {
			final int key = keys.next();
			multimap.get(key);
		}
		
		assertTrue(multimap.size() == 0);
		assertTrue(multimap.isEmpty());
	}
	
}
@@ -820,22 +820,23 @@
 sert
-True;%0A
+Equals;
 %0Aimport 
 java
@@ -835,21 +835,42 @@
 ort 
-java.util.Set
+static org.junit.Assert.assertTrue
 ;%0A%0Ai
@@ -1101,506 +1101,8 @@
  %7B%0A%0A
-%09@Test(expected = NullPointerException.class)%0A%09public void putNullValueTest() %7B%0A%09%09new IntKeySetMultimap%3C%3E().put(0, null);%0A%09%7D%0A%09%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void putInvalidValueTest() %7B%0A%09%09new IntKeySetMultimap%3C%3E().put(0, Integer.valueOf(111));%0A%09%7D%0A%09%0A%09@Test%0A%09public void putValidValueTest() %7B%0A%09%09new IntKeySetMultimap%3C%3E().put(0, Integer.valueOf(111));%0A%09%09new IntKeySetMultimap%3C%3E().put(0, Integer.valueOf(111));%0A%09%09new IntKeySetMultimap%3C%3E().put(0, Integer.valueOf(111));%0A%09%7D%0A%09%0A
 %09@Te
@@ -1767,23 +1767,18 @@
 (-1)
- instanceof Set
+.isEmpty()
 );%0A%09
@@ -3773,56 +3773,36 @@
 %0A%09%09%09
-final int key = keys.next();%0A%09%09%09multimap.get(key
+keys.next();%0A%09%09%09keys.remove(
 );%0A%09
@@ -3807,37 +3807,42 @@
 %0A%09%09%7D%0A%09%09%0A%09%09assert
-True(
+Equals(0, 
 multimap.size() 
@@ -3844,13 +3844,8 @@
 ze()
- == 0
 );%0A%09

remove no longer valid IntKeySetMultimap test cases