package com.battery.business; import static org.junit.jupiter.api.Assertions.assertFalse; import java.nio.file.Files; import java.nio.file.Path; import org.junit.jupiter.api.Test; /** 防止业务实现重新依赖厂商、模拟器或传输基础设施。 */ class ModuleDependencyContractTest { @Test void businessPomKeepsVendorImplementationsOutOfItsDependencies() throws Exception { Path pom = Path.of("pom.xml"); if (!Files.exists(pom)) pom = Path.of("battery-business", "pom.xml"); String text = Files.readString(pom); assertFalse(text.contains("battery-device-bts")); assertFalse(text.contains("battery-device-simulator")); assertFalse(text.contains("spring-boot-starter-data-redis")); } @Test void businessSourcesDependOnlyOnDeviceApi() throws Exception { Path sources = Path.of("src/main/java"); try (var files = Files.walk(sources)) { for (Path file : files.filter(path -> path.toString().endsWith(".java")).toList()) { String source = Files.readString(file); for (String forbidden : java.util.List.of("com.battery.device.bts", "com.battery.device.simulator", "com.ruoyi.system", "org.springframework.web", "org.springframework.data.redis", "SseEmitter")) assertFalse(source.contains(forbidden), file + " contains " + forbidden); } } } }