1 /* 2 * Copyright (C) 2018 The Dagger Authors. 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 dagger.functional.multibindings; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static java.lang.annotation.RetentionPolicy.RUNTIME; 21 22 import com.google.auto.value.AutoAnnotation; 23 import dagger.Component; 24 import dagger.MapKey; 25 import dagger.Module; 26 import dagger.Provides; 27 import dagger.multibindings.IntoMap; 28 import java.lang.annotation.Retention; 29 import java.util.Map; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.junit.runners.JUnit4; 33 34 @RunWith(JUnit4.class) 35 public final class ComplexMapKeysInDifferentOrderTest { 36 @Retention(RUNTIME) 37 @MapKey(unwrapValue = false) 38 @interface ComplexMapKey { i()39 int i(); j()40 int j(); 41 } 42 43 @Module 44 interface TestModule { 45 @Provides 46 @IntoMap 47 @ComplexMapKey(i = 1, j = 2) inOrder()48 static int inOrder() { 49 return 3; 50 } 51 52 @Provides 53 @IntoMap 54 @ComplexMapKey(j = 4, i = 5) backwardsOrder()55 static int backwardsOrder() { 56 return 6; 57 } 58 } 59 60 @Component(modules = TestModule.class) 61 interface TestComponent { map()62 Map<ComplexMapKey, Integer> map(); 63 } 64 65 @Test test()66 public void test() { 67 Map<ComplexMapKey, Integer> map = 68 DaggerComplexMapKeysInDifferentOrderTest_TestComponent.create().map(); 69 assertThat(map.get(mapKey(1, 2))).isEqualTo(3); 70 assertThat(map.get(mapKey(5, 4))).isEqualTo(6); 71 } 72 73 @AutoAnnotation mapKey(int i, int j)74 static ComplexMapKey mapKey(int i, int j) { 75 return new AutoAnnotation_ComplexMapKeysInDifferentOrderTest_mapKey(i, j); 76 } 77 } 78