HitTest.java revision 511
511N/A/*
511N/A * CDDL HEADER START
511N/A *
511N/A * The contents of this file are subject to the terms of the
511N/A * Common Development and Distribution License (the "License").
511N/A * You may not use this file except in compliance with the License.
511N/A *
511N/A * See LICENSE.txt included in this distribution for the specific
511N/A * language governing permissions and limitations under the License.
511N/A *
511N/A * When distributing Covered Code, include this CDDL HEADER in each
511N/A * file and include the License file at LICENSE.txt.
511N/A * If applicable, add the following below this CDDL HEADER, with the
511N/A * fields enclosed by brackets "[]" replaced with your own identifying
511N/A * information: Portions Copyright [yyyy] [name of copyright owner]
511N/A *
511N/A * CDDL HEADER END
511N/A */
511N/A
511N/A/*
511N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
511N/A * Use is subject to license terms.
511N/A */
511N/Apackage org.opensolaris.opengrok.search;
511N/A
511N/Aimport org.junit.Test;
511N/Aimport static org.junit.Assert.*;
511N/A
511N/A/**
511N/A * Do basic sanity testing of the Hit class
511N/A *
511N/A * @author Trond Norbye
511N/A */
511N/Apublic class HitTest {
511N/A
511N/A @Test
511N/A public void testFilename() {
511N/A Hit instance = new Hit();
511N/A assertNull(instance.getFilename());
511N/A String expResult = "foobar";
511N/A instance.setFilename(expResult);
511N/A assertEquals(expResult, instance.getFilename());
511N/A }
511N/A
511N/A @Test
511N/A public void testPath() {
511N/A Hit instance = new Hit("/foo/bar", null, null, false, false);
511N/A assertEquals("/foo/bar", instance.getPath());
511N/A assertEquals("/foo", instance.getDirectory());
511N/A }
511N/A
511N/A @Test
511N/A public void testLine() {
511N/A Hit instance = new Hit();
511N/A assertNull(instance.getLine());
511N/A String expResult = "This is a line of text";
511N/A instance.setLine(expResult);
511N/A assertEquals(expResult, instance.getLine());
511N/A }
511N/A
511N/A @Test
511N/A public void testLineno() {
511N/A Hit instance = new Hit();
511N/A assertNull(instance.getLineno());
511N/A String expResult = "12";
511N/A instance.setLineno(expResult);
511N/A assertEquals(expResult, instance.getLineno());
511N/A }
511N/A
511N/A @Test
511N/A public void testCompareTo() {
511N/A Hit o1 = new Hit("/foo", null, null, false, false);
511N/A Hit o2 = new Hit("/foo", "hi", "there", false, false);
511N/A assertEquals(o2.compareTo(o1), o1.compareTo(o2));
511N/A o1.setFilename("bar");
511N/A assertFalse(o2.compareTo(o1) == o1.compareTo(o2));
511N/A }
511N/A
511N/A @Test
511N/A public void testBinary() {
511N/A Hit instance = new Hit();
511N/A assertFalse(instance.isBinary());
511N/A instance.setBinary(true);
511N/A assertTrue(instance.isBinary());
511N/A }
511N/A
511N/A @Test
511N/A public void testTag() {
511N/A Hit instance = new Hit();
511N/A assertNull(instance.getTag());
511N/A String expResult = "foobar";
511N/A instance.setTag(expResult);
511N/A assertEquals(expResult, instance.getTag());
511N/A }
511N/A
511N/A
511N/A @Test
511N/A public void testAlt() {
511N/A Hit instance = new Hit();
511N/A assertFalse(instance.getAlt());
511N/A Hit o2 = new Hit(null, null, null, false, true);
511N/A assertTrue(o2.getAlt());
511N/A }
511N/A
511N/A @Test
511N/A public void testEquals() {
511N/A Hit o1 = new Hit("/foo", null, null, false, false);
511N/A Hit o2 = new Hit("/foo", "hi", "there", false, false);
511N/A assertEquals(o2.equals(o1), o1.equals(o2));
511N/A o1.setFilename("bar");
511N/A assertFalse(o2.equals(o1));
511N/A assertFalse(o1.equals(o2));
511N/A }
511N/A
511N/A @Test
511N/A public void testHashCode() {
511N/A String filename = "bar";
511N/A Hit instance = new Hit(filename, null, null, false, false);
511N/A assertEquals(filename.hashCode(), instance.hashCode());
511N/A }
511N/A}