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

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

http://testability-explorer.googlecode.com/
Java | 49 lines | 18 code | 4 blank | 27 comment | 0 complexity | 42738e9a8138cedb3bd2ffab6ef99e75 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 * This class demonstrates that if a method is final, it cannot be
20 * overridden to make a seam.
21 */
22public class FinalMethodCantBeOverridden {
23  /**
24   * This class has a final method with a cyclomatic complexity of 2.
25   */
26  public static class HasFinalMethod {
27    final String computeString() {
28      boolean x = true;
29      boolean a = x ? false : true;
30      String b = a ? "hello" : "goodbye";
31      return b;
32    }
33  }
34
35  private HasFinalMethod collaborator;
36
37  // Even though the collaborator is injected into the constructor...
38  public FinalMethodCantBeOverridden(HasFinalMethod collaborator) {
39    this.collaborator = collaborator;
40  }
41
42  /**
43   * there is no seam between us and the computeString() method, so we have a
44   * non-mockable cost of 2.
45   */
46  public void NeedsAnInstance() {
47    collaborator.computeString();
48  }
49}