Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java mockito mock set

Tags:

java

mockito

set

Is possible mock set so after use in cycle e.g.

for(String key: mySet) { ...}

Thanks.

like image 426
user710818 Avatar asked Aug 25 '11 15:08

user710818


1 Answers

There is a couple options:

  1. Cast it
  2. Use @Mock annotation

Examples:

Set<String> mySet = (Set<String>) mock(Set.class);

--or--

@Mock
private Set<String> mySet;

@Before
public void doBefore() throws Exception {
    MockitoAnnotations.initMocks(this.getClass()); //this should create mocks for your objects...
}
like image 95
nicholas.hauschild Avatar answered Oct 25 '22 06:10

nicholas.hauschild