• 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 
6 package org.mockitousage.bugs;
7 
8 import java.io.OutputStream;
9 import java.io.PrintStream;
10 import org.junit.Test;
11 import org.junit.internal.TextListener;
12 import org.junit.runner.JUnitCore;
13 import org.junit.runner.Result;
14 import org.junit.runner.RunWith;
15 import org.mockito.exceptions.base.MockitoException;
16 import org.mockito.junit.MockitoJUnitRunner;
17 import org.mockitoutil.TestBase;
18 
19 import static junit.framework.TestCase.assertEquals;
20 import static junit.framework.TestCase.assertFalse;
21 import static junit.framework.TestCase.assertTrue;
22 
23 
24 // @Ignore("for demo only. this test cannot be enabled as it fails :)")
25 public class MockitoRunnerBreaksWhenNoTestMethodsTest extends TestBase {
26 
27     @Test
ensure_the_test_runner_breaks()28     public void ensure_the_test_runner_breaks() throws Exception {
29         JUnitCore runner = new JUnitCore();
30 //        runner.addListener(new TextListener(System.out));
31         runner.addListener(new TextListener(DevNull.out));
32 
33         Result result = runner.run(TestClassWithoutTestMethod.class);
34 
35         assertEquals(1, result.getFailureCount());
36         assertTrue(result.getFailures().get(0).getException() instanceof MockitoException);
37         assertFalse(result.wasSuccessful());
38     }
39 
40     @RunWith(MockitoJUnitRunner.class)
41     static class TestClassWithoutTestMethod { // package visibility is important
notATestMethod()42         public void notATestMethod() { }
43     }
44 
45     public static final class DevNull {
46         public final static PrintStream out = new PrintStream(new OutputStream() {
47             public void close() {}
48             public void flush() {}
49             public void write(byte[] b) {}
50             public void write(byte[] b, int off, int len) {}
51             public void write(int b) {}
52 
53         } );
54     }
55 }
56