1 // Copyright 2007 Google Inc. All Rights Reserved. 2 3 package com.google.inject; 4 5 import junit.framework.TestCase; 6 7 /** 8 * Tests relating to modules. 9 * 10 * @author kevinb 11 */ 12 public class ModuleTest extends TestCase { 13 14 static class A implements Module { 15 @Override configure(Binder binder)16 public void configure(Binder binder) { 17 binder.bind(X.class); 18 binder.install(new B()); 19 binder.install(new C()); 20 } 21 } 22 23 static class B implements Module { 24 @Override configure(Binder binder)25 public void configure(Binder binder) { 26 binder.bind(Y.class); 27 binder.install(new D()); 28 } 29 } 30 31 static class C implements Module { 32 @Override configure(Binder binder)33 public void configure(Binder binder) { 34 binder.bind(Z.class); 35 binder.install(new D()); 36 } 37 } 38 39 static class D implements Module { 40 @Override configure(Binder binder)41 public void configure(Binder binder) { 42 binder.bind(W.class); 43 } 44 45 @Override equals(Object obj)46 public boolean equals(Object obj) { 47 return obj.getClass() == D.class; // we're all equal in the eyes of guice 48 } 49 50 @Override hashCode()51 public int hashCode() { 52 return D.class.hashCode(); 53 } 54 } 55 56 static class X {} 57 58 static class Y {} 59 60 static class Z {} 61 62 static class W {} 63 testDiamond()64 public void testDiamond() throws Exception { 65 Guice.createInjector(new A()); 66 } 67 } 68