/** * Copyright 1999-2009 The Pegadi Team * * 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 org.pegadi.articlelist; import junit.framework.TestCase; import no.dusken.common.model.Person; import org.pegadi.model.Article; import java.util.ArrayList; import java.util.Collections; public class ArticleByPhotographerComparatorTest extends TestCase { ArticleByPhotographerComparator comparator; ArrayList articles; Person john, jane, abby, zelda; Article a1, a2, a3, a4, a5, a6, a7; public void setUp() { comparator = new ArticleByPhotographerComparator(); john = new Person(1L, "John", "Doe", "johndoe", "john@doe.com"); jane = new Person(2L, "Jane", "Doe", "janedoe", "jane@doe.com"); abby = new Person(3L, "Abby", "Doe", "abbydoe", "Abby@doe.com"); zelda = new Person(4L, "Zelda", "Doe", "abbydoe", "Abby@doe.com"); articles = new ArrayList(); a1 = new Article(); a1.setName("Article 1"); a1.setPhotographer(john); articles.add(a1); a2 = new Article(); a2.setName("Article 2"); a2.setPhotographer(null); articles.add(a2); a3 = new Article(); a3.setName("Article 3"); a3.setPhotographer(abby); articles.add(a3); a4 = new Article(); a4.setName("Article 4"); a4.setPhotographer(null); articles.add(a4); a5 = new Article(); a5.setName("Article 5"); a5.setPhotographer(null); articles.add(a5); a6 = new Article(); a6.setName("Article 6"); a6.setPhotographer(null); articles.add(a6); a7 = new Article(); a7.setName("Article 7"); a7.setPhotographer(zelda); articles.add(a7); } public void testComparator() { ArrayList list = new ArrayList(articles); Collections.sort(list, comparator); // Test the order assertSame(list.get(0), a3); assertSame(list.get(1), a1); assertSame(list.get(2), a7); assertSame(list.get(3), a2); assertSame(list.get(4), a4); assertSame(list.get(5), a5); assertSame(list.get(6), a6); } public void testToString() { comparator = new ArticleByPhotographerComparator("someName"); assertEquals("someName", comparator.toString()); } }