OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.base.test; |
| 6 |
| 7 import org.junit.Assert; |
| 8 import org.junit.Before; |
| 9 import org.junit.Test; |
| 10 import org.junit.rules.TestRule; |
| 11 import org.junit.runner.RunWith; |
| 12 import org.junit.runners.BlockJUnit4ClassRunner; |
| 13 import org.junit.runners.model.Statement; |
| 14 |
| 15 import java.util.ArrayList; |
| 16 import java.util.List; |
| 17 |
| 18 /** |
| 19 * Test SetUpStatement is working as intended with SetUpTestRule. |
| 20 */ |
| 21 @RunWith(BlockJUnit4ClassRunner.class) |
| 22 public class SetUpStatementTest { |
| 23 private Statement mBase; |
| 24 private SetUpTestRule<TestRule> mRule; |
| 25 private List<Integer> mList; |
| 26 |
| 27 @Before |
| 28 public void setUp() { |
| 29 mBase = new Statement() { |
| 30 @Override |
| 31 public void evaluate() { |
| 32 mList.add(1); |
| 33 } |
| 34 }; |
| 35 mList = new ArrayList<>(); |
| 36 mRule = new SetUpTestRule<TestRule>() { |
| 37 @Override |
| 38 public void setUp() { |
| 39 mList.add(0); |
| 40 } |
| 41 |
| 42 @Override |
| 43 public TestRule shouldSetUp(boolean toSetUp) { |
| 44 return null; |
| 45 } |
| 46 }; |
| 47 } |
| 48 |
| 49 @Test |
| 50 public void testSetUpStatementShouldSetUp() throws Throwable { |
| 51 SetUpStatement statement = new SetUpStatement(mBase, mRule, true); |
| 52 statement.evaluate(); |
| 53 Integer[] expected = {0, 1}; |
| 54 Assert.assertArrayEquals(expected, mList.toArray()); |
| 55 } |
| 56 |
| 57 @Test |
| 58 public void testSetUpStatementShouldNotSetUp() throws Throwable { |
| 59 SetUpStatement statement = new SetUpStatement(mBase, mRule, false); |
| 60 statement.evaluate(); |
| 61 Integer[] expected = {1}; |
| 62 Assert.assertArrayEquals(expected, mList.toArray()); |
| 63 } |
| 64 } |
OLD | NEW |