blob: 49414a95ead7497e949faf4afa46afbb73ff280f [file] [log] [blame]
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +00001// 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.
14package com.google.devtools.build.lib.skyframe;
15
16import com.google.common.collect.ImmutableList;
17import com.google.common.testing.EqualsTester;
18import com.google.devtools.build.lib.vfs.Path;
19import com.google.devtools.build.lib.vfs.PathFragment;
20import com.google.devtools.build.lib.vfs.RootedPath;
21import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
22
Han-Wen Nienhuys3b2eae32015-10-28 16:35:08 +000023import org.junit.Test;
24import org.junit.runner.RunWith;
25import org.junit.runners.JUnit4;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000026
Han-Wen Nienhuys3b2eae32015-10-28 16:35:08 +000027@RunWith(JUnit4.class)
28public class FileSymlinkCycleUniquenessFunctionTest {
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000029
Han-Wen Nienhuys3b2eae32015-10-28 16:35:08 +000030 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000031 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}