我有一個方法,需要一個地圖作爲參數的依賴關係。JMock地圖期望
public interface Service {
void doSomething(Map<String, String> map);
}
我想寫一個斷言,這個依賴被調用與適當的地圖內容。事情是這樣的:
@RunWith(JMock.class)
public class MainTest {
private Mockery context = new Mockery();
private Service service = context.mock(Service.class);
private Main main = new Main(service);
@Test
public void test() {
context.checking(new Expectations(){{
oneOf(service).doSomething(with(hasEntry("test", "test")));
}});
main.run();
}
}
不幸的是,這不能編譯,因爲hasEntry在地圖泛型參數通配符:
public static <K, V> org.hamcrest.Matcher<java.util.Map<? extends K, ? extends V>> hasEntry(K key, V value);
有沒有辦法寫一個JMock的expectaion在地圖內容是什麼?