/*
* Copyright 2009 Google Inc.
*
* 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.gtugs.service;
import org.gtugs.domain.Chapter;
import org.gtugs.repository.InMemoryChapterDao;
import org.gtugs.repository.ChapterDao;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
/**
* @author jasonacooper@google.com (Jason Cooper)
*/
public class SimpleChapterManagerTests extends TestCase {
private SimpleChapterManager chapterManager;
private List<Chapter> chapters;
private static int CHAPTER_COUNT = 2;
private static String GTUG_A_NAME = "GTUG A";
private static String GTUG_B_NAME = "GTUG B";
protected void setUp() throws Exception {
chapterManager = new SimpleChapterManager();
chapters = new ArrayList<Chapter>();
Chapter chapter = new Chapter();
chapter.setName(GTUG_A_NAME);
chapters.add(chapter);
chapter = new Chapter();
chapter.setName(GTUG_B_NAME);
chapters.add(chapter);
ChapterDao chapterDao = new InMemoryChapterDao(chapters);
chapterManager.setChapterDao(chapterDao);
}
public void testGetChaptersWithNoChapters() {
chapterManager = new SimpleChapterManager();
chapterManager.setChapterDao(new InMemoryChapterDao(null));
assertNull(chapterManager.getChapters());
}
public void testGetChapters() {
List<Chapter> chapters = chapterManager.getChapters();
assertNotNull(chapters);
assertEquals(CHAPTER_COUNT, chapterManager.getChapters().size());
Chapter chapter = chapters.get(0);
assertEquals(GTUG_A_NAME, chapter.getName());
chapter = chapters.get(1);
assertEquals(GTUG_B_NAME, chapter.getName());
}
}