Hi everybody.
I'm having this error too.
This piece of code works well, as my "ExpansionException" must be
thrown when calling "removeStopWords":
@Test(expected = ExpansionException.class)
public void testRemoveStopWords3() throws Exception {
Query q1 = new ElementQuery("with");
Query q2 = new ElementQuery("of");
Query testQuery = new BinaryQuery(Arrays.asList(q1, q2),
BinaryOperator.ANDCrisp);
testQuery.removeStopWords("eng");
}
But, with PowerMock ("SemanticServices.isStopWord" is used inside
"removeStopWords"):
@PrepareForTest(SemanticServices.class)
@Test(expected = ExpansionException.class)
public void testRemoveStopWords3() throws Exception {
PowerMock.mockStaticPartial(SemanticServices.class, "isStopWord");
EasyMock.expect(SemanticServices.isStopWord("with", "eng")).andReturn
(true);
EasyMock.expect(SemanticServices.isStopWord("of", "eng")).andReturn
(true);
PowerMock.replay(SemanticServices.class);
Query q1 = new ElementQuery("with");
Query q2 = new ElementQuery("of");
Query testQuery = new BinaryQuery(Arrays.asList(q1, q2),
BinaryOperator.ANDCrisp);
testQuery.removeStopWords("eng");
}
The result is:
java.lang.RuntimeException: test should never throw an exception to
this level
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters
(MethodRoadie.java:97)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:
84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod
(PowerMockJUnit44RunnerDelegateImpl.java:200)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods
(PowerMockJUnit44RunnerDelegateImpl.java:150)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl
$1.run(PowerMockJUnit44RunnerDelegateImpl.java:124)
at org.junit.internal.runners.ClassRoadie.runUnprotected
(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected
(ClassRoadie.java:44)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run
(PowerMockJUnit44RunnerDelegateImpl.java:122)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run
(JUnit4TestSuiteChunkerImpl.java:89)
at
org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run
(AbstractCommonPowerMockRunner.java:44)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run
(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.java:196)
Hope this can be useful. Thanks.
On Dec 9, 7:16 am, "Johan Haleby" <
johan.hal...@gmail.com> wrote:
> I've experienced this a couple of times but it's always related to something
> else, never the less I think the error message is right, it should never
> happen :). Does the test work in Eclipse or does it fail there as well? In
> that case could you set a break point in class MethodRoadie in JUnit4 where
> indicated below:
> public void runBeforesThenTestThenAfters(Runnable test) {
> try {
> runBefores();
> test.run();
> } catch (FailedBefore e) {
> } catch (Exception e) {
> throw new RuntimeException("test should never throw an exception to
> this level"); // set a breakpoint here.
> } finally {
> runAfters();
> }
> }
>
> and check what the real exception and its stacktrace is (i.e. "e"). Could
> you do this and the post the stacktrace here and I'll see what's going on.
> It might be a bug.
>
> /Johan
>