Migrate junit4 to junit5.

pull/2473/head
Freeman Lau 3 years ago
parent 3bd3f52d90
commit ec29e197e5

@ -104,13 +104,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -20,7 +20,7 @@ import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
import com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;

@ -31,12 +31,13 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -117,11 +118,13 @@ public class DataSourcePropertiesTests {
assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024);
}
@Test(expected = RuntimeException.class)
@Test
public void testFileException() {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("classpath: 1.json");
fileDataSourceProperties.preCheck("test-ds");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("classpath: 1.json");
fileDataSourceProperties.preCheck("test-ds");
});
}
@Test

@ -26,7 +26,7 @@ import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

@ -20,7 +20,7 @@ import com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter;
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;

@ -18,7 +18,7 @@ package com.alibaba.cloud.sentinel.datasource;
import com.alibaba.cloud.sentinel.datasource.config.NacosDataSourceProperties;
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

@ -22,7 +22,7 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

@ -27,12 +27,13 @@ import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -67,16 +68,22 @@ public class SentinelConverterTests {
assertThat(flowRules.size()).isEqualTo(0);
}
@Test(expected = RuntimeException.class)
@Test
public void testConverterErrorFormat() {
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
jsonConverter.convert(readFileContent("classpath: flowrule-errorformat.json"));
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
jsonConverter
.convert(readFileContent("classpath: flowrule-errorformat.json"));
});
}
@Test(expected = RuntimeException.class)
@Test
public void testConverterErrorContent() {
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
jsonConverter.convert(readFileContent("classpath: flowrule-errorcontent.json"));
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
jsonConverter
.convert(readFileContent("classpath: flowrule-errorcontent.json"));
});
}
@Test
@ -108,7 +115,8 @@ public class SentinelConverterTests {
private String readFileContent(String file) {
try {
return FileUtils.readFileToString(
ResourceUtils.getFile(StringUtils.trimAllWhitespace(file)), Charset.defaultCharset());
ResourceUtils.getFile(StringUtils.trimAllWhitespace(file)),
Charset.defaultCharset());
}
catch (IOException e) {
return "";

@ -20,7 +20,7 @@ import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;

Loading…
Cancel
Save