Home | History | Annotate | Download | only in jdk8
      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 
     17 package com.google.inject.jdk8;
     18 
     19 import com.google.inject.AbstractModule;
     20 import com.google.inject.Guice;
     21 import com.google.inject.Inject;
     22 import com.google.inject.Injector;
     23 import com.google.inject.assistedinject.Assisted;
     24 import com.google.inject.assistedinject.FactoryModuleBuilder;
     25 import junit.framework.TestCase;
     26 
     27 /**
     28  * Test static methods in interfaces.
     29  *
     30  * @author tavianator (at) tavianator.com (Tavian Barnes)
     31  */
     32 public class StaticInterfaceMethodsTest extends TestCase {
     33 
     34   private static class Thing {
     35     final int i;
     36 
     37     @Inject
     38     Thing(@Assisted int i) {
     39       this.i = i;
     40     }
     41   }
     42 
     43   private interface Factory {
     44     Thing create(int i);
     45 
     46     static Factory getDefault() {
     47       return Thing::new;
     48     }
     49   }
     50 
     51   public void testAssistedInjection() {
     52     Injector injector =
     53         Guice.createInjector(
     54             new AbstractModule() {
     55               @Override
     56               protected void configure() {
     57                 install(new FactoryModuleBuilder().build(Factory.class));
     58               }
     59             });
     60     Factory factory = injector.getInstance(Factory.class);
     61     assertEquals(1, factory.create(1).i);
     62   }
     63 }
     64