Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Bazel Authors. 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. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableList; |
| 17 | import com.google.common.testing.EqualsTester; |
| 18 | import com.google.devtools.build.lib.vfs.Path; |
| 19 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 20 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 21 | import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; |
| 22 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 23 | import org.junit.Test; |
| 24 | import org.junit.runner.RunWith; |
| 25 | import org.junit.runners.JUnit4; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 26 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 27 | @RunWith(JUnit4.class) |
| 28 | public class FileSymlinkCycleUniquenessFunctionTest { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 29 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 30 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 31 | public void testHashCodeAndEqualsContract() throws Exception { |
| 32 | Path root = new InMemoryFileSystem().getRootDirectory().getRelative("root"); |
| 33 | RootedPath p1 = RootedPath.toRootedPath(root, new PathFragment("p1")); |
| 34 | RootedPath p2 = RootedPath.toRootedPath(root, new PathFragment("p2")); |
| 35 | RootedPath p3 = RootedPath.toRootedPath(root, new PathFragment("p3")); |
| 36 | ImmutableList<RootedPath> cycleA1 = ImmutableList.of(p1); |
| 37 | ImmutableList<RootedPath> cycleB1 = ImmutableList.of(p2); |
| 38 | ImmutableList<RootedPath> cycleC1 = ImmutableList.of(p1, p2, p3); |
| 39 | ImmutableList<RootedPath> cycleC2 = ImmutableList.of(p2, p3, p1); |
| 40 | ImmutableList<RootedPath> cycleC3 = ImmutableList.of(p3, p1, p2); |
| 41 | new EqualsTester() |
| 42 | .addEqualityGroup(FileSymlinkCycleUniquenessFunction.key(cycleA1)) |
| 43 | .addEqualityGroup(FileSymlinkCycleUniquenessFunction.key(cycleB1)) |
| 44 | .addEqualityGroup( |
| 45 | FileSymlinkCycleUniquenessFunction.key(cycleC1), |
| 46 | FileSymlinkCycleUniquenessFunction.key(cycleC2), |
| 47 | FileSymlinkCycleUniquenessFunction.key(cycleC3)) |
| 48 | .testEquals(); |
| 49 | } |
| 50 | } |