From 62de505e439617bd7419c310e26baf38a5be0523 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 10 Mar 2017 09:45:10 +0000 Subject: [PATCH] Update tests to align with slight change in HtmlUnit's behaviour See gh-8515 --- ...lHostWebConnectionHtmlUnitDriverTests.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java index b618de2ce9..ade28caf81 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,12 @@ import java.net.URL; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebClientOptions; +import com.gargoylesoftware.htmlunit.WebRequest; +import com.gargoylesoftware.htmlunit.WebWindow; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openqa.selenium.Capabilities; @@ -31,6 +34,8 @@ import org.openqa.selenium.Capabilities; import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -92,7 +97,8 @@ public class LocalHostWebConnectionHtmlUnitDriverTests { LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver( environment); driver.get("/test"); - verify(this.webClient).getPage(new URL("http://localhost:8080/test")); + verify(this.webClient).getPage(any(WebWindow.class), + requestToUrl(new URL("http://localhost:8080/test"))); } @Test @@ -102,7 +108,12 @@ public class LocalHostWebConnectionHtmlUnitDriverTests { LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver( environment); driver.get("/test"); - verify(this.webClient).getPage(new URL("http://localhost:8181/test")); + verify(this.webClient).getPage(any(WebWindow.class), + requestToUrl(new URL("http://localhost:8181/test"))); + } + + private WebRequest requestToUrl(URL url) { + return argThat(new WebRequestUrlArgumentMatcher(url)); } public class TestLocalHostWebConnectionHtmlUnitDriver @@ -119,4 +130,20 @@ public class LocalHostWebConnectionHtmlUnitDriverTests { } + private static final class WebRequestUrlArgumentMatcher + implements ArgumentMatcher { + + private final URL expectedUrl; + + private WebRequestUrlArgumentMatcher(URL expectedUrl) { + this.expectedUrl = expectedUrl; + } + + @Override + public boolean matches(WebRequest argument) { + return argument.getUrl().equals(this.expectedUrl); + } + + } + }