File: ModuleTest.java

package info (click to toggle)
guice 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,692 kB
  • sloc: java: 72,879; xml: 1,431; sh: 58; jsp: 12; makefile: 5
file content (68 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2007 Google Inc. All Rights Reserved.

package com.google.inject;

import junit.framework.TestCase;

/**
 * Tests relating to modules.
 *
 * @author kevinb
 */
public class ModuleTest extends TestCase {

  static class A implements Module {
    @Override
    public void configure(Binder binder) {
      binder.bind(X.class);
      binder.install(new B());
      binder.install(new C());
    }
  }

  static class B implements Module {
    @Override
    public void configure(Binder binder) {
      binder.bind(Y.class);
      binder.install(new D());
    }
  }

  static class C implements Module {
    @Override
    public void configure(Binder binder) {
      binder.bind(Z.class);
      binder.install(new D());
    }
  }

  static class D implements Module {
    @Override
    public void configure(Binder binder) {
      binder.bind(W.class);
    }

    @Override
    @SuppressWarnings("EqualsBrokenForNull") // intentionally NPE on null for the test
    public boolean equals(Object obj) {
      return obj.getClass() == D.class; // we're all equal in the eyes of guice
    }

    @Override
    public int hashCode() {
      return D.class.hashCode();
    }
  }

  static class X {}

  static class Y {}

  static class Z {}

  static class W {}

  public void testDiamond() throws Exception {
    Guice.createInjector(new A());
  }
}