| | |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.workorder.MesProWorkOrderMapper; |
| | | import cn.iocoder.yudao.module.mes.service.cal.holiday.MesCalHolidayService; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService; |
| | |
| | | } |
| | | |
| | | private static <T> T stub(Class<T> type, InvocationHandler handler) { |
| | | return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, handler)); |
| | | return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, (proxy, method, args) -> { |
| | | if (method.getDeclaringClass() == Object.class) { |
| | | return switch (method.getName()) { |
| | | case "toString" -> type.getSimpleName() + "Stub"; |
| | | case "hashCode" -> System.identityHashCode(proxy); |
| | | case "equals" -> proxy == args[0]; |
| | | default -> throw new AssertionError(method.getName()); |
| | | }; |
| | | } |
| | | return handler.invoke(proxy, method, args); |
| | | })); |
| | | } |
| | | |
| | | static class Fixture { |
| | |
| | | new MesMdWorkstationDO().setId(2L).setName("工作站B").setProcessId(2L).setStatus(0)))); |
| | | set("machineryMapper", stub(MesDvMachineryMapper.class, (p,m,a) -> machines)); |
| | | set("customerApi", stub(CrmCustomerApi.class, (p,m,a) -> null)); |
| | | set("holidayService", stub(MesCalHolidayService.class, (p,m,a) -> List.of())); |
| | | set("workOrderProcessService", stub(MesProWorkOrderProcessService.class, (p,m,a) -> processes)); |
| | | var quantities = new MesProScheduleQuantityService(); |
| | | ReflectionTestUtils.setField(quantities, "workOrderProcessService", stub(MesProWorkOrderProcessService.class, (p,m,a) -> processes)); |