• 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     @SuppressWarnings("rawtypes") // class literals
33     @Override
getTesters()34     protected List<Class<? extends AbstractTester>> getTesters() {
35       return Collections.<Class<? extends AbstractTester>>singletonList(MyTester.class);
36     }
37   }
38 
testLifecycle()39   public void testLifecycle() {
40     boolean[] setUp = {false};
41     Runnable setUpRunnable =
42         new Runnable() {
43           @Override
44           public void run() {
45             setUp[0] = true;
46           }
47         };
48 
49     boolean[] tearDown = {false};
50     Runnable tearDownRunnable =
51         new Runnable() {
52           @Override
53           public void run() {
54             tearDown[0] = true;
55           }
56         };
57 
58     MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
59     Test test =
60         builder
61             .usingGenerator("yam")
62             .named("yam")
63             .withFeatures(CollectionFeature.NONE)
64             .withSetUp(setUpRunnable)
65             .withTearDown(tearDownRunnable)
66             .createTestSuite();
67     TestResult result = new TestResult();
68     int timesMyTesterWasRunBeforeSuite = MyTester.timesTestClassWasRun;
69     test.run(result);
70     assertEquals(timesMyTesterWasRunBeforeSuite + 1, MyTester.timesTestClassWasRun);
71     assertTrue(setUp[0]);
72     assertTrue(tearDown[0]);
73   }
74 }
75