Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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. |
| 14 | package com.google.devtools.build.lib.vfs; |
| 15 | |
| 16 | import com.google.common.testing.EqualsTester; |
philwo | 3bcb9f6 | 2017-09-06 12:52:21 +0200 | [diff] [blame] | 17 | import com.google.devtools.build.lib.clock.BlazeClock; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | import org.junit.runners.JUnit4; |
| 23 | |
| 24 | /** |
| 25 | * Tests for {@link RootedPath}. |
| 26 | */ |
| 27 | @RunWith(JUnit4.class) |
| 28 | public class RootedPathTest { |
| 29 | private FileSystem filesystem; |
| 30 | private Path root; |
| 31 | |
| 32 | @Before |
Florian Weikert | 99ac0a2 | 2015-12-01 15:05:35 +0000 | [diff] [blame] | 33 | public final void initializeFileSystem() throws Exception { |
ccalvarin | c9efd06 | 2018-07-27 12:46:46 -0700 | [diff] [blame] | 34 | filesystem = new InMemoryFileSystem(BlazeClock.instance()); |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 35 | root = filesystem.getPath("/"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | @Test |
| 39 | public void testEqualsAndHashCodeContract() throws Exception { |
| 40 | Path pkgRoot1 = root.getRelative("pkgroot1"); |
| 41 | Path pkgRoot2 = root.getRelative("pkgroot2"); |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 42 | 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")); |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 46 | RootedPath absolutePath1 = |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 47 | 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")); |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 52 | RootedPath absolutePath2 = |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 53 | RootedPath.toRootedPath(Root.fromPath(root), PathFragment.create("pkgroot2/foo/bar")); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | new EqualsTester() |
| 55 | .addEqualityGroup(rootedPathA1, rootedPathA2) |
| 56 | .addEqualityGroup(rootedPathB1, rootedPathB2) |
| 57 | .addEqualityGroup(absolutePath1) |
| 58 | .addEqualityGroup(absolutePath2) |
| 59 | .testEquals(); |
| 60 | } |
| 61 | } |