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.junitrunner; 6 7 import junit.framework.TestCase; 8 import org.junit.Ignore; 9 import org.junit.Test; 10 import org.junit.runner.JUnitCore; 11 import org.junit.runner.Result; 12 import org.junit.runner.RunWith; 13 import org.mockito.Mock; 14 import org.mockito.internal.exceptions.ExceptionIncludingMockitoWarnings; 15 import org.mockito.runners.VerboseMockitoJUnitRunner; 16 import org.mockitousage.IMethods; 17 import org.mockitoutil.TestBase; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 import static org.mockito.Mockito.*; 22 23 //@RunWith(ConsoleSpammingMockitoJUnitRunner.class) 24 @RunWith(VerboseMockitoJUnitRunner.class) 25 //TODO 26 public class VerboseMockitoRunnerTest extends TestBase { 27 28 @Mock private IMethods mock; 29 30 public static class NoWarnings { 31 32 @Test 33 @Ignore test()34 public void test() { 35 IMethods mock = mock(IMethods.class); 36 mock.simpleMethod(1); 37 mock.otherMethod(); 38 39 verify(mock).simpleMethod(1); 40 throw new RuntimeException("boo"); 41 } 42 } 43 44 public static class ContainsWarnings extends TestCase { 45 ContainsWarnings()46 public ContainsWarnings() { 47 super("test"); 48 } 49 testIgnored()50 public void testIgnored() {} 51 _test()52 public void _test() { 53 IMethods mock = mock(IMethods.class); 54 55 //some stubbing 56 when(mock.simpleMethod(1)).thenReturn("foo"); 57 when(mock.otherMethod()).thenReturn("foo"); 58 when(mock.booleanObjectReturningMethod()).thenReturn(false); 59 60 //stub called with different args: 61 String ret = mock.simpleMethod(2); 62 63 //assertion fails due to stub called with different args 64 assertEquals("foo", ret); 65 } 66 } 67 cleanStackTraces()68 public void cleanStackTraces() { 69 makeStackTracesClean(); 70 } 71 72 @Test 73 @Ignore shouldContainWarnings()74 public void shouldContainWarnings() throws Exception { 75 //when 76 Result result = new JUnitCore().run(new ContainsWarnings()); 77 //then 78 assertEquals(1, result.getFailures().size()); 79 Throwable exception = result.getFailures().get(0).getException(); 80 assertTrue(exception instanceof ExceptionIncludingMockitoWarnings); 81 } 82 83 @Test 84 @Ignore shouldNotContainWarnings()85 public void shouldNotContainWarnings() throws Exception { 86 Result result = new JUnitCore().run(NoWarnings.class); 87 assertEquals(1, result.getFailures().size()); 88 assertEquals("boo", result.getFailures().get(0).getException().getMessage()); 89 } 90 } 91