647N/A/*
647N/A * CDDL HEADER START
647N/A *
647N/A * The contents of this file are subject to the terms of the
647N/A * Common Development and Distribution License (the "License").
647N/A * You may not use this file except in compliance with the License.
647N/A *
647N/A * See LICENSE.txt included in this distribution for the specific
647N/A * language governing permissions and limitations under the License.
647N/A *
647N/A * When distributing Covered Code, include this CDDL HEADER in each
647N/A * file and include the License file at LICENSE.txt.
647N/A * If applicable, add the following below this CDDL HEADER, with the
647N/A * fields enclosed by brackets "[]" replaced with your own identifying
647N/A * information: Portions Copyright [yyyy] [name of copyright owner]
647N/A *
647N/A * CDDL HEADER END
647N/A */
647N/A
647N/A/*
647N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
647N/A * Use is subject to license terms.
647N/A */
647N/Apackage org.opensolaris.opengrok.history;
647N/A
1473N/Aimport static org.junit.Assert.assertEquals;
1473N/Aimport static org.junit.Assert.assertNotNull;
1473N/Aimport static org.junit.Assert.assertTrue;
1473N/A
647N/Aimport java.io.Reader;
647N/Aimport java.io.StringReader;
1473N/Aimport java.lang.reflect.Method;
1473N/A
647N/Aimport org.junit.After;
647N/Aimport org.junit.Before;
647N/Aimport org.junit.Test;
647N/A
647N/A/**
647N/A * @author austvik
647N/A */
647N/Apublic class GitRepositoryTest {
647N/A
647N/A GitRepository instance;
647N/A
1473N/A @SuppressWarnings("javadoc")
647N/A @Before
647N/A public void setUp() {
647N/A instance = new GitRepository();
647N/A }
647N/A
1473N/A @SuppressWarnings("javadoc")
647N/A @After
647N/A public void tearDown() {
647N/A instance = null;
647N/A }
647N/A
647N/A /**
647N/A * Test of parseAnnotation method, of class GitRepository.
1473N/A * @throws Exception
647N/A */
647N/A @Test
647N/A public void parseAnnotation() throws Exception {
647N/A String revId1 = "cd283405560689372626a69d5331c467bce71656";
647N/A String revId2 = "30ae764b12039348766291100308556675ca11ab";
647N/A String revId3 = "2394823984cde2390345435a9237bd7c25932342";
647N/A String author1 = "Author Name";
647N/A String author2 = "Author With Long Name";
647N/A String author3 = "Author Named Jr.";
647N/A String output = revId1 + " file1.ext (" + author1 + " 2005-06-06 16:38:26 -0400 272) \n" +
647N/A revId2 + " file2.h (" + author2 + " 2007-09-10 23:02:45 -0400 273) if (some code)\n" +
647N/A revId3 + " file2.c (" + author3 + " 2006-09-20 21:47:42 -0700 274) call_function(i);\n";
647N/A Reader input = new StringReader(output);
647N/A String fileName = "something.ext";
1473N/A Method method = instance.getClass()
1473N/A .getDeclaredMethod("parseAnnotation", Reader.class, String.class);
1473N/A method.setAccessible(true);
1473N/A Annotation result = (Annotation) method.invoke(instance, input, fileName);
647N/A assertNotNull(result);
647N/A assertEquals(3, result.size());
647N/A assertEquals(revId1, result.getRevision(1));
647N/A assertEquals(revId2, result.getRevision(2));
647N/A assertEquals(revId3, result.getRevision(3));
647N/A assertEquals(author1, result.getAuthor(1));
647N/A assertEquals(author2, result.getAuthor(2));
647N/A assertEquals(author3, result.getAuthor(3));
647N/A assertEquals(author2.length(), result.getWidestAuthor());
647N/A assertEquals(revId1.length(), result.getWidestRevision());
647N/A assertEquals(fileName, result.getFilename());
647N/A }
647N/A
647N/A /**
647N/A * Test of fileHasAnnotation method, of class GitRepository.
647N/A */
647N/A @Test
647N/A public void fileHasAnnotation() {
647N/A boolean result = instance.fileHasAnnotation(null);
647N/A assertTrue(result);
647N/A }
647N/A
647N/A /**
647N/A * Test of fileHasHistory method, of class GitRepository.
647N/A */
647N/A @Test
647N/A public void fileHasHistory() {
647N/A boolean result = instance.fileHasHistory(null);
647N/A assertTrue(result);
647N/A }
647N/A
1024N/A}