blob: 07eedbeded15d5ee08b66065a7c3099955f7455b [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.collect.ImmutableList;
17import com.google.common.testing.EqualsTester;
18
19import org.junit.Test;
20import org.junit.runner.RunWith;
21import org.junit.runners.JUnit4;
22
23/**
24 * Tests for {@link ModifiedFileSet}.
25 */
26@RunWith(JUnit4.class)
27public class ModifiedFileSetTest {
28
29 @Test
30 public void testHashCodeAndEqualsContract() throws Exception {
31 PathFragment fragA = new PathFragment("a");
32 PathFragment fragB = new PathFragment("b");
33
34 ModifiedFileSet empty1 = ModifiedFileSet.NOTHING_MODIFIED;
35 ModifiedFileSet empty2 = ModifiedFileSet.builder().build();
36 ModifiedFileSet empty3 = ModifiedFileSet.builder().modifyAll(
37 ImmutableList.<PathFragment>of()).build();
38
39 ModifiedFileSet nonEmpty1 = ModifiedFileSet.builder().modifyAll(
40 ImmutableList.of(fragA, fragB)).build();
41 ModifiedFileSet nonEmpty2 = ModifiedFileSet.builder().modifyAll(
42 ImmutableList.of(fragB, fragA)).build();
43 ModifiedFileSet nonEmpty3 = ModifiedFileSet.builder().modify(fragA).modify(fragB).build();
44 ModifiedFileSet nonEmpty4 = ModifiedFileSet.builder().modify(fragB).modify(fragA).build();
45
46 ModifiedFileSet everythingModified = ModifiedFileSet.EVERYTHING_MODIFIED;
47
48 new EqualsTester()
49 .addEqualityGroup(empty1, empty2, empty3)
50 .addEqualityGroup(nonEmpty1, nonEmpty2, nonEmpty3, nonEmpty4)
51 .addEqualityGroup(everythingModified)
52 .testEquals();
53 }
54}