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.collect.ImmutableList; |
| 17 | import com.google.common.testing.EqualsTester; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
| 21 | import org.junit.runners.JUnit4; |
| 22 | |
| 23 | /** |
| 24 | * Tests for {@link ModifiedFileSet}. |
| 25 | */ |
| 26 | @RunWith(JUnit4.class) |
| 27 | public 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 | } |