/** * 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.ArticleStatus; import java.util.ArrayList; import java.util.Collections; public class ArticleByStatusComparatorTest extends TestCase { ArticleByStatusComparator comparator; ArrayList<Article> articles; ArticleStatus ready, steady, go; Article a1, a2, a3, a4, a5, a6, a7; public void setUp() { comparator = new ArticleByStatusComparator(); ready = new ArticleStatus(2); ready.setName("Ready"); steady = new ArticleStatus(3); steady.setName("Steady"); go = new ArticleStatus(1); go.setName("Go"); articles = new ArrayList<Article>(); a1 = new Article(); a1.setArticleStatus(ready); articles.add(a1); a2 = new Article(); a2.setArticleStatus(steady); articles.add(a2); a3 = new Article(); a3.setArticleStatus(go); articles.add(a3); } public void testComparator() { ArrayList<Article> list = new ArrayList<Article>(articles); Collections.sort(list, comparator); // Test the order assertSame(list.get(0), a3); assertSame(list.get(1), a1); assertSame(list.get(2), a2); } public void testToString() { comparator = new ArticleByStatusComparator("someName"); assertEquals("someName", comparator.toString()); } }