how to handle CriteriaBuilder and predicates in junit mockito testcase
up vote
1
down vote
favorite
Impl.java
------------------------------------------------------------------
public List<SearchDTO> findByCriteria(SearchCriteriaDTO SearchCriteriaDTO) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Search> query = builder.createQuery(Search.class);
Root<Search> repls = query.from(Search.class);
final int QUERY_LIMIT = Integer.parseInt(queryLimit);
List<UUID> statusIds = SearchCriteriaDTO.getStatusIds();
if (statusIds != null && !statusIds.isEmpty()) {
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
}
-----------------------------
below is the test class for impl class.
impltest.java
---------------------------
//mocking the services.
@Mock
private SearchMapper SearchMapper;
@Mock
private SearchRepository SearchRepository;
@Mock
private CriteriaBuilder criteriaBuilder;
@Mock
private Root root;
@Mock
private EntityManager entityManager;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
CriteriaQuery<Search> criteriaQuery;
@Mock
Root<UUID> statusId;
@Mock
Path<String> path;
@Mock
Expression expr;
@Mock
Predicate predicate;
@Mock
TypedQuery<Member> querymem;
@Mock
Root<Search> rSearchRootMock;
@InjectMocks
private SearchServiceImpl SearchService;
@Value("${query.limit}")
String queryLimit;
@Before
public void init() {
MockitoAnnotations.initMocks(SearchService);
SearchRootMock = mock(Root.class);
}
@Test
public void test_findby_criteria() {
hen(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); when(criteriaBuilder.createQuery(Search.class)).thenReturn(criteriaQuery);
when(criteriaQuery.from(Search.class)).thenReturn(SearchRootMock);
Path statusIdMock = mock(Path.class);
//when(Integer.parseInt(queryLimit)).thenReturn(1);
String status = "statusId";
Expression<String> doublePath = root.get(status);
when(root.get((status))).thenReturn((Path) doublePath);
when(criteriaBuilder.upper(root.<String>get(status))).thenReturn(expr);
when(criteriaBuilder.equal(expr,status.toUpperCase())).thenReturn(predicate);
when(root.get("statusId")).thenReturn(path);
when(this.SearchService.findByCriteria(SearchCriteriaDTO)).thenReturn(Searches);
here i am trying to mock the predicate but getting null point exception due to root.get("statusId").
please let me know how to mock it.
here are the issues
how to handle and mock the @Value("${query.limit}") where i am reading limit from application properties file.
getting null point exception in predicate line.
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
not able to map the column name here for repl.get("statusId") where getting null.
please help me to solve this problem.Thanks
below is the error
java.lang.NumberFormatException: For input string: "${query.limit}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at com.capturerx.cumulus4.replenishment.impl.ReplenishmentSearchServiceImplTest.test_findby_criteria_for_success(ReplenishmentSearchServiceImplTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
getting java.lang.NullPointerException at line
query.select(replenishments).where(predicates.toArray(new Predicate[predicates.size()]));
unit-testing spring-boot jpa junit mockito
add a comment |
up vote
1
down vote
favorite
Impl.java
------------------------------------------------------------------
public List<SearchDTO> findByCriteria(SearchCriteriaDTO SearchCriteriaDTO) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Search> query = builder.createQuery(Search.class);
Root<Search> repls = query.from(Search.class);
final int QUERY_LIMIT = Integer.parseInt(queryLimit);
List<UUID> statusIds = SearchCriteriaDTO.getStatusIds();
if (statusIds != null && !statusIds.isEmpty()) {
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
}
-----------------------------
below is the test class for impl class.
impltest.java
---------------------------
//mocking the services.
@Mock
private SearchMapper SearchMapper;
@Mock
private SearchRepository SearchRepository;
@Mock
private CriteriaBuilder criteriaBuilder;
@Mock
private Root root;
@Mock
private EntityManager entityManager;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
CriteriaQuery<Search> criteriaQuery;
@Mock
Root<UUID> statusId;
@Mock
Path<String> path;
@Mock
Expression expr;
@Mock
Predicate predicate;
@Mock
TypedQuery<Member> querymem;
@Mock
Root<Search> rSearchRootMock;
@InjectMocks
private SearchServiceImpl SearchService;
@Value("${query.limit}")
String queryLimit;
@Before
public void init() {
MockitoAnnotations.initMocks(SearchService);
SearchRootMock = mock(Root.class);
}
@Test
public void test_findby_criteria() {
hen(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); when(criteriaBuilder.createQuery(Search.class)).thenReturn(criteriaQuery);
when(criteriaQuery.from(Search.class)).thenReturn(SearchRootMock);
Path statusIdMock = mock(Path.class);
//when(Integer.parseInt(queryLimit)).thenReturn(1);
String status = "statusId";
Expression<String> doublePath = root.get(status);
when(root.get((status))).thenReturn((Path) doublePath);
when(criteriaBuilder.upper(root.<String>get(status))).thenReturn(expr);
when(criteriaBuilder.equal(expr,status.toUpperCase())).thenReturn(predicate);
when(root.get("statusId")).thenReturn(path);
when(this.SearchService.findByCriteria(SearchCriteriaDTO)).thenReturn(Searches);
here i am trying to mock the predicate but getting null point exception due to root.get("statusId").
please let me know how to mock it.
here are the issues
how to handle and mock the @Value("${query.limit}") where i am reading limit from application properties file.
getting null point exception in predicate line.
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
not able to map the column name here for repl.get("statusId") where getting null.
please help me to solve this problem.Thanks
below is the error
java.lang.NumberFormatException: For input string: "${query.limit}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at com.capturerx.cumulus4.replenishment.impl.ReplenishmentSearchServiceImplTest.test_findby_criteria_for_success(ReplenishmentSearchServiceImplTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
getting java.lang.NullPointerException at line
query.select(replenishments).where(predicates.toArray(new Predicate[predicates.size()]));
unit-testing spring-boot jpa junit mockito
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Impl.java
------------------------------------------------------------------
public List<SearchDTO> findByCriteria(SearchCriteriaDTO SearchCriteriaDTO) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Search> query = builder.createQuery(Search.class);
Root<Search> repls = query.from(Search.class);
final int QUERY_LIMIT = Integer.parseInt(queryLimit);
List<UUID> statusIds = SearchCriteriaDTO.getStatusIds();
if (statusIds != null && !statusIds.isEmpty()) {
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
}
-----------------------------
below is the test class for impl class.
impltest.java
---------------------------
//mocking the services.
@Mock
private SearchMapper SearchMapper;
@Mock
private SearchRepository SearchRepository;
@Mock
private CriteriaBuilder criteriaBuilder;
@Mock
private Root root;
@Mock
private EntityManager entityManager;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
CriteriaQuery<Search> criteriaQuery;
@Mock
Root<UUID> statusId;
@Mock
Path<String> path;
@Mock
Expression expr;
@Mock
Predicate predicate;
@Mock
TypedQuery<Member> querymem;
@Mock
Root<Search> rSearchRootMock;
@InjectMocks
private SearchServiceImpl SearchService;
@Value("${query.limit}")
String queryLimit;
@Before
public void init() {
MockitoAnnotations.initMocks(SearchService);
SearchRootMock = mock(Root.class);
}
@Test
public void test_findby_criteria() {
hen(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); when(criteriaBuilder.createQuery(Search.class)).thenReturn(criteriaQuery);
when(criteriaQuery.from(Search.class)).thenReturn(SearchRootMock);
Path statusIdMock = mock(Path.class);
//when(Integer.parseInt(queryLimit)).thenReturn(1);
String status = "statusId";
Expression<String> doublePath = root.get(status);
when(root.get((status))).thenReturn((Path) doublePath);
when(criteriaBuilder.upper(root.<String>get(status))).thenReturn(expr);
when(criteriaBuilder.equal(expr,status.toUpperCase())).thenReturn(predicate);
when(root.get("statusId")).thenReturn(path);
when(this.SearchService.findByCriteria(SearchCriteriaDTO)).thenReturn(Searches);
here i am trying to mock the predicate but getting null point exception due to root.get("statusId").
please let me know how to mock it.
here are the issues
how to handle and mock the @Value("${query.limit}") where i am reading limit from application properties file.
getting null point exception in predicate line.
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
not able to map the column name here for repl.get("statusId") where getting null.
please help me to solve this problem.Thanks
below is the error
java.lang.NumberFormatException: For input string: "${query.limit}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at com.capturerx.cumulus4.replenishment.impl.ReplenishmentSearchServiceImplTest.test_findby_criteria_for_success(ReplenishmentSearchServiceImplTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
getting java.lang.NullPointerException at line
query.select(replenishments).where(predicates.toArray(new Predicate[predicates.size()]));
unit-testing spring-boot jpa junit mockito
Impl.java
------------------------------------------------------------------
public List<SearchDTO> findByCriteria(SearchCriteriaDTO SearchCriteriaDTO) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Search> query = builder.createQuery(Search.class);
Root<Search> repls = query.from(Search.class);
final int QUERY_LIMIT = Integer.parseInt(queryLimit);
List<UUID> statusIds = SearchCriteriaDTO.getStatusIds();
if (statusIds != null && !statusIds.isEmpty()) {
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
}
-----------------------------
below is the test class for impl class.
impltest.java
---------------------------
//mocking the services.
@Mock
private SearchMapper SearchMapper;
@Mock
private SearchRepository SearchRepository;
@Mock
private CriteriaBuilder criteriaBuilder;
@Mock
private Root root;
@Mock
private EntityManager entityManager;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
CriteriaQuery<Search> criteriaQuery;
@Mock
Root<UUID> statusId;
@Mock
Path<String> path;
@Mock
Expression expr;
@Mock
Predicate predicate;
@Mock
TypedQuery<Member> querymem;
@Mock
Root<Search> rSearchRootMock;
@InjectMocks
private SearchServiceImpl SearchService;
@Value("${query.limit}")
String queryLimit;
@Before
public void init() {
MockitoAnnotations.initMocks(SearchService);
SearchRootMock = mock(Root.class);
}
@Test
public void test_findby_criteria() {
hen(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); when(criteriaBuilder.createQuery(Search.class)).thenReturn(criteriaQuery);
when(criteriaQuery.from(Search.class)).thenReturn(SearchRootMock);
Path statusIdMock = mock(Path.class);
//when(Integer.parseInt(queryLimit)).thenReturn(1);
String status = "statusId";
Expression<String> doublePath = root.get(status);
when(root.get((status))).thenReturn((Path) doublePath);
when(criteriaBuilder.upper(root.<String>get(status))).thenReturn(expr);
when(criteriaBuilder.equal(expr,status.toUpperCase())).thenReturn(predicate);
when(root.get("statusId")).thenReturn(path);
when(this.SearchService.findByCriteria(SearchCriteriaDTO)).thenReturn(Searches);
here i am trying to mock the predicate but getting null point exception due to root.get("statusId").
please let me know how to mock it.
here are the issues
how to handle and mock the @Value("${query.limit}") where i am reading limit from application properties file.
getting null point exception in predicate line.
predicates.add(builder.and(repl.get("statusId").in(statusIds)));
not able to map the column name here for repl.get("statusId") where getting null.
please help me to solve this problem.Thanks
below is the error
java.lang.NumberFormatException: For input string: "${query.limit}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at com.capturerx.cumulus4.replenishment.impl.ReplenishmentSearchServiceImplTest.test_findby_criteria_for_success(ReplenishmentSearchServiceImplTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
getting java.lang.NullPointerException at line
query.select(replenishments).where(predicates.toArray(new Predicate[predicates.size()]));
unit-testing spring-boot jpa junit mockito
unit-testing spring-boot jpa junit mockito
edited Nov 14 at 8:29
asked Nov 13 at 9:55
Srikanth
92
92
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278296%2fhow-to-handle-criteriabuilder-and-predicates-in-junit-mockito-testcase%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown