|
Java example source code file (FeatureUtilTest.java)
The FeatureUtilTest.java Java example source code/* * 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 com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import junit.framework.TestCase; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; /** * @author 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(); } enum ExampleBaseFeature implements Feature<ExampleBaseInterface> { BASE_FEATURE_1, BASE_FEATURE_2; @Override public Set<Feature super ExampleBaseInterface>> getImpliedFeatures() { return Collections.emptySet(); } @Retention(RetentionPolicy.RUNTIME) @Inherited @TesterAnnotation @interface Require { ExampleBaseFeature[] value() default {}; ExampleBaseFeature[] absent() default {}; } } enum ExampleDerivedFeature implements Feature<ExampleDerivedInterface>{ DERIVED_FEATURE_1, DERIVED_FEATURE_2(ExampleBaseFeature.BASE_FEATURE_1), DERIVED_FEATURE_3, COMPOUND_DERIVED_FEATURE( DERIVED_FEATURE_1, DERIVED_FEATURE_2, ExampleBaseFeature.BASE_FEATURE_2); private Set<Feature super ExampleDerivedInterface>> implied; ExampleDerivedFeature( Feature<? super ExampleDerivedInterface> ... implied) { this.implied = ImmutableSet.copyOf(implied); } @Override public Set<Feature super ExampleDerivedInterface>> getImpliedFeatures() { return implied; } @Retention(RetentionPolicy.RUNTIME) @Inherited @TesterAnnotation @interface Require { ExampleDerivedFeature[] value() default {}; ExampleDerivedFeature[] absent() default {}; } } @Retention(RetentionPolicy.RUNTIME) @interface NonTesterAnnotation { } @ExampleBaseFeature.Require({ExampleBaseFeature.BASE_FEATURE_1}) private static abstract class ExampleBaseInterfaceTester extends TestCase { protected final void doNotActuallyRunThis() { fail("Nobody's meant to actually run this!"); } } @AndroidIncompatible // Android attempts to run directly @NonTesterAnnotation @ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2}) private static class ExampleDerivedInterfaceTester extends ExampleBaseInterfaceTester { // Exists to test that our framework doesn't run it: @SuppressWarnings("unused") @ExampleDerivedFeature.Require({ ExampleDerivedFeature.DERIVED_FEATURE_1, ExampleDerivedFeature.DERIVED_FEATURE_2}) public void testRequiringTwoExplicitDerivedFeatures() throws Exception { doNotActuallyRunThis(); } // Exists to test that our framework doesn't run it: @SuppressWarnings("unused") @ExampleDerivedFeature.Require({ ExampleDerivedFeature.DERIVED_FEATURE_1, ExampleDerivedFeature.DERIVED_FEATURE_3}) public void testRequiringAllThreeDerivedFeatures() { doNotActuallyRunThis(); } // Exists to test that our framework doesn't run it: @SuppressWarnings("unused") @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1}) public void testRequiringConflictingFeatures() throws Exception { doNotActuallyRunThis(); } } @ExampleDerivedFeature.Require( absent = {ExampleDerivedFeature.DERIVED_FEATURE_2}) 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( FeatureUtilTest.ExampleDerivedFeature.class); } public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception { Set<Feature>> features = Sets. Other Java examples (source code examples)Here is a short list of links related to this Java FeatureUtilTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.