/**
* 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 java.util.ArrayList;
import java.util.Collections;
public class ArticleByArticleNameComparatorTest extends TestCase {
ArticleByArticleNameComparator comparator;
ArrayList articles;
Article a1, a2, a3, a4, a5, a6;
public void setUp() {
comparator = new ArticleByArticleNameComparator();
articles = new ArrayList();
a1 = new Article();
a1.setName("About the earth");
articles.add(a1);
a2 = new Article();
a2.setName("Ziggy Stardust");
articles.add(a2);
a3 = new Article();
a3.setName(null);
articles.add(a3);
a4 = new Article();
a4.setName("Bowling is fun!");
articles.add(a4);
a5 = new Article();
a5.setName(null);
articles.add(a5);
a6 = new Article();
a6.setName(null);
articles.add(a6);
}
public void testComparator() {
ArrayList list = new ArrayList(articles);
Collections.sort(list, comparator);
// Test the order
assertSame(list.get(0), a1);
assertSame(list.get(1), a4);
assertSame(list.get(2), a2);
assertSame(list.get(3), a3);
assertSame(list.get(4), a5);
assertSame(list.get(5), a6);
}
public void testToString() {
comparator = new ArticleByArticleNameComparator("someName");
assertEquals("someName", comparator.toString());
}
}