Debian Codegraph @

guava-testlib/src/com/google/common/collect/testing/AbstractTester.java

raw
1 /*
2 * Copyright (C) 2008 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.common.collect.testing;
18
19 import com.google.common.annotations.GwtCompatible;
20 import junit.framework.TestCase;
21 import org.checkerframework.checker.nullness.qual.Nullable;
22
23 /**
24 * This abstract base class for testers allows the framework to inject needed information after
25 * JUnit constructs the instances.
26 *
27 * <p>This class is emulated in GWT.
28 *
29 * @param <G> the type of the test generator required by this tester. An instance of G should
30 * somehow provide an instance of the class under test, plus any other information required to
31 * parameterize the test.
32 * @author George van den Driessche
33 */
34 @GwtCompatible
35 public class AbstractTester<G> extends TestCase {
36 private G subjectGenerator;
37 private String suiteName;
38 private @Nullable Runnable setUp;
39 private @Nullable Runnable tearDown;
40
41 // public so that it can be referenced in generated GWT tests.
42 @Override
43 public void setUp() throws Exception {
44 if (setUp != null) {
45 setUp.run();
46 }
47 }
48
49 // public so that it can be referenced in generated GWT tests.
50 @Override
51 public void tearDown() throws Exception {
52 if (tearDown != null) {
53 tearDown.run();
54 }
55 }
56
57 // public so that it can be referenced in generated GWT tests.
58 public final void init(
59 G subjectGenerator, String suiteName, @Nullable Runnable setUp, @Nullable Runnable tearDown) {
60 this.subjectGenerator = subjectGenerator;
61 this.suiteName = suiteName;
62 this.setUp = setUp;
63 this.tearDown = tearDown;
64 }
65
66 // public so that it can be referenced in generated GWT tests.
67 public final void init(G subjectGenerator, String suiteName) {
68 init(subjectGenerator, suiteName, null, null);
69 }
70
71 public G getSubjectGenerator() {
72 return subjectGenerator;
73 }
74
75 /** Returns the name of the test method invoked by this test instance. */
76 public final String getTestMethodName() {
77 return super.getName();
78 }
79
80 @Override
81 public String getName() {
82 return Platform.format("%s[%s]", super.getName(), suiteName);
83 }
84 }