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