Skip to content

Instantly share code, notes, and snippets.

@need4spd
Last active December 16, 2017 17:34
Show Gist options
  • Select an option

  • Save need4spd/5712838 to your computer and use it in GitHub Desktop.

Select an option

Save need4spd/5712838 to your computer and use it in GitHub Desktop.
Mockito
//Dao class
public class DAO {
public Result select(Param param) {
return sqlClient.select("id", param);
}
}
//Paramter class
public class Param {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
//Service
public class Service {
@Autowired
private DAO dao;
public Result select() {
Param param = new Param();
return dao.select(param);
}
}
//TestCase
@Mock
private DAO dao;
@InjectMocks
private Service service;
@Test
public void test() {
when(dao.select(new Param())).thenReturn(new Result());
service.select();
Assert.assertTrue(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment