Skip to content

Commit cbf8605

Browse files
committed
added try/catch for successful FieldWriters tests.
1 parent 372e150 commit cbf8605

File tree

12 files changed

+315
-203
lines changed

12 files changed

+315
-203
lines changed

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/BigIntFieldWriterTest.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertFalse;
3535
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
3637
import static org.mockito.ArgumentMatchers.any;
3738
import static org.mockito.Mockito.mock;
3839
import static org.mockito.Mockito.verify;
@@ -73,15 +74,19 @@ private void verifyAssertions(boolean expectedResult, boolean actualResult) {
7374
}
7475

7576
@Test
76-
public void write_withValidBigIntValue_shouldWriteSuccessfully() throws Exception {
77-
when(mockConstraintProjector.apply(12345L)).thenReturn(true);
78-
configureBigIntExtractor(mockExtractor, expectedValue, 1);
79-
80-
boolean result = bigIntFieldWriter.write(new Object(), 0);
81-
82-
verifyAssertions(true, result);
83-
verify(mockExtractor).extract(any(), any(NullableBigIntHolder.class));
84-
verify(mockConstraintProjector).apply(expectedValue);
77+
public void write_withValidBigIntValue_shouldWriteSuccessfully() {
78+
try {
79+
when(mockConstraintProjector.apply(12345L)).thenReturn(true);
80+
configureBigIntExtractor(mockExtractor, expectedValue, 1);
81+
82+
boolean result = bigIntFieldWriter.write(new Object(), 0);
83+
84+
verifyAssertions(true, result);
85+
verify(mockExtractor).extract(any(), any(NullableBigIntHolder.class));
86+
verify(mockConstraintProjector).apply(expectedValue);
87+
} catch (Exception e) {
88+
fail("Unexpected exception in test: " + e.getMessage());
89+
}
8590
}
8691

8792
@Test
@@ -97,14 +102,18 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception {
97102
}
98103

99104
@Test
100-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception {
101-
bigIntFieldWriter = new BigIntFieldWriter(mockExtractor, vector, null);
102-
configureBigIntExtractor(mockExtractor, expectedValue, 1);
103-
104-
boolean result = bigIntFieldWriter.write(new Object(), 0);
105-
106-
verifyAssertions(true, result);
107-
verify(mockExtractor).extract(any(), any(NullableBigIntHolder.class));
105+
public void write_withoutConstraints_shouldWriteSuccessfully() {
106+
try {
107+
bigIntFieldWriter = new BigIntFieldWriter(mockExtractor, vector, null);
108+
configureBigIntExtractor(mockExtractor, expectedValue, 1);
109+
110+
boolean result = bigIntFieldWriter.write(new Object(), 0);
111+
112+
verifyAssertions(true, result);
113+
verify(mockExtractor).extract(any(), any(NullableBigIntHolder.class));
114+
} catch (Exception e) {
115+
fail("Unexpected exception in test: " + e.getMessage());
116+
}
108117
}
109118

110119
@Test

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/BitFieldWriterTest.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertFalse;
3535
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
3637
import static org.mockito.ArgumentMatchers.any;
3738
import static org.mockito.Mockito.mock;
3839
import static org.mockito.Mockito.times;
@@ -78,29 +79,37 @@ private void verifyAssertions(boolean expectedResult, int expectedValue, boolean
7879
}
7980

8081
@Test
81-
public void write_withValidTrueBitValue_shouldWriteSuccessfully() throws Exception
82+
public void write_withValidTrueBitValue_shouldWriteSuccessfully()
8283
{
83-
when(mockConstraintProjector.apply(true)).thenReturn(true);
84-
configureBitExtractor(mockExtractor, trueBit, 1);
85-
86-
boolean result = bitFieldWriter.write(new Object(), 0);
87-
88-
verifyAssertions(true, trueBit, result);
89-
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
90-
verify(mockConstraintProjector, times(1)).apply(true);
84+
try {
85+
when(mockConstraintProjector.apply(true)).thenReturn(true);
86+
configureBitExtractor(mockExtractor, trueBit, 1);
87+
88+
boolean result = bitFieldWriter.write(new Object(), 0);
89+
90+
verifyAssertions(true, trueBit, result);
91+
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
92+
verify(mockConstraintProjector, times(1)).apply(true);
93+
} catch (Exception e) {
94+
fail("Unexpected exception in test: " + e.getMessage());
95+
}
9196
}
9297

9398
@Test
94-
public void write_withValidFalseBitValue_shouldWriteSuccessfully() throws Exception
99+
public void write_withValidFalseBitValue_shouldWriteSuccessfully()
95100
{
96-
when(mockConstraintProjector.apply(false)).thenReturn(true);
97-
configureBitExtractor(mockExtractor, falseBit, 1);
98-
99-
boolean result = bitFieldWriter.write(new Object(), 0);
100-
101-
verifyAssertions(true, falseBit, result);
102-
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
103-
verify(mockConstraintProjector, times(1)).apply(false);
101+
try {
102+
when(mockConstraintProjector.apply(false)).thenReturn(true);
103+
configureBitExtractor(mockExtractor, falseBit, 1);
104+
105+
boolean result = bitFieldWriter.write(new Object(), 0);
106+
107+
verifyAssertions(true, falseBit, result);
108+
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
109+
verify(mockConstraintProjector, times(1)).apply(false);
110+
} catch (Exception e) {
111+
fail("Unexpected exception in test: " + e.getMessage());
112+
}
104113
}
105114

106115
@Test
@@ -117,15 +126,19 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception
117126
}
118127

119128
@Test
120-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception
129+
public void write_withoutConstraints_shouldWriteSuccessfully()
121130
{
122-
bitFieldWriter = new BitFieldWriter(mockExtractor, vector, null);
123-
configureBitExtractor(mockExtractor, falseBit, 1);
131+
try {
132+
bitFieldWriter = new BitFieldWriter(mockExtractor, vector, null);
133+
configureBitExtractor(mockExtractor, falseBit, 1);
124134

125-
boolean result = bitFieldWriter.write(new Object(), 0);
135+
boolean result = bitFieldWriter.write(new Object(), 0);
126136

127-
verifyAssertions(true, falseBit, result);
128-
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
137+
verifyAssertions(true, falseBit, result);
138+
verify(mockExtractor, times(1)).extract(any(), any(NullableBitHolder.class));
139+
} catch (Exception e) {
140+
fail("Unexpected exception in test: " + e.getMessage());
141+
}
129142
}
130143

131144
@Test

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/DateDayFieldWriterTest.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertFalse;
3535
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
3637
import static org.mockito.ArgumentMatchers.any;
3738
import static org.mockito.Mockito.mock;
3839
import static org.mockito.Mockito.times;
@@ -77,16 +78,20 @@ private void verifyAssertions(boolean expectedResult, boolean actualResult)
7778
}
7879

