Clover Coverage Report - guice
Coverage timestamp: Wed Jan 7 2009 19:09:55 CST
../../../../img/srcFileCovDistChart0.png 84% of files have more coverage
12   95   11   1.09
0   52   0.92   1.57
11     1  
7    
 
  ClientServiceWithDependencyInjection       Line # 24 5 2 7 0% 0.0
  ClientServiceWithDependencyInjection.Service       Line # 28 0 0 0 - -1.0
  ClientServiceWithDependencyInjection.ServiceImpl       Line # 32 0 1 1 0% 0.0
  ClientServiceWithDependencyInjection.ServiceFactory       Line # 38 1 2 3 0% 0.0
  ClientServiceWithDependencyInjection.Client       Line # 49 2 2 4 0% 0.0
  ClientServiceWithDependencyInjection.ClientFactory       Line # 62 2 2 4 0% 0.0
  ClientServiceWithDependencyInjection.MockService       Line # 79 2 2 4 0% 0.0
 
No Tests
 
1    /**
2    * Copyright (C) 2006 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.example;
18   
19    import static junit.framework.Assert.assertTrue;
20   
21    /**
22    * @author crazybob@google.com (Bob Lee)
23    */
 
24    public class ClientServiceWithDependencyInjection {
25   
26    // 62 lines
27   
 
28    public interface Service {
29    void go();
30    }
31   
 
32    public static class ServiceImpl implements ClientServiceWithDependencyInjection.Service {
 
33  0 toggle public void go() {
34    // ...
35    }
36    }
37   
 
38    public static class ServiceFactory {
39   
 
40  0 toggle private ServiceFactory() {}
41   
42    private static final Service service = new ServiceImpl();
43   
 
44  0 toggle public static Service getInstance() {
45  0 return service;
46    }
47    }
48   
 
49    public static class Client {
50   
51    private final Service service;
52   
 
53  0 toggle public Client(Service service) {
54  0 this.service = service;
55    }
56   
 
57  0 toggle public void go() {
58  0 service.go();
59    }
60    }
61   
 
62    public static class ClientFactory {
63   
 
64  0 toggle private ClientFactory() {}
65   
 
66  0 toggle public static Client getInstance() {
67  0 Service service = ServiceFactory.getInstance();
68  0 return new Client(service);
69    }
70    }
71   
 
72  0 togglepublic 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   
 
79    public static class MockService implements Service {
80   
81    private boolean gone = false;
82   
 
83  0 toggle public void go() {
84  0 gone = true;
85    }
86   
 
87  0 toggle public boolean isGone() {
88  0 return gone;
89    }
90    }
91   
 
92  0 toggle public static void main(String[] args) {
93  0 new ClientServiceWithDependencyInjection().testClient();
94    }
95    }