ducthinh2111 / weekend-project

0 stars 0 forks source link

Mocking generate from java class/file #4

Open OzGhost opened 7 months ago

OzGhost commented 7 months ago

Situation

Expectation

OzGhost commented 6 months ago

Selected option:

OzGhost commented 6 months ago

v0.0.1:

OzGhost commented 6 months ago

Sample:

java -jar mockgen.jar /tmp/project/src/main/services/AddressService.java

Output on stdout:

when(addrDao.create(arg0, arg1, arg2, arg3)).thenReturn(out0);
when(addrDao.create(any(), any(), any(), any())).thenReturn(out0);
when(addrDao.delete(arg0)).thenThrow(ex0);
when(addrDao.delete(any())).thenThrow(ex0);
doNothing().when(addrDao).update(arg0);
doNothing().when(addrDao).update(any());
doThrow(ex0).when(addrDao).merge(arg0, arg1);
doThrow(ex0).when(addrDao).merge(any(), any());
ducthinh2111 commented 6 months ago
public class AddressService {

    @Inject
    private AddressDao addrDao;

    public Address create(Address address) {
        return addrDao.create(address);
    }

    public int delete(Address address) {
        return addrDao.delete(address);
    }

    public void update(Address address) {
        addrDao.update(address);
    }

    public Address merge(Address addr1, Address addr2) {
        return addrDao.merge(addr1, addr2);
    }
}