Skip to content

Instantly share code, notes, and snippets.

@dwursteisen
Created January 27, 2011 09:53
Show Gist options
  • Save dwursteisen/798309 to your computer and use it in GitHub Desktop.
Save dwursteisen/798309 to your computer and use it in GitHub Desktop.
package itw;
import java.util.Collection;
public class AboutCollections {
/**
* La méthode retourne une liste avec les élements de stringList sans les doublons.
*
* @param stringList
* @return
*/
public Collection<String> uniqueElements(final Collection<String> stringList) {
}
/**
* La méthode retourne une liste contenant les élements de toutes les listes passées en paramètre.
*
* @param lists
* @return
*/
public Collection<String> createOneBigCollection(Collection<String> l1, Collection<String> l2, Collection<String> l3) {
}
}
package itw;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class AboutCollectionsTest {
private AboutCollections obj;
@Before
public void setUp() {
obj = new AboutCollections();
}
@Test
public void testUniqueElements() {
Collection<String> stringList = Arrays.asList("david", "alexandre", "nicolas", "beko", "alexandre", "nicolas");
Collection<String> result = obj.uniqueElements(stringList);
assertEquals(4, result.size());
assertTrue(result.contains("david"));
assertTrue(result.contains("alexandre"));
assertTrue(result.contains("nicolas"));
assertTrue(result.contains("beko"));
}
@Test
public void testOneBigCollection() {
Collection<String> stringList1 = Arrays.asList("mickey", "donald");
Collection<String> stringList2 = Arrays.asList("pluto", "daisy");
Collection<String> stringList3 = Arrays.asList("bugs bunny", "picsou");
Collection<String> result = obj.createOneBigCollection(stringList1, stringList2, stringList3);
assertEquals(6, result.size());
assertTrue(result.contains("mickey"));
assertTrue(result.contains("daisy"));
assertTrue(result.contains("bugs bunny"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment