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