Michael Staib | 5e573fd | 2016-01-27 00:33:29 +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.analysis; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
| 17 | import static org.junit.Assert.fail; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.testing.EqualsTester; |
| 22 | import com.google.common.testing.NullPointerTester; |
| 23 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 24 | import com.google.devtools.build.lib.analysis.config.HostTransition; |
gregce | 7fa23ea | 2018-01-18 12:46:04 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.analysis.config.transitions.NoTransition; |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.lib.analysis.util.AnalysisTestCase; |
| 27 | import com.google.devtools.build.lib.analysis.util.TestAspects; |
| 28 | import com.google.devtools.build.lib.cmdline.Label; |
Dmitry Lomov | 1575652 | 2016-12-16 16:52:37 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.lib.packages.AspectDescriptor; |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
| 32 | import org.junit.runners.JUnit4; |
| 33 | |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 34 | /** |
| 35 | * Tests for {@link Dependency}. |
| 36 | * |
| 37 | * <p>Although this is just a data class, we need a way to create a configuration. |
| 38 | */ |
| 39 | @RunWith(JUnit4.class) |
| 40 | public class DependencyTest extends AnalysisTestCase { |
| 41 | @Test |
| 42 | public void withNullConfiguration_BasicAccessors() throws Exception { |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 43 | Dependency nullDep = |
| 44 | Dependency.withNullConfiguration(Label.parseAbsolute("//a", ImmutableMap.of())); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 45 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 46 | assertThat(nullDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of())); |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 47 | assertThat(nullDep.hasExplicitConfiguration()).isTrue(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 48 | assertThat(nullDep.getConfiguration()).isNull(); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 49 | assertThat(nullDep.getAspects().getAllAspects()).isEmpty(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 50 | |
| 51 | try { |
| 52 | nullDep.getTransition(); |
| 53 | fail("withNullConfiguration-created Dependencies should throw ISE on getTransition()"); |
| 54 | } catch (IllegalStateException ex) { |
| 55 | // good. expected. |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void withConfiguration_BasicAccessors() throws Exception { |
| 61 | update(); |
| 62 | Dependency targetDep = |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 63 | Dependency.withConfiguration( |
| 64 | Label.parseAbsolute("//a", ImmutableMap.of()), getTargetConfiguration()); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 65 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 66 | assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of())); |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 67 | assertThat(targetDep.hasExplicitConfiguration()).isTrue(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 68 | assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration()); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 69 | assertThat(targetDep.getAspects().getAllAspects()).isEmpty(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 70 | |
| 71 | try { |
| 72 | targetDep.getTransition(); |
| 73 | fail("withConfiguration-created Dependencies should throw ISE on getTransition()"); |
| 74 | } catch (IllegalStateException ex) { |
| 75 | // good. expected. |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void withConfigurationAndAspects_BasicAccessors() throws Exception { |
| 81 | update(); |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 82 | AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); |
| 83 | AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 84 | AspectCollection twoAspects = AspectCollection.createForTests( |
| 85 | ImmutableSet.of(simpleAspect, attributeAspect)); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 86 | Dependency targetDep = |
| 87 | Dependency.withConfigurationAndAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 88 | Label.parseAbsolute("//a", ImmutableMap.of()), getTargetConfiguration(), twoAspects); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 89 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 90 | assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of())); |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 91 | assertThat(targetDep.hasExplicitConfiguration()).isTrue(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 92 | assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration()); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 93 | assertThat(targetDep.getAspects()).isEqualTo(twoAspects); |
| 94 | assertThat(targetDep.getAspectConfiguration(simpleAspect)).isEqualTo(getTargetConfiguration()); |
| 95 | assertThat(targetDep.getAspectConfiguration(attributeAspect)) |
| 96 | .isEqualTo(getTargetConfiguration()); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 97 | |
| 98 | try { |
| 99 | targetDep.getTransition(); |
| 100 | fail("withConfigurationAndAspects-created Dependencies should throw ISE on getTransition()"); |
| 101 | } catch (IllegalStateException ex) { |
| 102 | // good. that's what I WANTED to happen. |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | @Test |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 107 | public void withConfigurationAndAspects_RejectsNullConfigWithNPE() throws Exception { |
| 108 | // Although the NullPointerTester should check this, this test invokes a different code path, |
| 109 | // because it includes aspects (which the NPT test will not). |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 110 | AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); |
| 111 | AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 112 | AspectCollection twoAspects = AspectCollection.createForTests(simpleAspect, attributeAspect); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 113 | |
| 114 | try { |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 115 | Dependency.withConfigurationAndAspects( |
| 116 | Label.parseAbsolute("//a", ImmutableMap.of()), null, twoAspects); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 117 | fail("should not be allowed to create a dependency with a null configuration"); |
| 118 | } catch (NullPointerException expected) { |
| 119 | // good. you fell rrrrright into my trap. |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void withConfigurationAndAspects_AllowsEmptyAspectSet() throws Exception { |
| 125 | update(); |
| 126 | Dependency dep = |
| 127 | Dependency.withConfigurationAndAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 128 | Label.parseAbsolute("//a", ImmutableMap.of()), |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 129 | getTargetConfiguration(), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 130 | AspectCollection.EMPTY); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 131 | // Here we're also checking that this doesn't throw an exception. No boom? OK. Good. |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 132 | assertThat(dep.getAspects().getAllAspects()).isEmpty(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Test |
| 136 | public void withConfiguredAspects_BasicAccessors() throws Exception { |
| 137 | update(); |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 138 | AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); |
| 139 | AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 140 | AspectCollection aspects = |
| 141 | AspectCollection.createForTests(ImmutableSet.of(simpleAspect, attributeAspect)); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 142 | ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectMap = ImmutableMap.of( |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 143 | simpleAspect, getTargetConfiguration(), attributeAspect, getHostConfiguration()); |
| 144 | Dependency targetDep = |
| 145 | Dependency.withConfiguredAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 146 | Label.parseAbsolute("//a", ImmutableMap.of()), |
| 147 | getTargetConfiguration(), |
| 148 | aspects, |
| 149 | twoAspectMap); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 150 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 151 | assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of())); |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 152 | assertThat(targetDep.hasExplicitConfiguration()).isTrue(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 153 | assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration()); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 154 | assertThat(targetDep.getAspects().getAllAspects()) |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 155 | .containsExactly(simpleAspect, attributeAspect); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 156 | assertThat(targetDep.getAspectConfiguration(simpleAspect)).isEqualTo(getTargetConfiguration()); |
| 157 | assertThat(targetDep.getAspectConfiguration(attributeAspect)) |
| 158 | .isEqualTo(getHostConfiguration()); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 159 | |
| 160 | try { |
| 161 | targetDep.getTransition(); |
| 162 | fail("withConfiguredAspects-created Dependencies should throw ISE on getTransition()"); |
| 163 | } catch (IllegalStateException ex) { |
| 164 | // good. all according to keikaku. (TL note: keikaku means plan) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | |
| 169 | @Test |
| 170 | public void withConfiguredAspects_AllowsEmptyAspectMap() throws Exception { |
| 171 | update(); |
| 172 | Dependency dep = |
| 173 | Dependency.withConfiguredAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 174 | Label.parseAbsolute("//a", ImmutableMap.of()), |
| 175 | getTargetConfiguration(), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 176 | AspectCollection.EMPTY, |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 177 | ImmutableMap.<AspectDescriptor, BuildConfiguration>of()); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 178 | // Here we're also checking that this doesn't throw an exception. No boom? OK. Good. |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 179 | assertThat(dep.getAspects().getAllAspects()).isEmpty(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | @Test |
| 183 | public void withTransitionAndAspects_BasicAccessors() throws Exception { |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 184 | AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); |
| 185 | AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 186 | AspectCollection twoAspects = AspectCollection.createForTests( |
| 187 | ImmutableSet.of(simpleAspect, attributeAspect)); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 188 | Dependency hostDep = |
| 189 | Dependency.withTransitionAndAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 190 | Label.parseAbsolute("//a", ImmutableMap.of()), HostTransition.INSTANCE, twoAspects); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 191 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 192 | assertThat(hostDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of())); |
gregce | e0bbe75 | 2017-09-12 23:58:34 +0200 | [diff] [blame] | 193 | assertThat(hostDep.hasExplicitConfiguration()).isFalse(); |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 194 | assertThat(hostDep.getAspects().getAllAspects()) |
| 195 | .containsExactlyElementsIn(twoAspects.getAllAspects()); |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 196 | assertThat(hostDep.getTransition().isHostTransition()).isTrue(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 197 | |
| 198 | try { |
| 199 | hostDep.getConfiguration(); |
| 200 | fail("withTransitionAndAspects-created Dependencies should throw ISE on getConfiguration()"); |
| 201 | } catch (IllegalStateException ex) { |
| 202 | // good. I knew you would do that. |
| 203 | } |
| 204 | |
| 205 | try { |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 206 | hostDep.getAspectConfiguration(simpleAspect); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 207 | fail("withTransitionAndAspects-created Dependencies should throw ISE on " |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 208 | + "getAspectConfiguration()"); |
| 209 | } catch (IllegalStateException ex) { |
| 210 | // good. you're so predictable. |
| 211 | } |
| 212 | |
| 213 | try { |
| 214 | hostDep.getAspectConfiguration(attributeAspect); |
| 215 | fail("withTransitionAndAspects-created Dependencies should throw ISE on " |
| 216 | + "getAspectConfiguration()"); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 217 | } catch (IllegalStateException ex) { |
| 218 | // good. you're so predictable. |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | @Test |
| 223 | public void withTransitionAndAspects_AllowsEmptyAspectSet() throws Exception { |
| 224 | update(); |
| 225 | Dependency dep = |
| 226 | Dependency.withTransitionAndAspects( |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 227 | Label.parseAbsolute("//a", ImmutableMap.of()), |
| 228 | HostTransition.INSTANCE, |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 229 | AspectCollection.EMPTY); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 230 | // Here we're also checking that this doesn't throw an exception. No boom? OK. Good. |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 231 | assertThat(dep.getAspects().getAllAspects()).isEmpty(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Test |
| 235 | public void factoriesPassNullableTester() throws Exception { |
| 236 | update(); |
| 237 | |
| 238 | new NullPointerTester() |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 239 | .setDefault(Label.class, Label.parseAbsolute("//a", ImmutableMap.of())) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 240 | .setDefault(BuildConfiguration.class, getTargetConfiguration()) |
| 241 | .testAllPublicStaticMethods(Dependency.class); |
| 242 | } |
| 243 | |
| 244 | @Test |
| 245 | public void equalsPassesEqualsTester() throws Exception { |
| 246 | update(); |
| 247 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame^] | 248 | Label a = Label.parseAbsolute("//a", ImmutableMap.of()); |
| 249 | Label aExplicit = Label.parseAbsolute("//a:a", ImmutableMap.of()); |
| 250 | Label b = Label.parseAbsolute("//b", ImmutableMap.of()); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 251 | |
| 252 | BuildConfiguration host = getHostConfiguration(); |
| 253 | BuildConfiguration target = getTargetConfiguration(); |
| 254 | |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 255 | AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); |
| 256 | AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); |
| 257 | AspectDescriptor errorAspect = new AspectDescriptor(TestAspects.ERROR_ASPECT); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 258 | |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 259 | AspectCollection twoAspects = |
| 260 | AspectCollection.createForTests(simpleAspect, attributeAspect); |
| 261 | AspectCollection inverseAspects = |
| 262 | AspectCollection.createForTests(attributeAspect, simpleAspect); |
| 263 | AspectCollection differentAspects = |
| 264 | AspectCollection.createForTests(attributeAspect, errorAspect); |
| 265 | AspectCollection noAspects = AspectCollection.EMPTY; |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 266 | |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 267 | ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsHostMap = |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 268 | ImmutableMap.of(simpleAspect, host, attributeAspect, host); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 269 | ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsTargetMap = |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 270 | ImmutableMap.of(simpleAspect, target, attributeAspect, target); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 271 | ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsHostMap = |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 272 | ImmutableMap.of(attributeAspect, host, errorAspect, host); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 273 | ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsTargetMap = |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 274 | ImmutableMap.of(attributeAspect, target, errorAspect, target); |
Dmitry Lomov | e804017 | 2016-04-06 14:53:43 +0000 | [diff] [blame] | 275 | ImmutableMap<AspectDescriptor, BuildConfiguration> noAspectsMap = |
| 276 | ImmutableMap.<AspectDescriptor, BuildConfiguration>of(); |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 277 | |
| 278 | new EqualsTester() |
| 279 | .addEqualityGroup( |
| 280 | // base set: //a, host configuration, normal aspect set |
| 281 | Dependency.withConfigurationAndAspects(a, host, twoAspects), |
| 282 | Dependency.withConfigurationAndAspects(aExplicit, host, twoAspects), |
| 283 | Dependency.withConfigurationAndAspects(a, host, inverseAspects), |
| 284 | Dependency.withConfigurationAndAspects(aExplicit, host, inverseAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 285 | Dependency.withConfiguredAspects(a, host, twoAspects, twoAspectsHostMap), |
| 286 | Dependency.withConfiguredAspects(aExplicit, host, twoAspects, twoAspectsHostMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 287 | .addEqualityGroup( |
| 288 | // base set but with label //b |
| 289 | Dependency.withConfigurationAndAspects(b, host, twoAspects), |
| 290 | Dependency.withConfigurationAndAspects(b, host, inverseAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 291 | Dependency.withConfiguredAspects(b, host, twoAspects, twoAspectsHostMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 292 | .addEqualityGroup( |
| 293 | // base set but with target configuration |
| 294 | Dependency.withConfigurationAndAspects(a, target, twoAspects), |
| 295 | Dependency.withConfigurationAndAspects(aExplicit, target, twoAspects), |
| 296 | Dependency.withConfigurationAndAspects(a, target, inverseAspects), |
| 297 | Dependency.withConfigurationAndAspects(aExplicit, target, inverseAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 298 | Dependency.withConfiguredAspects(a, target, twoAspects, twoAspectsTargetMap), |
| 299 | Dependency.withConfiguredAspects(aExplicit, target, twoAspects, twoAspectsTargetMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 300 | .addEqualityGroup( |
| 301 | // base set but with null configuration |
| 302 | Dependency.withNullConfiguration(a), |
| 303 | Dependency.withNullConfiguration(aExplicit)) |
| 304 | .addEqualityGroup( |
| 305 | // base set but with different aspects |
| 306 | Dependency.withConfigurationAndAspects(a, host, differentAspects), |
| 307 | Dependency.withConfigurationAndAspects(aExplicit, host, differentAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 308 | Dependency.withConfiguredAspects( |
| 309 | a, host, differentAspects, differentAspectsHostMap), |
| 310 | Dependency.withConfiguredAspects( |
| 311 | aExplicit, host, differentAspects, differentAspectsHostMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 312 | .addEqualityGroup( |
| 313 | // base set but with label //b and target configuration |
| 314 | Dependency.withConfigurationAndAspects(b, target, twoAspects), |
| 315 | Dependency.withConfigurationAndAspects(b, target, inverseAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 316 | Dependency.withConfiguredAspects(b, target, |
| 317 | twoAspects, twoAspectsTargetMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 318 | .addEqualityGroup( |
| 319 | // base set but with label //b and null configuration |
| 320 | Dependency.withNullConfiguration(b)) |
| 321 | .addEqualityGroup( |
| 322 | // base set but with label //b and different aspects |
| 323 | Dependency.withConfigurationAndAspects(b, host, differentAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 324 | Dependency.withConfiguredAspects( |
| 325 | b, host, differentAspects, differentAspectsHostMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 326 | .addEqualityGroup( |
| 327 | // base set but with target configuration and different aspects |
| 328 | Dependency.withConfigurationAndAspects(a, target, differentAspects), |
| 329 | Dependency.withConfigurationAndAspects(aExplicit, target, differentAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 330 | Dependency.withConfiguredAspects( |
| 331 | a, target, differentAspects, differentAspectsTargetMap), |
| 332 | Dependency.withConfiguredAspects( |
| 333 | aExplicit, target, differentAspects, differentAspectsTargetMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 334 | .addEqualityGroup( |
| 335 | // inverse of base set: //b, target configuration, different aspects |
| 336 | Dependency.withConfigurationAndAspects(b, target, differentAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 337 | Dependency.withConfiguredAspects( |
| 338 | b, target, differentAspects, differentAspectsTargetMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 339 | .addEqualityGroup( |
| 340 | // base set but with no aspects |
| 341 | Dependency.withConfiguration(a, host), |
| 342 | Dependency.withConfiguration(aExplicit, host), |
| 343 | Dependency.withConfigurationAndAspects(a, host, noAspects), |
| 344 | Dependency.withConfigurationAndAspects(aExplicit, host, noAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 345 | Dependency.withConfiguredAspects(a, host, noAspects, noAspectsMap), |
| 346 | Dependency.withConfiguredAspects(aExplicit, host, noAspects, noAspectsMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 347 | .addEqualityGroup( |
| 348 | // base set but with label //b and no aspects |
| 349 | Dependency.withConfiguration(b, host), |
| 350 | Dependency.withConfigurationAndAspects(b, host, noAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 351 | Dependency.withConfiguredAspects(b, host, noAspects, noAspectsMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 352 | .addEqualityGroup( |
| 353 | // base set but with target configuration and no aspects |
| 354 | Dependency.withConfiguration(a, target), |
| 355 | Dependency.withConfiguration(aExplicit, target), |
| 356 | Dependency.withConfigurationAndAspects(a, target, noAspects), |
| 357 | Dependency.withConfigurationAndAspects(aExplicit, target, noAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 358 | Dependency.withConfiguredAspects(a, target, noAspects, noAspectsMap), |
| 359 | Dependency.withConfiguredAspects(aExplicit, target, noAspects, noAspectsMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 360 | .addEqualityGroup( |
| 361 | // inverse of base set: //b, target configuration, no aspects |
| 362 | Dependency.withConfiguration(b, target), |
| 363 | Dependency.withConfigurationAndAspects(b, target, noAspects), |
Dmitry Lomov | e851fe2 | 2017-02-14 23:11:23 +0000 | [diff] [blame] | 364 | Dependency.withConfiguredAspects(b, target, noAspects, noAspectsMap)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 365 | .addEqualityGroup( |
| 366 | // base set but with transition HOST |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 367 | Dependency.withTransitionAndAspects(a, HostTransition.INSTANCE, twoAspects), |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 368 | Dependency.withTransitionAndAspects( |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 369 | aExplicit, HostTransition.INSTANCE, twoAspects), |
| 370 | Dependency.withTransitionAndAspects(a, HostTransition.INSTANCE, inverseAspects), |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 371 | Dependency.withTransitionAndAspects( |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 372 | aExplicit, HostTransition.INSTANCE, inverseAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 373 | .addEqualityGroup( |
| 374 | // base set but with transition HOST and different aspects |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 375 | Dependency.withTransitionAndAspects(a, HostTransition.INSTANCE, differentAspects), |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 376 | Dependency.withTransitionAndAspects( |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 377 | aExplicit, HostTransition.INSTANCE, differentAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 378 | .addEqualityGroup( |
| 379 | // base set but with transition HOST and label //b |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 380 | Dependency.withTransitionAndAspects(b, HostTransition.INSTANCE, twoAspects), |
| 381 | Dependency.withTransitionAndAspects(b, HostTransition.INSTANCE, inverseAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 382 | .addEqualityGroup( |
| 383 | // inverse of base set: transition HOST, label //b, different aspects |
gregce | c7b2121 | 2017-12-21 12:40:20 -0800 | [diff] [blame] | 384 | Dependency.withTransitionAndAspects(b, HostTransition.INSTANCE, differentAspects), |
| 385 | Dependency.withTransitionAndAspects(b, HostTransition.INSTANCE, differentAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 386 | .addEqualityGroup( |
| 387 | // base set but with transition NONE |
gregce | 7fa23ea | 2018-01-18 12:46:04 -0800 | [diff] [blame] | 388 | Dependency.withTransitionAndAspects(a, NoTransition.INSTANCE, twoAspects), |
| 389 | Dependency.withTransitionAndAspects(aExplicit, NoTransition.INSTANCE, twoAspects), |
| 390 | Dependency.withTransitionAndAspects(a, NoTransition.INSTANCE, inverseAspects), |
| 391 | Dependency.withTransitionAndAspects(aExplicit, NoTransition.INSTANCE, inverseAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 392 | .addEqualityGroup( |
| 393 | // base set but with transition NONE and different aspects |
gregce | 7fa23ea | 2018-01-18 12:46:04 -0800 | [diff] [blame] | 394 | Dependency.withTransitionAndAspects(a, NoTransition.INSTANCE, differentAspects), |
| 395 | Dependency.withTransitionAndAspects(aExplicit, NoTransition.INSTANCE, differentAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 396 | .addEqualityGroup( |
| 397 | // base set but with transition NONE and label //b |
gregce | 7fa23ea | 2018-01-18 12:46:04 -0800 | [diff] [blame] | 398 | Dependency.withTransitionAndAspects(b, NoTransition.INSTANCE, twoAspects), |
| 399 | Dependency.withTransitionAndAspects(b, NoTransition.INSTANCE, inverseAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 400 | .addEqualityGroup( |
| 401 | // inverse of base set: transition NONE, label //b, different aspects |
gregce | 7fa23ea | 2018-01-18 12:46:04 -0800 | [diff] [blame] | 402 | Dependency.withTransitionAndAspects(b, NoTransition.INSTANCE, differentAspects), |
| 403 | Dependency.withTransitionAndAspects(b, NoTransition.INSTANCE, differentAspects)) |
Michael Staib | 5e573fd | 2016-01-27 00:33:29 +0000 | [diff] [blame] | 404 | .testEquals(); |
| 405 | } |
| 406 | } |