[ 
https://issues.apache.org/jira/browse/SLING-4237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14243212#comment-14243212
 ] 

Stefan Seifert commented on SLING-4237:
---------------------------------------

ah, interesting problem. normally i try to avoid using Mockito.spy and use a 
real mockito-mock in this case, but i assume you example is simplified for 
demonstration.

patch looks fine. by which criteria did you where to add such an exception or 
not? where there are defined in the JCR API (have not cross-checked that)
on some classes e.g. the new MockQuery* classes you did not add them.

> JCR Mock implementation should have "throws RepositoryException"
> ----------------------------------------------------------------
>
>                 Key: SLING-4237
>                 URL: https://issues.apache.org/jira/browse/SLING-4237
>             Project: Sling
>          Issue Type: Bug
>          Components: Testing
>    Affects Versions: Testing JCR Mock 1.1.0
>            Reporter: Julian Sedding
>            Assignee: Julian Sedding
>            Priority: Minor
>              Labels: mocks
>             Fix For: Testing JCR Mock 1.1.2
>
>
> MockSession does not play nice with Mockito. When I run this test
> {code}
> @Test(expected = RepositoryException.class)
> public void pathNotFound() throws RepositoryException {
>       Session session = Mockito.spy(MockJcr.newSession());
>       doThrow(new 
> PathNotFoundException("/foo")).when(session).getNode("/foo");
>       session.getNode("/foo");
> }
> {code}
> the test fails with the following error message:
> {code}
> rootNotFound(a.b.c.impl.JcrTest)  Time elapsed: 0.035 sec  <<< ERROR!
> java.lang.Exception: Unexpected exception, 
> expected<javax.jcr.RepositoryException> but 
> was<org.mockito.exceptions.base.MockitoException>
>       at a.b.c.impl.JcrTest.rootNotFound(JcrTest.java:40)
> {code}
> I found a hint on stackoverflow\[0\] that it is due to the fact that the 
> implementation does not declare any (potentially) thrown exceptions.
> Above test passes when {{MockSession#getRootNode()}} is odified to throw a 
> repositoryException.
> \[0\] 
> http://stackoverflow.com/questions/6647957/mockito-refuses-to-throw-checked-exception



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to