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 org.junit.Test; 8 import org.junit.runner.RunWith; 9 import org.mockito.InjectMocks; 10 import org.mockito.Mock; 11 import org.mockito.junit.MockitoJUnitRunner; 12 13 import java.util.List; 14 15 import static org.junit.Assert.*; 16 import static org.mockito.Mockito.verify; 17 import static org.mockitousage.junitrunner.Filters.methodNameContains; 18 19 @RunWith(MockitoJUnitRunner.class) 20 public class JUnit45RunnerTest { 21 22 @InjectMocks private ListDependent listDependent = new ListDependent(); 23 @Mock private List<String> list; 24 25 @Test shouldInitMocksUsingRunner()26 public void shouldInitMocksUsingRunner() { 27 list.add("test"); 28 verify(list).add("test"); 29 } 30 31 @Test shouldInjectMocksUsingRunner()32 public void shouldInjectMocksUsingRunner() { 33 assertNotNull(list); 34 assertSame(list, listDependent.getList()); 35 } 36 37 @Test shouldFilterTestMethodsCorrectly()38 public void shouldFilterTestMethodsCorrectly() throws Exception{ 39 MockitoJUnitRunner runner = new MockitoJUnitRunner(this.getClass()); 40 41 runner.filter(methodNameContains("shouldInitMocksUsingRunner")); 42 43 assertEquals(1, runner.testCount()); 44 } 45 46 class ListDependent { 47 private List<?> list; 48 getList()49 public List<?> getList() { 50 return list; 51 } 52 } 53 } 54