7980
@Test
80-
public void write_withValidDateDayValue_shouldWriteSuccessfully() throws Exception
81+
public void write_withValidDateDayValue_shouldWriteSuccessfully()
8182
{
82-
configureDateDayExtractor(mockExtractor, expectedEpochDays, 1);
83-
when(mockConstraintProjector.apply(expectedEpochDays)).thenReturn(true);
84-
85-
boolean result = dateDayFieldWriter.write(new Object(), 0);
86-
87-
verifyAssertions(true, result);
88-
verify(mockExtractor, times(1)).extract(any(), any(NullableDateDayHolder.class));
89-
verify(mockConstraintProjector, times(1)).apply(expectedEpochDays);
83+
try {
84+
configureDateDayExtractor(mockExtractor, expectedEpochDays, 1);
85+
when(mockConstraintProjector.apply(expectedEpochDays)).thenReturn(true);
86+
87+
boolean result = dateDayFieldWriter.write(new Object(), 0);
88+
89+
verifyAssertions(true, result);
90+
verify(mockExtractor, times(1)).extract(any(), any(NullableDateDayHolder.class));
91+
verify(mockConstraintProjector, times(1)).apply(expectedEpochDays);
92+
} catch (Exception e) {
93+
fail("Unexpected exception in test: " + e.getMessage());
94+
}
9095
}
9196

9297
@Test
@@ -103,16 +108,20 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception
103108
}
104109

105110
@Test
106-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception
111+
public void write_withoutConstraints_shouldWriteSuccessfully()
107112
{
108-
dateDayFieldWriter = new DateDayFieldWriter(mockExtractor, vector, null);
113+
try {
114+
dateDayFieldWriter = new DateDayFieldWriter(mockExtractor, vector, null);
109115

110-
configureDateDayExtractor(mockExtractor, expectedEpochDays, 1);
116+
configureDateDayExtractor(mockExtractor, expectedEpochDays, 1);
111117

112-
boolean result = dateDayFieldWriter.write(new Object(), 0);
118+
boolean result = dateDayFieldWriter.write(new Object(), 0);
113119

114-
verifyAssertions(true, result);
115-
verify(mockExtractor, times(1)).extract(any(), any(NullableDateDayHolder.class));
120+
verifyAssertions(true, result);
121+
verify(mockExtractor, times(1)).extract(any(), any(NullableDateDayHolder.class));
122+
} catch (Exception e) {
123+
fail("Unexpected exception in test: " + e.getMessage());
124+
}
116125
}
117126

