blob: 46d286dcdc4ac5438a38d76832f8d0b175844496 [file] [log] [blame]
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01001// Copyright 2014 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// 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
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.vfs;
15
16import com.google.common.testing.EqualsTester;
17import com.google.devtools.build.lib.util.BlazeClock;
18import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
19
20import org.junit.Before;
21import org.junit.Test;
22import org.junit.runner.RunWith;
23import org.junit.runners.JUnit4;
24
25/**
26 * Tests for {@link RootedPath}.
27 */
28@RunWith(JUnit4.class)
29public class RootedPathTest {
30 private FileSystem filesystem;
31 private Path root;
32
33 @Before
34 public void setUp() throws Exception {
35 filesystem = new InMemoryFileSystem(BlazeClock.instance());
36 root = filesystem.getRootDirectory();
37 }
38
39 @Test
40 public void testEqualsAndHashCodeContract() throws Exception {
41 Path pkgRoot1 = root.getRelative("pkgroot1");
42 Path pkgRoot2 = root.getRelative("pkgroot2");
43 RootedPath rootedPathA1 = RootedPath.toRootedPath(pkgRoot1, new PathFragment("foo/bar"));
44 RootedPath rootedPathA2 = RootedPath.toRootedPath(pkgRoot1, new PathFragment("foo/bar"));
45 RootedPath absolutePath1 = RootedPath.toRootedPath(root, new PathFragment("pkgroot1/foo/bar"));
46 RootedPath rootedPathB1 = RootedPath.toRootedPath(pkgRoot2, new PathFragment("foo/bar"));
47 RootedPath rootedPathB2 = RootedPath.toRootedPath(pkgRoot2, new PathFragment("foo/bar"));
48 RootedPath absolutePath2 = RootedPath.toRootedPath(root, new PathFragment("pkgroot2/foo/bar"));
49 new EqualsTester()
50 .addEqualityGroup(rootedPathA1, rootedPathA2)
51 .addEqualityGroup(rootedPathB1, rootedPathB2)
52 .addEqualityGroup(absolutePath1)
53 .addEqualityGroup(absolutePath2)
54 .testEquals();
55 }
56}