/** * 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 org.pegadi.model.Article; import org.pegadi.model.ArticleType; import java.util.ArrayList; import java.util.Collections; public class ArticleByArticleTypeComparatorTest extends TestCase { ArticleByArticleTypeComparator comparator; ArrayList articles; Article a1, a2, a3; ArticleType news, culture, feature; public void setUp() { comparator = new ArticleByArticleTypeComparator(); articles = new ArrayList(); news = new ArticleType(new Integer(1), "News", "blabla"); culture = new ArticleType(new Integer(2), "Culture", "blabla"); feature = new ArticleType(new Integer(3), "Feature", "blabla"); a1 = new Article(); a1.setArticleType(news); articles.add(a1); a2 = new Article(); a2.setArticleType(culture); articles.add(a2); a3 = new Article(); a3.setArticleType(feature); articles.add(a3); } public void testComparator() { ArrayList list = new ArrayList(articles); Collections.sort(list, comparator); // Test the order assertSame(list.get(0), a2); assertSame(list.get(1), a3); assertSame(list.get(2), a1); } public void testToString() { comparator = new ArticleByArticleTypeComparator("someName"); assertEquals("someName", comparator.toString()); } }