• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.bugs;
6 
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertTrue;
10 
11 import java.io.OutputStream;
12 import java.io.PrintStream;
13 
14 import org.junit.Test;
15 import org.junit.internal.TextListener;
16 import org.junit.runner.JUnitCore;
17 import org.junit.runner.Result;
18 import org.junit.runner.RunWith;
19 import org.mockito.exceptions.base.MockitoException;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.mockitoutil.TestBase;
22 
23 // @Ignore("for demo only. this test cannot be enabled as it fails :)")
24 public class MockitoRunnerBreaksWhenNoTestMethodsTest extends TestBase {
25 
26     @Test
ensure_the_test_runner_breaks()27     public void ensure_the_test_runner_breaks() throws Exception {
28         JUnitCore runner = new JUnitCore();
29         //        runner.addListener(new TextListener(System.out));
30         runner.addListener(new TextListener(DevNull.out));
31 
32         Result result = runner.run(TestClassWithoutTestMethod.class);
33 
34         assertEquals(1, result.getFailureCount());
35         assertTrue(result.getFailures().get(0).getException() instanceof MockitoException);
36         assertFalse(result.wasSuccessful());
37     }
38 
39     @RunWith(MockitoJUnitRunner.class)
40     static class TestClassWithoutTestMethod { // package visibility is important
notATestMethod()41         public void notATestMethod() {}
42     }
43 
44     public static final class DevNull {
45         public static final PrintStream out =
46                 new PrintStream(
47                         new OutputStream() {
48                             public void close() {}
49 
50                             public void flush() {}
51 
52                             public void write(byte[] b) {}
53 
54                             public void write(byte[] b, int off, int len) {}
55 
56                             public void write(int b) {}
57                         });
58     }
59 }
60