• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.google.common.collect.testing;
18 
19 import com.google.common.collect.testing.features.CollectionFeature;
20 import java.util.Collections;
21 import java.util.List;
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestResult;
25 
26 /**
27  * @author Max Ross
28  */
29 public class FeatureSpecificTestSuiteBuilderTest extends TestCase {
30   private static final class MyTestSuiteBuilder
31       extends FeatureSpecificTestSuiteBuilder<MyTestSuiteBuilder, String> {
32     @Override
getTesters()33     protected List<Class<? extends AbstractTester>> getTesters() {
34       return Collections.<Class<? extends AbstractTester>>singletonList(MyTester.class);
35     }
36   }
37 
testLifecycle()38   public void testLifecycle() {
39     boolean[] setUp = {false};
40     Runnable setUpRunnable =
41         new Runnable() {
42           @Override
43           public void run() {
44             setUp[0] = true;
45           }
46         };
47 
48     boolean[] tearDown = {false};
49     Runnable tearDownRunnable =
50         new Runnable() {
51           @Override
52           public void run() {
53             tearDown[0] = true;
54           }
55         };
56 
57     MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
58     Test test =
59         builder
60             .usingGenerator("yam")
61             .named("yam")
62             .withFeatures(CollectionFeature.NONE)
63             .withSetUp(setUpRunnable)
64             .withTearDown(tearDownRunnable)
65             .createTestSuite();
66     TestResult result = new TestResult();
67     int timesMyTesterWasRunBeforeSuite = MyTester.timesTestClassWasRun;
68     test.run(result);
69     assertEquals(timesMyTesterWasRunBeforeSuite + 1, MyTester.timesTestClassWasRun);
70     assertTrue(setUp[0]);
71     assertTrue(tearDown[0]);
72   }
73 }
74