Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shobithpejathaya opened this issue Jul 29, 2020 · 1 comment

Comments

@shobithpejathaya
Copy link

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

@zsoltherpai
Copy link
Owner

zsoltherpai commented Jul 29, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants