IDE : Intellij 2020.1.2
Java 8
fluentJDBC - 1.8.5
Below is the sample code I have written to mock the fluent JDBC behavior for any select query
@SpringBootTest
@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(classes = FluentJDBCConfiguration.class)
public class PatientRepositoryTest {
@InjectMocks
private PatientRepository patientRepository;
@Mock
private ObjectMappers objectMappers;
@Mock
private DataSource dataSource;
@Mock
private Query fluentJDBCQuery;
private List<Patient> patientList;
@test
public void getpatientSuccess() throws ParseException, PatientNotFoundException {
Mockito.when(fluentJDBCQuery .select(Mockito.anyString()).listResult(Mockito.any()))
.thenReturn(Collections.singletonList(patientList));
}
Above line always throws error : NULL Pointer exception (as per the notes,due to conn object NULL in PreparedStatementFactory.createSingle method
Even changing to something like below where a valid object mapper is passed :
Mockito.when(fluentJDBCQuery .select(Mockito.anyString()).listResult(patientMapper))
.thenReturn(tasyPatients);
Does result in the same thing.
When i manually set the connection object along with proper query (which i should not be ideally) it still fails in the mockito library
Can you please let me know if there is any predefined way how the fluentJDBC should be injected or change in behavior when integrated with Mockito framework .
Thanks
IDE : Intellij 2020.1.2
Java 8
fluentJDBC - 1.8.5
Below is the sample code I have written to mock the fluent JDBC behavior for any select query
@SpringBootTest
@RunWith(MockitoJUnitRunner.class)
@ContextConfiguration(classes = FluentJDBCConfiguration.class)
public class PatientRepositoryTest {
@test
public void getpatientSuccess() throws ParseException, PatientNotFoundException {
Mockito.when(fluentJDBCQuery .select(Mockito.anyString()).listResult(Mockito.any()))
.thenReturn(Collections.singletonList(patientList));
}
Above line always throws error : NULL Pointer exception (as per the notes,due to conn object NULL in PreparedStatementFactory.createSingle method
Even changing to something like below where a valid object mapper is passed :
Does result in the same thing.
When i manually set the connection object along with proper query (which i should not be ideally) it still fails in the mockito library
Can you please let me know if there is any predefined way how the fluentJDBC should be injected or change in behavior when integrated with Mockito framework .
Thanks