Java
74 строки · 2.3 Кб
1/*
2* Copyright (C) 2011 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
17package com.google.common.collect.testing;18
19import com.google.common.collect.testing.features.CollectionFeature;20import java.util.Collections;21import java.util.List;22import junit.framework.Test;23import junit.framework.TestCase;24import junit.framework.TestResult;25
26/**
27* @author Max Ross
28*/
29public class FeatureSpecificTestSuiteBuilderTest extends TestCase {30private static final class MyTestSuiteBuilder31extends FeatureSpecificTestSuiteBuilder<MyTestSuiteBuilder, String> {32@SuppressWarnings("rawtypes") // class literals33@Override34protected List<Class<? extends AbstractTester>> getTesters() {35return Collections.<Class<? extends AbstractTester>>singletonList(MyTester.class);36}37}38
39public void testLifecycle() {40boolean[] setUp = {false};41Runnable setUpRunnable =42new Runnable() {43@Override44public void run() {45setUp[0] = true;46}47};48
49boolean[] tearDown = {false};50Runnable tearDownRunnable =51new Runnable() {52@Override53public void run() {54tearDown[0] = true;55}56};57
58MyTestSuiteBuilder builder = new MyTestSuiteBuilder();59Test test =60builder
61.usingGenerator("yam")62.named("yam")63.withFeatures(CollectionFeature.NONE)64.withSetUp(setUpRunnable)65.withTearDown(tearDownRunnable)66.createTestSuite();67TestResult result = new TestResult();68int timesMyTesterWasRunBeforeSuite = MyTester.timesTestClassWasRun;69test.run(result);70assertEquals(timesMyTesterWasRunBeforeSuite + 1, MyTester.timesTestClassWasRun);71assertTrue(setUp[0]);72assertTrue(tearDown[0]);73}74}
75