blob: 6f452c2fcbe8f9ac5c6c883b81adf20db3a50e8f [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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;
philwo3bcb9f62017-09-06 12:52:21 +020017import com.google.devtools.build.lib.clock.BlazeClock;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010018import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010019import org.junit.Before;
20import org.junit.Test;
21import org.junit.runner.RunWith;
22import org.junit.runners.JUnit4;
23
24/**
25 * Tests for {@link RootedPath}.
26 */
27@RunWith(JUnit4.class)
28public class RootedPathTest {
29 private FileSystem filesystem;
30 private Path root;
31
32 @Before
Florian Weikert99ac0a22015-12-01 15:05:35 +000033 public final void initializeFileSystem() throws Exception {
ccalvarinc9efd062018-07-27 12:46:46 -070034 filesystem = new InMemoryFileSystem(BlazeClock.instance());
tomluee6a6862018-01-17 14:36:26 -080035 root = filesystem.getPath("/");
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010036 }
37
38 @Test
39 public void testEqualsAndHashCodeContract() throws Exception {
40 Path pkgRoot1 = root.getRelative("pkgroot1");
41 Path pkgRoot2 = root.getRelative("pkgroot2");
tomluee6a6862018-01-17 14:36:26 -080042 RootedPath rootedPathA1 =
43 RootedPath.toRootedPath(Root.fromPath(pkgRoot1), PathFragment.create("foo/bar"));
44 RootedPath rootedPathA2 =
45 RootedPath.toRootedPath(Root.fromPath(pkgRoot1), PathFragment.create("foo/bar"));
nharmatab4060b62017-04-04 17:11:39 +000046 RootedPath absolutePath1 =
tomluee6a6862018-01-17 14:36:26 -080047 RootedPath.toRootedPath(Root.fromPath(root), PathFragment.create("pkgroot1/foo/bar"));
48 RootedPath rootedPathB1 =
49 RootedPath.toRootedPath(Root.fromPath(pkgRoot2), PathFragment.create("foo/bar"));
50 RootedPath rootedPathB2 =
51 RootedPath.toRootedPath(Root.fromPath(pkgRoot2), PathFragment.create("foo/bar"));
nharmatab4060b62017-04-04 17:11:39 +000052 RootedPath absolutePath2 =
tomluee6a6862018-01-17 14:36:26 -080053 RootedPath.toRootedPath(Root.fromPath(root), PathFragment.create("pkgroot2/foo/bar"));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010054 new EqualsTester()
55 .addEqualityGroup(rootedPathA1, rootedPathA2)
56 .addEqualityGroup(rootedPathB1, rootedPathB2)
57 .addEqualityGroup(absolutePath1)
58 .addEqualityGroup(absolutePath2)
59 .testEquals();
60 }
61}