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