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.verification; 7 8 import org.junit.Test; 9 import org.mockito.Mockito; 10 import org.mockitoutil.TestBase; 11 12 import java.util.HashMap; 13 import java.util.List; 14 import java.util.Map; 15 import java.util.Set; 16 17 import static org.mockito.Mockito.*; 18 19 @SuppressWarnings("unchecked") 20 public class VerificationOnMultipleMocksUsingMatchersTest extends TestBase { 21 22 @Test shouldVerifyUsingMatchers()23 public void shouldVerifyUsingMatchers() throws Exception { 24 List<Object> list = Mockito.mock(List.class); 25 HashMap<Object, Object> map = Mockito.mock(HashMap.class); 26 27 list.add("test"); 28 list.add(1, "test two"); 29 30 map.put("test", 100); 31 map.put("test two", 200); 32 33 verify(list).add(anyObject()); 34 verify(list).add(anyInt(), eq("test two")); 35 36 verify(map, times(2)).put(anyObject(), anyObject()); 37 verify(map).put(eq("test two"), eq(200)); 38 39 verifyNoMoreInteractions(list, map); 40 } 41 42 @Test shouldVerifyMultipleMocks()43 public void shouldVerifyMultipleMocks() throws Exception { 44 List<String> list = mock(List.class); 45 Map<Object, Integer> map = mock(Map.class); 46 Set<?> set = mock(Set.class); 47 48 list.add("one"); 49 list.add("one"); 50 list.add("two"); 51 52 map.put("one", 1); 53 map.put("one", 1); 54 55 verify(list, times(2)).add("one"); 56 verify(list, times(1)).add("two"); 57 verify(list, times(0)).add("three"); 58 59 verify(map, times(2)).put(anyObject(), anyInt()); 60 61 verifyNoMoreInteractions(list, map); 62 verifyZeroInteractions(set); 63 } 64 } 65