Home | History | Annotate | Download | only in producerstest
      1 /*
      2 * Copyright (C) 2015 Google, Inc.
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 * http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 package producerstest;
     17 
     18 import com.google.common.collect.ImmutableSet;
     19 import com.google.common.util.concurrent.Futures;
     20 import com.google.common.util.concurrent.ListenableFuture;
     21 import dagger.producers.ProducerModule;
     22 import dagger.producers.Produces;
     23 import java.util.Set;
     24 import javax.inject.Qualifier;
     25 
     26 import static dagger.producers.Produces.Type.SET;
     27 import static dagger.producers.Produces.Type.SET_VALUES;
     28 
     29 @ProducerModule
     30 final class MultibindingProducerModule {
     31   @Qualifier
     32   @interface PossiblyThrowingSet {}
     33 
     34   @Produces(type = SET)
     35   static ListenableFuture<String> futureStr() {
     36     return Futures.immediateFuture("foo");
     37   }
     38 
     39   @Produces(type = SET)
     40   static String str() {
     41     return "bar";
     42   }
     43 
     44   @Produces(type = SET_VALUES)
     45   static ListenableFuture<Set<String>> futureStrs() {
     46     return Futures.<Set<String>>immediateFuture(ImmutableSet.of("foo1", "foo2"));
     47   }
     48 
     49   @Produces(type = SET_VALUES)
     50   static Set<String> strs() {
     51     return ImmutableSet.of("bar1", "bar2");
     52   }
     53 
     54   @Produces
     55   static int strCount(Set<String> strs) {
     56     return strs.size();
     57   }
     58 
     59   @Produces(type = SET)
     60   @PossiblyThrowingSet
     61   static String successfulStringForSet() {
     62     return "singleton";
     63   }
     64 
     65   @Produces(type = SET_VALUES)
     66   @PossiblyThrowingSet
     67   static Set<String> successfulStringsForSet() {
     68     return ImmutableSet.of("double", "ton");
     69   }
     70 
     71   @Produces(type = SET)
     72   @PossiblyThrowingSet
     73   static String throwingStringForSet() {
     74     throw new RuntimeException("monkey");
     75   }
     76 }
     77