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