@Test public void withConfigurationAndAspects_BasicAccessors() throws Exception { update(); AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); ImmutableSet<AspectDescriptor> twoAspects = ImmutableSet.of(simpleAspect, attributeAspect); Dependency targetDep = Dependency.withConfigurationAndAspects( Label.parseAbsolute("//a"), getTargetConfiguration(), twoAspects); assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a")); assertThat(targetDep.hasStaticConfiguration()).isTrue(); assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration()); assertThat(targetDep.getAspects()).containsExactlyElementsIn(twoAspects); assertThat(targetDep.getAspectConfigurations()) .containsExactlyEntriesIn( ImmutableMap.of( simpleAspect, getTargetConfiguration(), attributeAspect, getTargetConfiguration())); try { targetDep.getTransition(); fail("withConfigurationAndAspects-created Dependencies should throw ISE on getTransition()"); } catch (IllegalStateException ex) { // good. that's what I WANTED to happen. } }
@Test public void withTransitionAndAspects_BasicAccessors() throws Exception { AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); ImmutableSet<AspectDescriptor> twoAspects = ImmutableSet.of(simpleAspect, attributeAspect); Dependency hostDep = Dependency.withTransitionAndAspects( Label.parseAbsolute("//a"), ConfigurationTransition.HOST, twoAspects); assertThat(hostDep.getLabel()).isEqualTo(Label.parseAbsolute("//a")); assertThat(hostDep.hasStaticConfiguration()).isFalse(); assertThat(hostDep.getAspects()).containsExactlyElementsIn(twoAspects); assertThat(hostDep.getTransition()).isEqualTo(ConfigurationTransition.HOST); try { hostDep.getConfiguration(); fail("withTransitionAndAspects-created Dependencies should throw ISE on getConfiguration()"); } catch (IllegalStateException ex) { // good. I knew you would do that. } try { hostDep.getAspectConfigurations(); fail( "withTransitionAndAspects-created Dependencies should throw ISE on " + "getAspectConfigurations()"); } catch (IllegalStateException ex) { // good. you're so predictable. } }
@Test public void withConfiguredAspects_BasicAccessors() throws Exception { update(); AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT); AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT); ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectMap = ImmutableMap.of( simpleAspect, getTargetConfiguration(), attributeAspect, getHostConfiguration()); Dependency targetDep = Dependency.withConfiguredAspects( Label.parseAbsolute("//a"), getTargetConfiguration(), twoAspectMap); assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a")); assertThat(targetDep.hasStaticConfiguration()).isTrue(); assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration()); assertThat(targetDep.getAspects()) .containsExactlyElementsIn(ImmutableSet.of(simpleAspect, attributeAspect)); assertThat(targetDep.getAspectConfigurations()).containsExactlyEntriesIn(twoAspectMap); try { targetDep.getTransition(); fail("withConfiguredAspects-created Dependencies should throw ISE on getTransition()"); } catch (IllegalStateException ex) { // good. all according to keikaku. (TL note: keikaku means plan) } }
@Test public void withConfiguredAspects_AllowsEmptyAspectMap() throws Exception { update(); Dependency dep = Dependency.withConfiguredAspects( Label.parseAbsolute("//a"), getTargetConfiguration(), ImmutableMap.<AspectDescriptor, BuildConfiguration>of()); // Here we're also checking that this doesn't throw an exception. No boom? OK. Good. assertThat(dep.getAspects()).isEmpty(); assertThat(dep.getAspectConfigurations()).isEmpty(); }
@Test public void withNullConfiguration_BasicAccessors() throws Exception { Dependency nullDep = Dependency.withNullConfiguration(Label.parseAbsolute("//a")); assertThat(nullDep.getLabel()).isEqualTo(Label.parseAbsolute("//a")); assertThat(nullDep.hasStaticConfiguration()).isTrue(); assertThat(nullDep.getConfiguration()).isNull(); assertThat(nullDep.getAspects()).isEmpty(); assertThat(nullDep.getAspectConfigurations()).isEmpty(); try { nullDep.getTransition(); fail("withNullConfiguration-created Dependencies should throw ISE on getTransition()"); } catch (IllegalStateException ex) { // good. expected. } }