• 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 
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestResult;
24 
25 import java.util.Collections;
26 import java.util.List;
27 
28 /**
29  * @author Max Ross
30  */
31 public class FeatureSpecificTestSuiteBuilderTest extends TestCase {
32 
33   static boolean testWasRun;
34 
35   @Override
setUp()36   protected void setUp() throws Exception {
37     super.setUp();
38     testWasRun = false;
39   }
40 
41   public static final class MyAbstractTester extends AbstractTester<Void> {
testNothing()42     public void testNothing() {
43       testWasRun = true;
44     }
45   }
46 
47   private static final class MyTestSuiteBuilder extends
48       FeatureSpecificTestSuiteBuilder<MyTestSuiteBuilder, String> {
49 
50     @Override
getTesters()51     protected List<Class<? extends AbstractTester>> getTesters() {
52       return Collections.<Class<? extends AbstractTester>>singletonList(MyAbstractTester.class);
53     }
54   }
55 
testLifecycle()56   public void testLifecycle() {
57     final boolean setUp[] = {false};
58     Runnable setUpRunnable = new Runnable() {
59       @Override
60       public void run() {
61         setUp[0] = true;
62       }
63     };
64 
65     final boolean tearDown[] = {false};
66     Runnable tearDownRunnable = new Runnable() {
67       @Override
68       public void run() {
69         tearDown[0] = true;
70       }
71     };
72 
73     MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
74     Test test = builder.usingGenerator("yam").named("yam")
75         .withFeatures(CollectionFeature.NONE).withSetUp(setUpRunnable)
76         .withTearDown(tearDownRunnable).createTestSuite();
77     TestResult result = new TestResult();
78     test.run(result);
79     assertTrue(testWasRun);
80     assertTrue(setUp[0]);
81     assertTrue(tearDown[0]);
82   }
83 }
84