DefinitionsTest.java revision 1108
2026N/A/*
2026N/A * CDDL HEADER START
3427N/A *
3427N/A * The contents of this file are subject to the terms of the
2383N/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.
3427N/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 2010 Sun Microsystems, Inc. All rights reserved.
2026N/A * Use is subject to license terms.
2026N/A */
3427N/A
3427N/Apackage org.opensolaris.opengrok.analysis;
2026N/A
2026N/Aimport java.util.Set;
2026N/Aimport org.junit.After;
2026N/Aimport org.junit.AfterClass;
2026N/Aimport org.junit.Before;
2026N/Aimport org.junit.BeforeClass;
2026N/Aimport org.junit.Test;
2026N/Aimport static org.junit.Assert.*;
2026N/A
2026N/A/**
*
* @author austvik
*/
public class DefinitionsTest {
public DefinitionsTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getSymbols method, of class Definitions.
*/
@Test
public void getSymbols() {
Definitions instance = new Definitions();
Set<String> result = instance.getSymbols();
assertNotNull(result);
assertEquals(result.size(), 0);
instance.addTag(1, "found", "", "");
result = instance.getSymbols();
assertNotNull(result);
assertEquals(result.size(), 1);
}
/**
* Test of hasSymbol method, of class Definitions.
*/
@Test
public void hasSymbol() {
Definitions instance = new Definitions();
instance.addTag(1, "found", "", "");
assertEquals(instance.hasSymbol("notFound"), false);
assertEquals(instance.hasSymbol("found"), true);
}
/**
* Test of hasDefinitionAt method, of class Definitions.
*/
@Test
public void hasDefinitionAt() {
Definitions instance = new Definitions();
String[] type= new String[1];
type[0]="";
instance.addTag(1, "found", "", "");
assertEquals(instance.hasDefinitionAt("found", 0, type), false);
assertEquals(instance.hasDefinitionAt("found", 1, type), true);
assertEquals(instance.hasDefinitionAt("found", 2, type), false);
assertEquals(instance.hasDefinitionAt("notFound", 0, type), false);
assertEquals(instance.hasDefinitionAt("notFound", 1, type), false);
}
/**
* Test of occurrences method, of class Definitions.
*/
@Test
public void occurrences() {
Definitions instance = new Definitions();
instance.addTag(1, "one", "", "");
instance.addTag(1, "two", "", "");
instance.addTag(3, "two", "", "");
assertEquals(instance.occurrences("one"), 1);
assertEquals(instance.occurrences("two"), 2);
assertEquals(instance.occurrences("notFound"), 0);
}
/**
* Test of numberOfSymbols method, of class Definitions.
*/
@Test
public void numberOfSymbols() {
Definitions instance = new Definitions();
assertEquals(instance.numberOfSymbols(), 0);
instance.addTag(1, "one", "", "");
assertEquals(instance.numberOfSymbols(), 1);
instance.addTag(1, "two", "", "");
instance.addTag(3, "two", "", "");
assertEquals(instance.numberOfSymbols(), 2);
}
/**
* Test of getTags method, of class Definitions.
*/
@Test
public void getTags() {
Definitions instance = new Definitions();
assertEquals(instance.getTags().size(), 0);
instance.addTag(1, "one", "", "");
assertEquals(instance.getTags().size(), 1);
instance.addTag(1, "two", "", "");
assertEquals(instance.getTags().size(), 2);
instance.addTag(3, "two", "", "");
assertEquals(instance.getTags().size(), 3);
}
/**
* Test of addTag method, of class Definitions.
*/
@Test
public void addTag() {
Definitions instance = new Definitions();
assertEquals(instance.getTags().size(), 0);
instance.addTag(1, "one", "", "");
assertEquals(instance.getTags().size(), 1);
}
/**
* Test of serialize method, of class Definitions.
*/
@Test
public void serialize() throws Exception {
Definitions instance = new Definitions();
instance.addTag(1, "one", "", "");
byte serial[] = instance.serialize();
Definitions instance2 = Definitions.deserialize(serial);
assertEquals(instance.getTags().size(), instance2.getTags().size());
assertEquals(instance.getSymbols().size(), instance2.getSymbols().size());
}
}