118127
@Test

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/DateMilliFieldWriterTest.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.junit.Assert.assertEquals;
3838
import static org.junit.Assert.assertFalse;
3939
import static org.junit.Assert.assertTrue;
40+
import static org.junit.Assert.fail;
4041
import static org.mockito.ArgumentMatchers.any;
4142
import static org.mockito.Mockito.mock;
4243
import static org.mockito.Mockito.times;
@@ -80,15 +81,19 @@ private void verifyAssertions(boolean expectedResult, boolean actualResult) {
8081
}
8182

8283
@Test
83-
public void write_withValidDateMilliValue_shouldWriteSuccessfully() throws Exception {
84-
when(mockConstraintProjector.apply(expectedDate)).thenReturn(true);
85-
configureDateMilliExtractor(mockExtractor, expectedEpochMilliseconds, 1);
86-
87-
boolean result = dateMilliFieldWriter.write(new Object(), 0);
88-
89-
verifyAssertions(true, result);
90-
verify(mockExtractor, times(1)).extract(any(), any(NullableDateMilliHolder.class));
91-
verify(mockConstraintProjector, times(1)).apply(expectedDate);
84+
public void write_withValidDateMilliValue_shouldWriteSuccessfully() {
85+
try {
86+
when(mockConstraintProjector.apply(expectedDate)).thenReturn(true);
87+
configureDateMilliExtractor(mockExtractor, expectedEpochMilliseconds, 1);
88+
89+
boolean result = dateMilliFieldWriter.write(new Object(), 0);
90+
91+
verifyAssertions(true, result);
92+
verify(mockExtractor, times(1)).extract(any(), any(NullableDateMilliHolder.class));
93+
verify(mockConstraintProjector, times(1)).apply(expectedDate);
94+
} catch (Exception e) {
95+
fail("Unexpected exception in test: " + e.getMessage());
96+
}
9297
}
9398

9499
@Test
@@ -104,14 +109,18 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception {
104109
}
105110

106111
@Test
107-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception {
108-
dateMilliFieldWriter = new DateMilliFieldWriter(mockExtractor, vector, null);
109-
configureDateMilliExtractor(mockExtractor, expectedEpochMilliseconds, 1);
110-
111-
boolean result = dateMilliFieldWriter.write(new Object(), 0);
112-
113-
verifyAssertions(true, result);
114-
verify(mockExtractor, times(1)).extract(any(), any(NullableDateMilliHolder.class));
112+
public void write_withoutConstraints_shouldWriteSuccessfully() {
113+
try {
114+
dateMilliFieldWriter = new DateMilliFieldWriter(mockExtractor, vector, null);
115+
configureDateMilliExtractor(mockExtractor, expectedEpochMilliseconds, 1);
116+
117+
boolean result = dateMilliFieldWriter.write(new Object(), 0);
118+
119+
verifyAssertions(true, result);
120+
verify(mockExtractor, times(1)).extract(any(), any(NullableDateMilliHolder.class));
121+
} catch (Exception e) {
122+
fail("Unexpected exception in test: " + e.getMessage());
123+
}
115124
}
116125

117126
@Test

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/DecimalFieldWriterTest.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,19 @@ private void verifyAssertions(boolean expectedResult, boolean actualResult) {
7878
}
7979

8080
@Test
81-
public void write_withValidDecimalValue_shouldWriteSuccessfully() throws Exception {
82-
when(mockConstraintProjector.apply(actualValue)).thenReturn(true);
83-
configureDecimalExtractor(mockExtractor, actualValue, 1);
81+
public void write_withValidDecimalValue_shouldWriteSuccessfully() {
82+
try {
83+
when(mockConstraintProjector.apply(actualValue)).thenReturn(true);
84+
configureDecimalExtractor(mockExtractor, actualValue, 1);
8485

85-
boolean result = decimalFieldWriter.write(new Object(), 0);
86+
boolean result = decimalFieldWriter.write(new Object(), 0);
8687

87-
verifyAssertions(true, result);
88-
verify(mockExtractor, times(1)).extract(any(), any(NullableDecimalHolder.class));
89-
verify(mockConstraintProjector, times(1)).apply(actualValue);
88+
verifyAssertions(true, result);
89+
verify(mockExtractor, times(1)).extract(any(), any(NullableDecimalHolder.class));
90+
verify(mockConstraintProjector, times(1)).apply(actualValue);
91+
} catch (Exception e) {
92+
fail("Unexpected exception in test: " + e.getMessage());
93+
}
9094
}
9195

9296
@Test
@@ -102,14 +106,18 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception {
102106
}
103107

104108
@Test
105-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception {
106-
decimalFieldWriter = new DecimalFieldWriter(mockExtractor, vector, null);
107-
configureDecimalExtractor(mockExtractor, actualValue, 1);
109+
public void write_withoutConstraints_shouldWriteSuccessfully() {
110+
try {
111+
decimalFieldWriter = new DecimalFieldWriter(mockExtractor, vector, null);
112+
configureDecimalExtractor(mockExtractor, actualValue, 1);
108113

109-
boolean result = decimalFieldWriter.write(new Object(), 0);
114+
boolean result = decimalFieldWriter.write(new Object(), 0);
110115

111-
verifyAssertions(true, result);
112-
verify(mockExtractor, times(1)).extract(any(), any(NullableDecimalHolder.class));
116+
verifyAssertions(true, result);
117+
verify(mockExtractor, times(1)).extract(any(), any(NullableDecimalHolder.class));
118+
} catch (Exception e) {
119+
fail("Unexpected exception in test: " + e.getMessage());
120+
}
113121
}
114122

115123
@Test

athena-federation-sdk/src/test/java/com/amazonaws/athena/connector/lambda/data/writers/fieldwriters/Float4FieldWriterTest.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertFalse;
3535
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
3637
import static org.mockito.ArgumentMatchers.any;
3738
import static org.mockito.Mockito.mock;
3839
import static org.mockito.Mockito.times;
@@ -75,15 +76,19 @@ private void verifyAssertions(boolean expectedResult, boolean actualResult) {
7576
}
7677

7778
@Test
78-
public void write_withValidFloat4Value_shouldWriteSuccessfully() throws Exception {
79-
when(mockConstraintProjector.apply(expectedFloatValue)).thenReturn(true);
80-
configureFloat4Extractor(mockExtractor, expectedFloatValue, 1);
81-
82-
boolean result = float4FieldWriter.write(new Object(), 0);
83-
84-
verifyAssertions(true, result);
85-
verify(mockExtractor, times(1)).extract(any(), any(NullableFloat4Holder.class));
86-
verify(mockConstraintProjector, times(1)).apply(expectedFloatValue);
79+
public void write_withValidFloat4Value_shouldWriteSuccessfully() {
80+
try {
81+
when(mockConstraintProjector.apply(expectedFloatValue)).thenReturn(true);
82+
configureFloat4Extractor(mockExtractor, expectedFloatValue, 1);
83+
84+
boolean result = float4FieldWriter.write(new Object(), 0);
85+
86+
verifyAssertions(true, result);
87+
verify(mockExtractor, times(1)).extract(any(), any(NullableFloat4Holder.class));
88+
verify(mockConstraintProjector, times(1)).apply(expectedFloatValue);
89+
} catch (Exception e) {
90+
fail("Unexpected exception in test: " + e.getMessage());
91+
}
8792
}
8893

8994
@Test
@@ -99,14 +104,18 @@ public void write_withConstraintFailure_shouldReturnFalse() throws Exception {
99104
}
100105

101106
@Test
102-
public void write_withoutConstraints_shouldWriteSuccessfully() throws Exception {
103-
float4FieldWriter = new Float4FieldWriter(mockExtractor, vector, null);
104-
configureFloat4Extractor(mockExtractor, expectedFloatValue, 1);
105-
106-
boolean result = float4FieldWriter.write(new Object(), 0);
107-
108-
verifyAssertions(true, result);
109-
verify(mockExtractor, times(1)).extract(any(), any(NullableFloat4Holder.class));
107+
public void write_withoutConstraints_shouldWriteSuccessfully() {
108+
try {
109+
float4FieldWriter = new Float4FieldWriter(mockExtractor, vector, null);
110+
configureFloat4Extractor(mockExtractor, expectedFloatValue, 1);
111+
112+
boolean result = float4FieldWriter.write(new Object(), 0);
113+
114+
verifyAssertions(true, result);
115+
verify(mockExtractor, times(1)).extract(any(), any(NullableFloat4Holder.class));
116+
} catch (Exception e) {
117+
fail("Unexpected exception in test: " + e.getMessage());
118+
}
110119
}
111120

112121
@Test

0 commit comments

Comments
 (0)