From aa0c61491288caba91004041abc86c9b7a7f8e10 Mon Sep 17 00:00:00 2001 From: Dmitry Zaytsev Date: Wed, 21 Jun 2017 13:00:36 +0200 Subject: [PATCH] Ignoring query parameters in URL --- .../java/com/car2go/endpoint2mock/Registry.java | 6 +++++- .../com/car2go/endpoint2mock/RegistryTest.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/endpoint2mock/src/main/java/com/car2go/endpoint2mock/Registry.java b/endpoint2mock/src/main/java/com/car2go/endpoint2mock/Registry.java index e43d096..ad463a9 100644 --- a/endpoint2mock/src/main/java/com/car2go/endpoint2mock/Registry.java +++ b/endpoint2mock/src/main/java/com/car2go/endpoint2mock/Registry.java @@ -60,7 +60,11 @@ public boolean isInRegistry(String url) { private static boolean endpointMatches(String mockedEndpoint, String url) { String regEx = toRegEx(mockedEndpoint); - return url.matches(".*" + regEx); + return url.matches(".*" + regEx + queryArguments()); + } + + private static String queryArguments() { + return "(\\?.*)?"; } private static String toRegEx(String mockedEndpoint) { diff --git a/endpoint2mock/src/test/java/com/car2go/endpoint2mock/RegistryTest.java b/endpoint2mock/src/test/java/com/car2go/endpoint2mock/RegistryTest.java index e4eade2..25e34e9 100644 --- a/endpoint2mock/src/test/java/com/car2go/endpoint2mock/RegistryTest.java +++ b/endpoint2mock/src/test/java/com/car2go/endpoint2mock/RegistryTest.java @@ -44,6 +44,21 @@ public void inRegistry_Yes_PathParameters() throws Exception { assertTrue(result); } + @Test + public void inRegistry_Yes_QueryParameters() throws Exception { + // Given + MocksRegistry.setRegistry(new HashSet<>(asList( + "/path3/path4", + "/path1/path2" + ))); + + // When + boolean result = testee.isInRegistry("http://example.com/path3/path4?someArg=a&otherArg=b"); + + // Then + assertTrue(result); + } + @Test public void inRegistry_No() throws Exception { // Given