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.matchers; 6 7 import static org.junit.Assert.assertEquals; 8 import static org.mockito.Mockito.*; 9 10 import java.util.Arrays; 11 import java.util.HashMap; 12 import java.util.HashSet; 13 14 import org.junit.Before; 15 import org.junit.Test; 16 import org.mockito.Mockito; 17 import org.mockitousage.IMethods; 18 import org.mockitoutil.TestBase; 19 20 @SuppressWarnings("unchecked") 21 public class NewMatchersTest extends TestBase { 22 23 private IMethods mock; 24 25 @Before setUp()26 public void setUp() { 27 mock = Mockito.mock(IMethods.class); 28 } 29 30 @Test shouldAllowAnyList()31 public void shouldAllowAnyList() { 32 when(mock.forList(anyList())).thenReturn("matched"); 33 34 assertEquals("matched", mock.forList(Arrays.asList("x", "y"))); 35 assertEquals(null, mock.forList(null)); 36 37 verify(mock, times(1)).forList(anyList()); 38 } 39 40 @Test shouldAllowAnyCollection()41 public void shouldAllowAnyCollection() { 42 when(mock.forCollection(anyCollection())).thenReturn("matched"); 43 44 assertEquals("matched", mock.forCollection(Arrays.asList("x", "y"))); 45 assertEquals(null, mock.forCollection(null)); 46 47 verify(mock, times(1)).forCollection(anyCollection()); 48 } 49 50 @Test shouldAllowAnyMap()51 public void shouldAllowAnyMap() { 52 when(mock.forMap(anyMap())).thenReturn("matched"); 53 54 assertEquals("matched", mock.forMap(new HashMap<String, String>())); 55 assertEquals(null, mock.forMap(null)); 56 57 verify(mock, times(1)).forMap(anyMap()); 58 } 59 60 @Test shouldAllowAnySet()61 public void shouldAllowAnySet() { 62 when(mock.forSet(anySet())).thenReturn("matched"); 63 64 assertEquals("matched", mock.forSet(new HashSet<String>())); 65 assertEquals(null, mock.forSet(null)); 66 67 verify(mock, times(1)).forSet(anySet()); 68 } 69 70 @Test shouldAllowAnyIterable()71 public void shouldAllowAnyIterable() { 72 when(mock.forIterable(anyIterable())).thenReturn("matched"); 73 74 assertEquals("matched", mock.forIterable(new HashSet<String>())); 75 assertEquals(null, mock.forIterable(null)); 76 77 verify(mock, times(1)).forIterable(anyIterable()); 78 } 79 } 80