Java 使用Mockito测试具有lambda参数的方法的链式调用
我有以下接口: DAOFunctionCommand:Java 使用Mockito测试具有lambda参数的方法的链式调用,java,unit-testing,mocking,mockito,Java,Unit Testing,Mocking,Mockito,我有以下接口: DAOFunctionCommand: @FunctionalInterface public interface DAOFunctionCommand<T, R> { R execute(T input, IDAOManager manager) throws Exception; } @functioninterface 公共接口命令 { R execute(T输入,IDooManager)抛出异常; } DAOSupplierCommand: @Fu
@FunctionalInterface
public interface DAOFunctionCommand<T, R>
{
R execute(T input, IDAOManager manager) throws Exception;
}
@functioninterface
公共接口命令
{
R execute(T输入,IDooManager)抛出异常;
}
DAOSupplierCommand:
@FunctionalInterface
public interface DAOSupplierCommand<T>
{
T get(IDAOManager manager) throws Exception;
}
@functioninterface
公共接口DAOSupplierCommand
{
T get(IDooManager)抛出异常;
}
ITransactionStream:
public interface ITransactionStream<T, K extends IDAOManager>
{
<R> ITransactionStream<R, K> chain(DAOFunctionCommand<? super T, ? extends R> cmd) throws Exception;
<R> ITransactionStream<R, K> chain(DAOSupplierCommand<? extends R> cmd) throws Exception;
T getResult();
T end() throws Exception;
}
公共接口ITransactionStream
{
ITransactionStream链(DAOSfunctionCommands)DAO从何处获得m
?模拟它。@BoristheSpider'm'表示IDAOManager。
public interface ITransactionHead<T, K extends IDAOManager>
{
ITransactionStream<T, K> start() throws Exception;
}
public interface IDAOManager
{
ITicketDAO getTicketDAO() throws Exception;
IParkingSpotsDAO getParkingSpotDAO() throws Exception;
IParkingSpotCategoriesDAO getParkingSpotCategoriesDAO() throws Exception;
ITransactionHead<Object, ? extends IDAOManager> txStream() throws Exception;
}
public Optional<ParkingSpot> occupySpot(String category) throws Exception
{
daoManager.getParkingSpotCategoriesDAO().get(category);
Optional<ParkingSpot> ps = daoManager.txStream()
.start()
.chain((m) -> m.getParkingSpotDAO().getFreeSpot(category))
.chain((p, m) ->
{
if (!p.isPresent()) return Optional.<ParkingSpot>empty();
p.get().setAvailable(false);
m.getParkingSpotDAO().update(p.get());
return p;
}).end();
if (ps.isPresent()) notifyAllListeners();
return ps;
}