/testability-explorer/src/test/java/com/google/test/metric/testing/MetricComputerBuilder.java

http://testability-explorer.googlecode.com/ · Java · 58 lines · 26 code · 10 blank · 22 comment · 0 complexity · 57c319771c7e280a6f4e7cdecbb69dff MD5 · raw file

  1. /*
  2. * Copyright 2008 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.testing;
  17. import java.io.PrintStream;
  18. import com.google.test.metric.ClassRepository;
  19. import com.google.test.metric.JavaClassRepository;
  20. import com.google.test.metric.MetricComputer;
  21. import com.google.test.metric.RegExpWhiteList;
  22. /**
  23. * For use in tests, this is a preferable way to construct a {@code MetricComputer},
  24. * as opposed to inheriting from a TestCase that does it for you. Prefer composition
  25. * over inheritance.
  26. *
  27. * @author Jonathan Andrew Wolter
  28. */
  29. public class MetricComputerBuilder {
  30. private ClassRepository repo = new JavaClassRepository();
  31. private PrintStream printStream = null;
  32. private RegExpWhiteList whitelist = new RegExpWhiteList();
  33. public MetricComputerBuilder withClassRepository(ClassRepository repository) {
  34. this.repo = repository;
  35. return this;
  36. }
  37. public MetricComputerBuilder withPrintStream(PrintStream stream) {
  38. this.printStream = stream;
  39. return this;
  40. }
  41. public MetricComputerBuilder withWhitelist(RegExpWhiteList regExpWhitelist) {
  42. this.whitelist = regExpWhitelist;
  43. return this;
  44. }
  45. public MetricComputer build() {
  46. return new MetricComputer(repo, printStream, whitelist, 1);
  47. }
  48. }