1 /* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 * express or implied. See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 package com.google.common.collect; 16 17 import com.google.common.annotations.GwtCompatible; 18 import com.google.common.collect.BstTesting.SimpleNode; 19 20 import junit.framework.TestCase; 21 22 /** 23 * Simple tests for {@code BstPath}. 24 * 25 * @author Louis Wasserman 26 */ 27 @GwtCompatible 28 public class BstPathTest extends TestCase { 29 static class SimplePath extends BstPath<SimpleNode, SimplePath> { SimplePath(SimpleNode tip, SimplePath tail)30 private SimplePath(SimpleNode tip, SimplePath tail) { 31 super(tip, tail); 32 } 33 } 34 testTailAtRoot()35 public void testTailAtRoot() { 36 SimpleNode root = new SimpleNode('a', null, null); 37 SimplePath rootPath = new SimplePath(root, null); 38 assertFalse(rootPath.hasPrefix()); 39 assertNull(rootPath.prefixOrNull()); 40 try { 41 rootPath.getPrefix(); 42 fail("Expected IllegalStateException"); 43 } catch (IllegalStateException expected) {} 44 } 45 testTailDown()46 public void testTailDown() { 47 SimpleNode node = new SimpleNode('a', null, null); 48 SimpleNode root = new SimpleNode('b', node, null); 49 SimplePath rootPath = new SimplePath(root, null); 50 SimplePath nodePath = new SimplePath(node, rootPath); 51 assertTrue(nodePath.hasPrefix()); 52 assertEquals(rootPath, nodePath.prefixOrNull()); 53 assertEquals(rootPath, nodePath.getPrefix()); 54 } 55 } 56