This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 0858500d10 refactor DubboAppenderTest (#10250)
0858500d10 is described below
commit 0858500d10f78d68a02f0ec50787424b4cfaa4ab
Author: cheese8 <[email protected]>
AuthorDate: Fri Jul 1 14:17:50 2022 +0800
refactor DubboAppenderTest (#10250)
---
.../dubbo/common/utils/DubboAppenderTest.java | 39 +++++++++++-----------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DubboAppenderTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DubboAppenderTest.java
index 7f1045b044..24cb10539a 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DubboAppenderTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/DubboAppenderTest.java
@@ -23,25 +23,25 @@ import org.apache.log4j.spi.LoggingEvent;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class DubboAppenderTest {
private LoggingEvent event;
@BeforeEach
public void setUp() throws Exception {
- Level level = Mockito.mock(Level.class);
- Category category = Mockito.mock(Category.class);
- event = Mockito.mock(LoggingEvent.class);
- Mockito.when(event.getLogger()).thenReturn(category);
- Mockito.when(event.getLevel()).thenReturn(level);
- Mockito.when(event.getThreadName()).thenReturn("thread-name");
- Mockito.when(event.getMessage()).thenReturn("message");
+ event = mock(LoggingEvent.class);
+ when(event.getLogger()).thenReturn(mock(Category.class));
+ when(event.getLevel()).thenReturn(mock(Level.class));
+ when(event.getThreadName()).thenReturn("thread-name");
+ when(event.getMessage()).thenReturn("message");
}
@AfterEach
@@ -51,8 +51,8 @@ public class DubboAppenderTest {
}
@Test
- public void testAvailable() throws Exception {
- assertThat(DubboAppender.available, is(false));
+ public void testAvailable() {
+ assumeFalse(DubboAppender.available);
DubboAppender.doStart();
assertThat(DubboAppender.available, is(true));
DubboAppender.doStop();
@@ -60,24 +60,23 @@ public class DubboAppenderTest {
}
@Test
- public void testAppend() throws Exception {
+ public void testAppend() {
DubboAppender appender = new DubboAppender();
appender.append(event);
- assertThat(DubboAppender.logList, hasSize(0));
+ assumeTrue(0 == DubboAppender.logList.size());
DubboAppender.doStart();
appender.append(event);
assertThat(DubboAppender.logList, hasSize(1));
- Log log = DubboAppender.logList.get(0);
- assertThat(log.getLogThread(), equalTo("thread-name"));
+ assertThat(DubboAppender.logList.get(0).getLogThread(),
equalTo("thread-name"));
}
@Test
- public void testClear() throws Exception {
+ public void testClear() {
DubboAppender.doStart();
DubboAppender appender = new DubboAppender();
appender.append(event);
-// assertThat(DubboAppender.logList, hasSize(1));
+ assumeTrue(1 == DubboAppender.logList.size());
DubboAppender.clear();
-// assertThat(DubboAppender.logList, hasSize(0));
+ assertThat(DubboAppender.logList, hasSize(0));
}
}