PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/InjectabilityVerifier.java

http://testability-explorer.googlecode.com/
Java | 55 lines | 33 code | 7 blank | 15 comment | 13 complexity | 02f02902ed265e8df19ef3809013a0e6 MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric;
17
18import junit.framework.Assert;
19
20public class InjectabilityVerifier {
21
22  private String errors = "";
23
24  public void assertInjectable(ClassInfo classInfo, VariableState globalVariables) {
25    for (Variable field : classInfo.getFields()) {
26      verify(field, globalVariables);
27    }
28    for (MethodInfo method : classInfo.getMethods()) {
29      for (Variable param : method.getParameters()) {
30        verify(param, globalVariables);
31      }
32      for (Variable param : method.getLocalVariables()) {
33        verify(param, globalVariables);
34      }
35    }
36    Assert.assertTrue(errors, errors.length() == 0);
37  }
38
39  public void verify(Variable variable, VariableState globalVariables) {
40    if (variable.getName().equals("this")) {
41    } else if (variable.getName().endsWith("_I")) {
42      if (!globalVariables.isInjectable(variable)) {
43        errors += "\n" + variable + " should be injectable";
44      }
45    } else if (variable.getName().endsWith("_NI")) {
46      if (globalVariables.isInjectable(variable)) {
47        errors += "\n" + variable + " should be non injectable";
48      }
49    } else {
50      errors += "\n" + variable + " should end with '_I' or '_NI'.";
51    }
52  }
53
54
55}