exceptionfactory commented on a change in pull request #4951:
URL: https://github.com/apache/nifi/pull/4951#discussion_r662594551
##########
File path:
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java
##########
@@ -241,6 +243,45 @@ public void testCreateRecord() throws SQLException {
assertEquals(bigDecimal5Value,
record.getValue(COLUMN_NAME_BIG_DECIMAL_5));
}
+ @Test(expected = SQLException.class)
+ public void testCreateSchemaArrayThrowsException() throws SQLException {
+ // given
Review comment:
Although various tests use different approaches, I recommend removing
the given/when/then comments.
##########
File path:
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java
##########
@@ -241,6 +243,45 @@ public void testCreateRecord() throws SQLException {
assertEquals(bigDecimal5Value,
record.getValue(COLUMN_NAME_BIG_DECIMAL_5));
}
+ @Test(expected = SQLException.class)
Review comment:
To provide more precision in testing, the `assertThrows()` method
supports indicating the expected exception on the particular method being
called. In addition, should the expected exception be
`SQLFeatureNotSupportedException`?
##########
File path:
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java
##########
@@ -241,6 +243,45 @@ public void testCreateRecord() throws SQLException {
assertEquals(bigDecimal5Value,
record.getValue(COLUMN_NAME_BIG_DECIMAL_5));
}
+ @Test(expected = SQLException.class)
+ public void testCreateSchemaArrayThrowsException() throws SQLException {
+ // given
+ final List<RecordField> fields = new ArrayList<>();
+ fields.add(new RecordField("column",
RecordFieldType.DECIMAL.getDecimalDataType(30, 10)));
+ final RecordSchema recordSchema = new SimpleRecordSchema(fields);
+ final ResultSet resultSet =
givenResultSetForArrayThrowsException(true);
+
+ // when
+ final ResultSetRecordSet testSubject = new
ResultSetRecordSet(resultSet, recordSchema);
+ }
+
+ @Test
+ public void testCreateSchemaArrayThrowsNotSupportedException() throws
SQLException {
+ // given
+ final List<RecordField> fields = new ArrayList<>();
+ fields.add(new RecordField("column",
RecordFieldType.DECIMAL.getDecimalDataType(30, 10)));
+ final RecordSchema recordSchema = new SimpleRecordSchema(fields);
+ final ResultSet resultSet =
givenResultSetForArrayThrowsException(false);
+
+ // when
+ final ResultSetRecordSet testSubject = new
ResultSetRecordSet(resultSet, recordSchema);
+ final RecordSchema resultSchema = testSubject.getSchema();
+
+ // then
+
assertEquals(RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.STRING.getDataType()),
resultSchema.getField(0).getDataType());
+ }
+
+ private ResultSet givenResultSetForArrayThrowsException(boolean
featureSupported) throws SQLException {
+ final ResultSet resultSet = Mockito.mock(ResultSet.class);
+ final ResultSetMetaData resultSetMetaData =
Mockito.mock(ResultSetMetaData.class);
+ when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
+
when(resultSet.getArray(ArgumentMatchers.anyInt())).thenThrow(featureSupported
? new SQLException("test exception") : new SQLFeatureNotSupportedException("not
supported"));
+ when(resultSetMetaData.getColumnCount()).thenReturn(1);
+ when(resultSetMetaData.getColumnLabel(1)).thenReturn("column");
Review comment:
To avoid unexpected results, passing the column label as a parameteror
using a static variable would be helpful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]