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