Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2008 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect.testing.features;
 
 import static org.truth0.Truth.ASSERT;
 
 
 
 import java.util.Set;

Author(s):
George van den Driessche
 
 // Enum values use constructors with generic varargs.
 @SuppressWarnings("unchecked")
 public class FeatureUtilTest extends TestCase {
   interface ExampleBaseInterface {
     void behave();
   }
 
   interface ExampleDerivedInterface extends ExampleBaseInterface {
     void misbehave();
   }
 
     BASE_FEATURE_1,
     BASE_FEATURE_2;
 
     @Override
     public Set<Feature<? super ExampleBaseInterface>> getImpliedFeatures() {
       return Collections.emptySet();
     }
 
     @Inherited
     @interface Require {
       ExampleBaseFeature[] value() default {};
       ExampleBaseFeature[] absent() default {};
     }
   }
 
     DERIVED_FEATURE_1,
     DERIVED_FEATURE_2(.),
     DERIVED_FEATURE_3,
 
     COMPOUND_DERIVED_FEATURE(
         ,
         ,
 
     private Set<Feature<? super ExampleDerivedInterface>> implied;
 
         Feature<? super ExampleDerivedInterface> ... implied) {
       this. = ImmutableSet.copyOf(implied);
     }
 
     @Override
     public Set<Feature<? super ExampleDerivedInterface>> getImpliedFeatures() {
       return ;
     }
 
     @Inherited
     @interface Require {
       ExampleDerivedFeature[] value() default {};
       ExampleDerivedFeature[] absent() default {};
     }
   }
 
   @interface NonTesterAnnotation {
   }
 
  private static abstract class ExampleBaseInterfaceTester extends TestCase {
    protected final void doNotActuallyRunThis() {
      fail("Nobody's meant to actually run this!");
    }
  }
  private static class ExampleDerivedInterfaceTester
      extends ExampleBaseInterfaceTester {
    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
    }
    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    public void testRequiringAllThreeDerivedFeatures() {
    }
    // Exists to test that our framework doesn't run it:
    @SuppressWarnings("unused")
    public void testRequiringConflictingFeatures() throws Exception {
    }
  }
  private static class ExampleDerivedInterfaceTester_Conflict
      extends ExampleBaseInterfaceTester {
  }
  public void testTestFeatureEnums() throws Exception {
    // Haha! Let's test our own test rig!
    FeatureEnumTest.assertGoodFeatureEnum(
        FeatureUtilTest.ExampleBaseFeature.class);
    FeatureEnumTest.assertGoodFeatureEnum(
  }
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(
    assertSame(features, FeatureUtil.addImpliedFeatures(features));
  }
    Set<Feature<?>> features;
    features = Sets.<Feature<?>>newHashSet(
    .that(FeatureUtil.addImpliedFeatures(features)).has().item(
    features = Sets.<Feature<?>>newHashSet(
    .that(FeatureUtil.addImpliedFeatures(features)).has().exactly(
    features = Sets.<Feature<?>>newHashSet(
    .that(FeatureUtil.addImpliedFeatures(features)).has().exactly(
  }
    Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(
    assertNotSame(features, FeatureUtil.impliedFeatures(features));
  }
    Set<Feature<?>> features;
    features = Sets.<Feature<?>>newHashSet(
    assertTrue(FeatureUtil.impliedFeatures(features).isEmpty());
    features = Sets.<Feature<?>>newHashSet(
    .that(FeatureUtil.impliedFeatures(features)).has().item(
    features = Sets.<Feature<?>>newHashSet(
    .that(FeatureUtil.impliedFeatures(features)).has().exactly(
  }
  public void testBuildTesterRequirements_class() throws Exception {
            ExampleBaseInterfaceTester.class),
        new TesterRequirements(
            Sets.<Feature<?>>newHashSet(.),
            Collections.<Feature<?>>emptySet()));
            ExampleDerivedInterfaceTester.class),
        new TesterRequirements(
            Sets.<Feature<?>>newHashSet(
                .,
                .),
            Collections.<Feature<?>>emptySet()));
  }
  public void testBuildTesterRequirements_method() throws Exception {
            "testRequiringTwoExplicitDerivedFeatures")),
        new TesterRequirements(
            Sets.<Feature<?>>newHashSet(
                .,
                .,
                .),
            Collections.<Feature<?>>emptySet()));
            "testRequiringAllThreeDerivedFeatures")),
        new TesterRequirements(
            Sets.<Feature<?>>newHashSet(
                .,
                .,
                .,
                .),
            Collections.<Feature<?>>emptySet()));
  }
      throws Exception {
    try {
      FeatureUtil.buildTesterRequirements(
          ExampleDerivedInterfaceTester_Conflict.class);
      fail("Expected ConflictingRequirementsException");
    } catch (ConflictingRequirementsException e) {
      .that(e.getConflicts()).has().item(
    }
  }
      throws Exception {
    final Method method = ExampleDerivedInterfaceTester.class
        .getMethod("testRequiringConflictingFeatures");
    try {
      FeatureUtil.buildTesterRequirements(method);
      fail("Expected ConflictingRequirementsException");
    } catch (ConflictingRequirementsException e) {
      .that(e.getConflicts()).has().item(
      assertEquals(methode.getSource());
    }
  }
  public void testBuildDeclaredTesterRequirements() throws Exception {
        ExampleDerivedInterfaceTester.class
            .getMethod("testRequiringTwoExplicitDerivedFeatures")),
        new TesterRequirements(FeatureUtil.addImpliedFeatures(
            Sets.<Feature<?>>newHashSet(
                .,
                .)),
            Collections.<Feature<?>>emptySet()));
  }
New to GrepCode? Check out our FAQ X