Hi Team, I am very new to WireMock and tried setti...
# wiremock-java
s
Hi Team, I am very new to WireMock and tried setting up my wiremockserver integrated with JUnit not as a standalone server. Everything in the configuration seems to be fine. But when I run the test class annotated with WireMockTest I am getting IndexOutofboundexception and the stack trace shows its while starting the WireMockserver. May be this can be a very basic question but could not find any way out of it so posting it here. Can anyone please help me through this
t
Can you post your code and the full error/output you’re seeing?
s
In our present project we are using JUnit 5 and I have used the same example WireMock website has for JUnit5
Sample code:
@WireMockTest(httpPort = 8081)
public class MockTestClass{
@Test
void testBasicFlow(){
System.out.println("WireMock is running");
}
The error I am seeing while running the test method is
Copy code
Index 0 out of bounds for length 0
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at Objects.checkIndex
at ArrayList.get
at HttpServerFactoryLoader.pickMostAppropriateFrom
at HttpServerFactoryLoader.load
at WireMockServer.getHttpServerFactory
at WireMockExtension.startServerIfRequired
at WireMockExtension.beforeAll
at ArrayList.forEach
t
Are you using WireMock 3.10.0? And can you share the snippet from your build that’s including the dependency?
s
Yes I am using WireMock 3.10.0 and WireMock-junit5 JARs from groups org.wiremock, ru.lanwen.wiremock and yes I see them these JARs added into my External Libraries. Sorry Tom I will not be able to share any snippets from my build due to organization standards, so was just updating without providing evidence. Do you suspect its because the dependencies not included
t
That error suggests it can’t find an HTTP server to load. Clearly it’s a bug as it should never reach this point, but I need to be able to replicate the setup (and classpath in particular) that produced this outcome if I’m going to be able to fix it. Do you have Jetty 12 on the classpath by any chance? If you do, then switching to wiremock-jetty12 should fix the issue.
I’ve just spotted that you’ve got the
ru.lanwen
package in there. I suggest getting rid of this as it’s been made obsolete by WireMock’s own JUnit 5 support and it’s probably pulling in some old dependencies.
s
I have removed both the dependencies added jetty 12 and it was working fine. I was able to start the MockServer. Thank you for the help. Also to add to before scenario even before adding the dependency from ru.lanwen package I was seeing the same issue. To give you complete details on my project I was using the above mentioned dependencies, my project has both JUnit 4 and 5
Hey Tom I have tried putting just the Wiremock-3.10 and see the IndexOutOfBounds exception again.
t
Can you share a project that reproduces this?
s
Sure Tom will be sharing it soon