Skip to content

JUnit testing using Mockito : Not able to Inject the fluentJDBC mocks  #79

Description

@shobithpejathaya

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions