-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I cant use It #156
Comments
Can you provide a simple project which reproduce such issue? |
It's almost identical to your case @Component
@Slf4j
public class OssManager {
@Resource
private OssCopyUtil ossCopyUtil;
public void asyncCopyFile() {
new ForkJoinPool().execute(() -> {
try {
ossPartCopyUtil.copy();
}
catch (Exception e) {
log.error("copy has an oss exception, message={}",e.getMessage());
}
});
}
} @RunWith(MockitoJUnitRunner.class)
public class OssManagerTest extends MockTest {
@Mock
Logger log;
@Mock
OssCopyUtil ossCopyUtil;
@InjectMocks
@Spy
OssManager ossManager;
@SneakyThrows
@Test
public void testAsyncCopyFile() {
when(ossCopyUtil.copy()).thenReturn("").thenThrow(new RuntimeException());
ossManager.asyncCopyFile();
verify(log, timeout(1000).times(1)).error(anyString(), anyString(), anyLong(), anyString());
}
} |
To reproduce I need a complete project example code na pom.xml ... sometime dependencies in project are important |
I can only provide you with partial dependence The SpringBoot version is 2.2.4.RELEASE <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- 因为uic、switchcenter、sentinel强依赖log4j,所以要排掉log4j-over-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>999-not-exist-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-inline -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>org.simplify4u</groupId>
<artifactId>slf4j-mock</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.12.10</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.10</version>
</dependency> |
I need a simple project which can I build and show your issue - without it is difficult to debug and fix. Try creating new Maven project with pom and simple test, next please attach in issue or provide link to repository. |
ok,But this is a problem I have at work, and I need time to sort out the dependencies |
My two cents:
Logback is in the classpath. I think you should exclude it, something like that: <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>surefire or failsafe</artifactId>
<version>2.22.2</version>
<configuration>
...
<classpathDependencyExcludes>
<classpathDependencyExclude>ch.qos.logback:logback-classic</classpathDependencyExclude>
<classpathDependencyExclude>ch.qos.logback:logback-core</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>
|
I eliminated dependency the way you did, but verify(log, timeout(1000).times(1)).error(anyString(), anyString()); This verification is invalid, but in fact it executes on the contrary,Such verification is successful verifyNoInteractions(log); <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExclude>ch.qos.logback:logback-classic</classpathDependencyExclude>
<classpathDependencyExclude>ch.qos.logback:logback-core</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin> |
The text was updated successfully, but these errors were encountered: