PageRenderTime 47ms CodeModel.GetById 44ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/example/NonMockableCollaborator/StaticMethodCalled.java

http://testability-explorer.googlecode.com/
Java | 48 lines | 13 code | 3 blank | 32 comment | 1 complexity | 69b1fa80f6f866bd5b5453eef8cc1720 MD5 | raw file
 1/*
 2 * Copyright 2009 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.example.NonMockableCollaborator;
17
18/**
19 * An example of how static method calls to a complex method
20 * count as cyclomatic complexity cost due to a non-mockable
21 * dependency.
22 */
23public class StaticMethodCalled {
24
25  /**
26   * A static method is defined in this class, with a
27   * cyclomatic complexity of 2.
28   */
29  public static class HasStaticMethod {
30    public static boolean isGreat() {
31      boolean x = true;
32      boolean a = x ? true : false;
33      return a && x ? false : true;
34    }
35  }
36
37  /**
38   * In this code, there is a call to the static method. This is equivalent
39   * to calling new() to make an instance of HasStaticMethod - there is no
40   * seam between us and that method.
41   */
42  public void callTheMethod() {
43    /**
44     * This will incur a cyclomatic complexity cost of 2.
45     */
46    HasStaticMethod.isGreat();
47  }
48}