未验证 提交 39b32844 编写于 作者: L Liang Zhang 提交者: GitHub

add includeTestSourceDirectory for checkstyle (#3177)

* for checkstyle

* includeTestSourceDirectory for checkstyle

* for checkstyle: avoid catch exception

* for checkstyle: avoid catch exception for BaseIT

* open rule: IllegalCatch
上级 14a106d7
......@@ -668,6 +668,7 @@
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<configLocation>src/resources/checkstyle_ci.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<excludes>**/autogen/**/*</excludes>
</configuration>
<executions>
......@@ -842,6 +843,7 @@
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<configLocation>src/resources/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<excludes>**/autogen/**/*</excludes>
</configuration>
</plugin>
......
......@@ -231,11 +231,7 @@ public final class EncryptRule implements BaseRule {
@Override
public Object apply(final Object input) {
if (input == null) {
return null;
} else {
return ((ShardingQueryAssistedEncryptor) shardingEncryptor.get()).queryAssistedEncrypt(input.toString());
}
return null == input ? null : ((ShardingQueryAssistedEncryptor) shardingEncryptor.get()).queryAssistedEncrypt(input.toString());
}
});
}
......@@ -255,11 +251,7 @@ public final class EncryptRule implements BaseRule {
@Override
public Object apply(final Object input) {
if (input == null) {
return null;
} else {
return String.valueOf(shardingEncryptor.get().encrypt(input.toString()));
}
return null == input ? null : String.valueOf(shardingEncryptor.get().encrypt(input.toString()));
}
});
}
......
......@@ -30,43 +30,38 @@ import java.util.Properties;
import static org.junit.Assert.assertNull;
/**
* @author kezhenxu94
*/
public class EncryptRuleTest {
public final class EncryptRuleTest {
private final String table = "table";
private final String column = "column";
private EncryptRuleConfiguration encryptRuleConfig;
@Before
public void before() {
public void setUp() {
Properties props = new Properties();
EncryptorRuleConfiguration encryptorConfig = new EncryptorRuleConfiguration("assistedTest", props);
EncryptColumnRuleConfiguration columnConfig = new EncryptColumnRuleConfiguration("plain_pwd", "cipher_pwd", "", "aes");
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(Collections.singletonMap(column, columnConfig));
encryptRuleConfig = new EncryptRuleConfiguration();
encryptRuleConfig.getEncryptors().put("aes", encryptorConfig);
encryptRuleConfig.getTables().put(table, tableConfig);
}
@Test
public void testGetEncryptAssistedQueryValues() {
public void assertGetEncryptAssistedQueryValues() {
List<Object> encryptAssistedQueryValues = new EncryptRule(encryptRuleConfig).getEncryptAssistedQueryValues(table, column, Collections.singletonList(null));
for (final Object value : encryptAssistedQueryValues) {
assertNull(value);
}
}
@Test
public void testGetEncryptValues() {
public void assertGetEncryptValues() {
List<Object> encryptAssistedQueryValues = new EncryptRule(encryptRuleConfig).getEncryptValues(table, column, Collections.singletonList(null));
for (final Object value : encryptAssistedQueryValues) {
assertNull(value);
}
}
}
\ No newline at end of file
}
......@@ -59,7 +59,7 @@ public final class TableAssert {
}
}
// TODO:yanan remove this method and make sure the table number of xml is correct
// TODO yanan remove this method and make sure the table number of xml is correct
private Collection<TableSegment> mergeTableSegments(final Collection<TableSegment> actual) {
Collection<TableSegment> result = new LinkedList<>();
Set<String> tableNames = new HashSet<>(actual.size(), 1);
......@@ -71,7 +71,7 @@ public final class TableAssert {
return result;
}
// TODO:yanan remove this method and make sure the seq of xml is correct
// TODO yanan remove this method and make sure the seq of xml is correct
private Map<String, ExpectedTable> getExpectedMap(final List<ExpectedTable> expected) {
Map<String, ExpectedTable> result = new HashMap<>(expected.size(), 1);
for (ExpectedTable each : expected) {
......
......@@ -67,13 +67,12 @@ public final class TableBroadcastRoutingEngineTest {
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration("t_order", "ds${0..1}.t_order_${0..2}");
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, Arrays.asList("ds0", "ds1"));
when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
when(tablesContext.getTableNames()).thenReturn(Lists.newArrayList("t_order"));
when(tableMetas.getAllTableNames()).thenReturn(Lists.newArrayList("t_order"));
when(tableMetas.get("t_order")).thenReturn(tableMetaData);
when(tableMetaData.containsIndex("index_name")).thenReturn(true);
tableBroadcastRoutingEngine = new TableBroadcastRoutingEngine(shardingRule, tableMetas, sqlStatementContext);
tableBroadcastRoutingEngine = new TableBroadcastRoutingEngine(new ShardingRule(shardingRuleConfig, Arrays.asList("ds0", "ds1")), tableMetas, sqlStatementContext);
}
@Test
......
......@@ -180,7 +180,7 @@ public abstract class BaseIT {
for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
SchemaEnvironmentManager.createDatabase(each);
}
} catch (final Exception ex) {
} catch (final JAXBException | IOException | SQLException ex) {
ex.printStackTrace();
}
}
......@@ -190,7 +190,7 @@ public abstract class BaseIT {
for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
SchemaEnvironmentManager.createTable(each);
}
} catch (final Exception ex) {
} catch (final JAXBException | IOException | SQLException ex) {
ex.printStackTrace();
}
}
......@@ -200,7 +200,7 @@ public abstract class BaseIT {
for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
SchemaEnvironmentManager.dropDatabase(each);
}
} catch (final Exception ex) {
} catch (final JAXBException | IOException ex) {
ex.printStackTrace();
}
}
......@@ -210,7 +210,7 @@ public abstract class BaseIT {
for (String each : integrateTestEnvironment.getShardingRuleTypes()) {
SchemaEnvironmentManager.dropTable(each);
}
} catch (final Exception ex) {
} catch (final JAXBException | IOException ex) {
ex.printStackTrace();
}
}
......
......@@ -112,7 +112,7 @@ public final class ResultSetUtil {
case "java.lang.String":
return value.toString();
default:
throw new ShardingException("Unsupported data type:%s", convertType);
throw new ShardingException("Unsupported data type: %s", convertType);
}
}
......@@ -128,7 +128,7 @@ public final class ResultSetUtil {
case "java.lang.String":
return date.toString();
default:
throw new ShardingException("Unsupported Date type:%s", convertType);
throw new ShardingException("Unsupported Date type: %s", convertType);
}
}
......
......@@ -18,6 +18,7 @@
package org.apache.shardingsphere.shardingjdbc.jdbc.adapter;
import org.apache.shardingsphere.core.database.DatabaseTypes;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.shardingjdbc.common.base.AbstractShardingJDBCDatabaseAndTableTest;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection;
import org.apache.shardingsphere.shardingjdbc.jdbc.util.JDBCTestSQL;
......@@ -221,127 +222,127 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
}
@Test
public void assertGetBytesForColumnIndex() {
public void assertGetBytesForColumnIndex() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
assertTrue(each.getBytes(1).length > 0);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetBytesForColumnLabel() {
public void assertGetBytesForColumnLabel() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
assertTrue(each.getBytes(columnName).length > 0);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetDateForColumnIndex() {
public void assertGetDateForColumnIndex() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getDate(1);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetDateForColumnLabel() {
public void assertGetDateForColumnLabel() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getDate(columnName);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetDateColumnIndexWithCalendar() {
public void assertGetDateColumnIndexWithCalendar() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getDate(1, Calendar.getInstance());
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetDateColumnLabelWithCalendar() {
public void assertGetDateColumnLabelWithCalendar() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getDate(columnName, Calendar.getInstance());
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimeForColumnIndex() {
public void assertGetTimeForColumnIndex() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getTime(1);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimeForColumnLabel() {
public void assertGetTimeForColumnLabel() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getTime(columnName);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimeColumnIndexWithCalendar() {
public void assertGetTimeColumnIndexWithCalendar() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getTime(1, Calendar.getInstance());
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimeColumnLabelWithCalendar() {
public void assertGetTimeColumnLabelWithCalendar() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getTime(columnName, Calendar.getInstance());
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimestampForColumnIndex() {
public void assertGetTimestampForColumnIndex() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
each.getValue().getTimestamp(1);
......@@ -349,14 +350,14 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
continue;
}
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimestampForColumnLabel() {
public void assertGetTimestampForColumnLabel() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
each.getValue().getTimestamp(columnName);
......@@ -364,14 +365,14 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
continue;
}
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimestampColumnIndexWithCalendar() {
public void assertGetTimestampColumnIndexWithCalendar() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
each.getValue().getTimestamp(1, Calendar.getInstance());
......@@ -379,14 +380,14 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
continue;
}
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetTimestampColumnLabelWithCalendar() {
public void assertGetTimestampColumnLabelWithCalendar() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
each.getValue().getTimestamp(columnName, Calendar.getInstance());
......@@ -394,7 +395,7 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
continue;
}
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
} catch (final ShardingException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
......@@ -433,7 +434,7 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
if (DatabaseTypes.getActualDatabaseType("H2") == each.getKey() || DatabaseTypes.getActualDatabaseType("SQLServer") == each.getKey()) {
try {
each.getValue().getUnicodeStream(1).read(b);
} catch (final Exception ignored) {
} catch (final ShardingException ignored) {
}
} else {
each.getValue().getUnicodeStream(1).read(b);
......@@ -453,7 +454,7 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
if (DatabaseTypes.getActualDatabaseType("H2") == each.getKey() || DatabaseTypes.getActualDatabaseType("SQLServer") == each.getKey()) {
try {
each.getValue().getUnicodeStream(columnName).read(b);
} catch (final Exception ignored) {
} catch (final ShardingException ignored) {
}
} else {
each.getValue().getUnicodeStream(columnName).read(b);
......@@ -503,13 +504,14 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
}
@Test
public void assertGetBlobForColumnIndex() {
public void assertGetBlobForColumnIndex() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
if (DatabaseTypes.getActualDatabaseType("H2") == each.getKey()) {
try {
assertTrue(each.getValue().getBlob(1).length() > 0);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
......@@ -517,13 +519,14 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
}
@Test
public void assertGetBlobForColumnLabel() {
public void assertGetBlobForColumnLabel() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
if (DatabaseTypes.getActualDatabaseType("H2") == each.getKey()) {
try {
assertTrue(each.getValue().getBlob(columnName).length() > 0);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
......@@ -531,48 +534,52 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
}
@Test
public void assertGetClobForColumnIndex() {
public void assertGetClobForColumnIndex() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
assertThat(each.getValue().getClob(1).getSubString(1, 2), is("10"));
each.getValue().getClob(1);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetClobForColumnLabel() {
public void assertGetClobForColumnLabel() throws SQLException {
for (Entry<DatabaseType, ResultSet> each : resultSets.entrySet()) {
try {
assertThat(each.getValue().getClob(columnName).getSubString(1, 2), is("10"));
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetURLForColumnIndex() {
public void assertGetURLForColumnIndex() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getURL(1);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
}
@Test
public void assertGetURLForColumnLabel() {
public void assertGetURLForColumnLabel() throws SQLException {
for (ResultSet each : resultSets.values()) {
try {
each.getURL(columnName);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
}
......@@ -588,7 +595,8 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
try {
each.getValue().getSQLXML(1);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
} else {
......@@ -607,7 +615,8 @@ public final class ResultSetGetterAdapterTest extends AbstractShardingJDBCDataba
try {
each.getValue().getSQLXML(columnName);
fail("Expected an SQLException to be thrown");
} catch (final Exception ex) {
// TODO need investigate why throw ClassCastException
} catch (final ClassCastException ex) {
assertFalse(ex.getMessage().isEmpty());
}
} else {
......
......@@ -41,7 +41,9 @@ public final class EmbedTestingServer {
}
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
}
......
......@@ -41,7 +41,9 @@ public final class EmbedTestingServer {
}
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
}
......
......@@ -41,7 +41,9 @@ public final class EmbedTestingServer {
}
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
}
......
......@@ -43,7 +43,9 @@ public final class EmbedTestingServer {
}
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
}
......
......@@ -43,7 +43,9 @@ public final class EmbedTestingServer {
}
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册