| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package com.google.inject.example; |
| 18 |
|
|
| 19 |
|
import static junit.framework.Assert.assertTrue; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
@author |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 24 |
|
public class ClientServiceWithDependencyInjection { |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 28 |
|
public interface Service { |
| 29 |
|
void go(); |
| 30 |
|
} |
| 31 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
| 32 |
|
public static class ServiceImpl implements ClientServiceWithDependencyInjection.Service { |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 33 |
0
|
public void go() {... |
| 34 |
|
|
| 35 |
|
} |
| 36 |
|
} |
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 38 |
|
public static class ServiceFactory { |
| 39 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 40 |
0
|
private ServiceFactory() {}... |
| 41 |
|
|
| 42 |
|
private static final Service service = new ServiceImpl(); |
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
0
|
public static Service getInstance() {... |
| 45 |
0
|
return service; |
| 46 |
|
} |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 49 |
|
public static class Client { |
| 50 |
|
|
| 51 |
|
private final Service service; |
| 52 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
0
|
public Client(Service service) {... |
| 54 |
0
|
this.service = service; |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
0
|
public void go() {... |
| 58 |
0
|
service.go(); |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 62 |
|
public static class ClientFactory { |
| 63 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 64 |
0
|
private ClientFactory() {}... |
| 65 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 66 |
0
|
public static Client getInstance() {... |
| 67 |
0
|
Service service = ServiceFactory.getInstance(); |
| 68 |
0
|
return new Client(service); |
| 69 |
|
} |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 72 |
0
|
public void testClient() {... |
| 73 |
0
|
MockService mock = new MockService(); |
| 74 |
0
|
Client client = new Client(mock); |
| 75 |
0
|
client.go(); |
| 76 |
0
|
assertTrue(mock.isGone()); |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 79 |
|
public static class MockService implements Service { |
| 80 |
|
|
| 81 |
|
private boolean gone = false; |
| 82 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 83 |
0
|
public void go() {... |
| 84 |
0
|
gone = true; |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
0
|
public boolean isGone() {... |
| 88 |
0
|
return gone; |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
0
|
public static void main(String[] args) {... |
| 93 |
0
|
new ClientServiceWithDependencyInjection().testClient(); |
| 94 |
|
} |
| 95 |
|
} |