546N/A/*
613N/A * CDDL HEADER START
613N/A *
613N/A * The contents of this file are subject to the terms of the
613N/A * Common Development and Distribution License (the "License").
613N/A * You may not use this file except in compliance with the License.
613N/A *
613N/A * See LICENSE.txt included in this distribution for the specific
613N/A * language governing permissions and limitations under the License.
613N/A *
613N/A * When distributing Covered Code, include this CDDL HEADER in each
613N/A * file and include the License file at LICENSE.txt.
613N/A * If applicable, add the following below this CDDL HEADER, with the
613N/A * fields enclosed by brackets "[]" replaced with your own identifying
613N/A * information: Portions Copyright [yyyy] [name of copyright owner]
613N/A *
613N/A * CDDL HEADER END
546N/A */
546N/A
613N/A/*
613N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
613N/A * Use is subject to license terms.
613N/A */
546N/Apackage org.opensolaris.opengrok.history;
546N/A
546N/Aimport java.util.ArrayList;
900N/Aimport java.util.Collections;
546N/Aimport java.util.Date;
546N/Aimport java.util.List;
802N/Aimport java.util.TreeSet;
546N/Aimport org.junit.After;
546N/Aimport org.junit.AfterClass;
546N/Aimport org.junit.Before;
546N/Aimport org.junit.BeforeClass;
546N/Aimport org.junit.Test;
546N/Aimport static org.junit.Assert.*;
546N/A
546N/A/**
546N/A *
546N/A * @author austvik
546N/A */
546N/Apublic class HistoryEntryTest {
546N/A
546N/A private HistoryEntry instance;
546N/A private Date historyDate = new Date();
546N/A private String historyRevision = "1.0";
546N/A private String historyAuthor = "test author";
546N/A private String historyMessage = "history entry message";
546N/A
546N/A public HistoryEntryTest() {
546N/A }
546N/A
546N/A @BeforeClass
546N/A public static void setUpClass() throws Exception {
546N/A }
546N/A
546N/A @AfterClass
546N/A public static void tearDownClass() throws Exception {
546N/A }
546N/A
546N/A @Before
546N/A public void setUp() {
1481N/A instance = new HistoryEntry(historyRevision, null, historyDate, historyAuthor, historyMessage, true);
546N/A }
546N/A
546N/A @After
546N/A public void tearDown() {
546N/A }
546N/A
546N/A /**
546N/A * Test of getLine method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getLine() {
546N/A assertTrue(instance.getLine().contains(historyRevision));
546N/A assertTrue(instance.getLine().contains(historyAuthor));
546N/A }
546N/A
546N/A /**
546N/A * Test of dump method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void dump() {
546N/A instance.dump();
549N/A instance.setActive(false);
549N/A instance.addFile("testFile1.txt");
549N/A instance.addFile("testFile2.txt");
549N/A instance.addChangeRequest("CR1");
549N/A instance.addChangeRequest("CR2");
549N/A instance.dump();
546N/A }
546N/A
546N/A /**
546N/A * Test of getAuthor method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getAuthor() {
546N/A String result = instance.getAuthor();
546N/A assertEquals(historyAuthor, result);
546N/A }
546N/A
546N/A /**
546N/A * Test of getDate method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getDate() {
546N/A assertEquals(historyDate, instance.getDate());
546N/A instance.setDate(null);
546N/A assertNull(instance.getDate());
546N/A }
546N/A
546N/A /**
546N/A * Test of getMessage method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getMessage() {
546N/A assertEquals(historyMessage, instance.getMessage());
546N/A }
546N/A
546N/A /**
546N/A * Test of getRevision method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getRevision() {
546N/A assertEquals(historyRevision, instance.getRevision());
546N/A }
546N/A
546N/A /**
546N/A * Test of setAuthor method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setAuthor() {
546N/A String newAuthor = "New Author";
546N/A instance.setAuthor(newAuthor);
546N/A assertEquals(newAuthor, instance.getAuthor());
546N/A }
546N/A
546N/A /**
546N/A * Test of setDate method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setDate() {
546N/A Date date = new Date();
546N/A instance.setDate(date);
546N/A assertEquals(date, instance.getDate());
546N/A }
546N/A
546N/A /**
546N/A * Test of isActive method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void isActive() {
546N/A assertEquals(true, instance.isActive());
546N/A instance.setActive(false);
546N/A assertEquals(false, instance.isActive());
546N/A }
546N/A
546N/A /**
546N/A * Test of setActive method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setActive() {
546N/A instance.setActive(true);
546N/A assertEquals(true, instance.isActive());
546N/A instance.setActive(false);
546N/A assertEquals(false, instance.isActive());
546N/A }
546N/A
546N/A /**
546N/A * Test of setMessage method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setMessage() {
546N/A String message = "Something";
546N/A instance.setMessage(message);
546N/A assertEquals(message, instance.getMessage());
546N/A }
546N/A
546N/A /**
546N/A * Test of setRevision method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setRevision() {
546N/A String revision = "1.2";
546N/A instance.setRevision(revision);
546N/A assertEquals(revision, instance.getRevision());
546N/A }
546N/A
546N/A /**
546N/A * Test of appendMessage method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void appendMessage() {
546N/A String message = "Something Added";
546N/A instance.appendMessage(message);
546N/A assertTrue(instance.getMessage().contains(message));
546N/A }
546N/A
546N/A /**
546N/A * Test of addFile method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void addFile() {
546N/A String fileName = "test.file";
546N/A HistoryEntry instance = new HistoryEntry();
900N/A assertFalse(
900N/A new History(Collections.singletonList(instance)).hasFileList());
546N/A instance.addFile(fileName);
546N/A assertTrue(instance.getFiles().contains(fileName));
900N/A assertTrue(
900N/A new History(Collections.singletonList(instance)).hasFileList());
546N/A }
546N/A
546N/A /**
546N/A * Test of getFiles method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void getFiles() {
546N/A String fileName = "test.file";
546N/A instance.addFile(fileName);
546N/A assertTrue(instance.getFiles().contains(fileName));
546N/A assertEquals(1, instance.getFiles().size());
546N/A instance.addFile("other.file");
546N/A assertEquals(2, instance.getFiles().size());
546N/A }
546N/A
546N/A /**
546N/A * Test of setFiles method, of class HistoryEntry.
546N/A */
546N/A @Test
1072N/A public void setFiles() {
802N/A TreeSet<String> files = new TreeSet<String>();
546N/A files.add("file1.file");
546N/A files.add("file2.file");
546N/A instance.setFiles(files);
546N/A assertEquals(2, instance.getFiles().size());
546N/A }
546N/A
546N/A /**
546N/A * Test of toString method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void testToString() {
546N/A assertTrue(instance.toString().contains(historyRevision));
546N/A assertTrue(instance.toString().contains(historyAuthor));
546N/A }
546N/A
546N/A /**
546N/A * Test of addChangeRequest method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void addGetChangeRequest() {
546N/A String changeRequest = "Change Request";
546N/A assertEquals(0, instance.getChangeRequests().size());
546N/A instance.addChangeRequest(changeRequest);
546N/A assertEquals(1, instance.getChangeRequests().size());
546N/A assertTrue(instance.getChangeRequests().contains(changeRequest));
546N/A }
546N/A
546N/A /**
546N/A * Test of setChangeRequests method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void setChangeRequests() {
546N/A List<String> changeRequests = new ArrayList<String>();
546N/A changeRequests.add("CR1");
546N/A changeRequests.add("CR2");
546N/A instance.setChangeRequests(changeRequests);
546N/A assertEquals(2, instance.getChangeRequests().size());
546N/A }
546N/A
546N/A /**
546N/A * Test of strip method, of class HistoryEntry.
546N/A */
546N/A @Test
546N/A public void strip() {
802N/A TreeSet<String> files = new TreeSet<String>();
546N/A files.add("file1.file");
546N/A files.add("file2.file");
546N/A instance.setFiles(files);
546N/A instance.strip();
546N/A assertEquals(0, instance.getFiles().size());
546N/A }
546N/A
1024N/A}