2
* Copyright (C) 2008 The Guava Authors
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package com.google.common.collect.testing;
19
import com.google.common.annotations.GwtCompatible;
20
import com.google.common.annotations.GwtIncompatible;
21
import com.google.common.annotations.J2ktIncompatible;
22
import junit.framework.TestCase;
23
import org.checkerframework.checker.nullness.qual.Nullable;
26
* This abstract base class for testers allows the framework to inject needed information after
27
* JUnit constructs the instances.
29
* <p>This class is emulated in GWT.
31
* @param <G> the type of the test generator required by this tester. An instance of G should
32
* somehow provide an instance of the class under test, plus any other information required to
33
* parameterize the test.
34
* @author George van den Driessche
36
@GwtCompatible(emulated = true)
37
@ElementTypesAreNonnullByDefault
38
public class AbstractTester<G> extends TestCase {
39
private G subjectGenerator;
40
private String suiteName;
41
private @Nullable Runnable setUp;
42
private @Nullable Runnable tearDown;
44
// public so that it can be referenced in generated GWT tests.
46
public void setUp() throws Exception {
52
// public so that it can be referenced in generated GWT tests.
54
public void tearDown() throws Exception {
55
if (tearDown != null) {
60
// public so that it can be referenced in generated GWT tests.
61
public final void init(
62
G subjectGenerator, String suiteName, @Nullable Runnable setUp, @Nullable Runnable tearDown) {
63
this.subjectGenerator = subjectGenerator;
64
this.suiteName = suiteName;
66
this.tearDown = tearDown;
69
// public so that it can be referenced in generated GWT tests.
70
public final void init(G subjectGenerator, String suiteName) {
71
init(subjectGenerator, suiteName, null, null);
74
public G getSubjectGenerator() {
75
return subjectGenerator;
78
/** Returns the name of the test method invoked by this test instance. */
80
@GwtIncompatible // not used under GWT, and super.getName() is not available under J2CL
81
public final String getTestMethodName() {
82
return super.getName();
86
@GwtIncompatible // not used under GWT, and super.getName() is not available under J2CL
88
public String getName() {
89
return Platform.format("%s[%s]", super.getName(), suiteName);