From 67ea8e74385ed22a38c69b66283c78ac707ead9a Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Fri, 10 Jul 2020 13:46:27 -0500 Subject: [PATCH] Fix hello-security-explicit checkstyle --- .../example/HelloSecurityExplicitITests.java | 15 +++--- .../java/example/pages/HomePage.java | 6 ++- .../java/example/pages/LoginPage.java | 8 +++ .../java/example/pages/LogoutConfirmPage.java | 50 +++++++++++-------- 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/HelloSecurityExplicitITests.java b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/HelloSecurityExplicitITests.java index 7c74eb1..7ae9095 100644 --- a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/HelloSecurityExplicitITests.java +++ b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/HelloSecurityExplicitITests.java @@ -22,10 +22,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; + import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; /** + * Integration tests. + * * @author Michael Simons */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -37,27 +40,25 @@ public class HelloSecurityExplicitITests { private int port; @BeforeEach - public void setup() { + void setup() { this.driver = new HtmlUnitDriver(); } @AfterEach - public void tearDown() { + void tearDown() { this.driver.quit(); } @Test - public void login() { + void login() { final LoginPage loginPage = HomePage.to(this.driver, this.port); loginPage.assertAt(); - HomePage homePage = loginPage.loginForm() - .username("user") - .password("password") - .submit(); + HomePage homePage = loginPage.loginForm().username("user").password("password").submit(); homePage.assertAt(); LoginPage logoutSuccess = homePage.logout(); logoutSuccess.assertAt(); } + } diff --git a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/HomePage.java b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/HomePage.java index 3a84e16..1e635cd 100644 --- a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/HomePage.java +++ b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/HomePage.java @@ -23,16 +23,19 @@ import org.openqa.selenium.support.PageFactory; import static org.assertj.core.api.Assertions.assertThat; /** + * The home page. + * * @author Michael Simons */ public class HomePage { + private final WebDriver webDriver; @FindBy(id = "logout") private WebElement logout; public static LoginPage to(WebDriver driver, int port) { - driver.get("http://localhost:" + port +"/"); + driver.get("http://localhost:" + port + "/"); return PageFactory.initElements(driver, LoginPage.class); } @@ -49,4 +52,5 @@ public class HomePage { this.logout.click(); return PageFactory.initElements(this.webDriver, LogoutConfirmPage.class).logout(); } + } diff --git a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LoginPage.java b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LoginPage.java index 3214c7b..60e0b3d 100644 --- a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LoginPage.java +++ b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LoginPage.java @@ -23,6 +23,8 @@ import org.openqa.selenium.support.PageFactory; import static org.assertj.core.api.Assertions.assertThat; /** + * The login page. + * * @author Michael Simons */ public class LoginPage { @@ -46,9 +48,13 @@ public class LoginPage { } public static class LoginForm { + private WebDriver webDriver; + private WebElement username; + private WebElement password; + @FindBy(css = "button[type=submit]") private WebElement submit; @@ -70,5 +76,7 @@ public class LoginPage { this.submit.click(); return PageFactory.initElements(this.webDriver, HomePage.class); } + } + } diff --git a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LogoutConfirmPage.java b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LogoutConfirmPage.java index fc32845..8e85e74 100644 --- a/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LogoutConfirmPage.java +++ b/servlet/spring-boot/java/hello-security-explicit/src/integTest/java/example/pages/LogoutConfirmPage.java @@ -21,33 +21,41 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; +/** + * The log out confirmation page. + * @author Rob Winch + */ public class LogoutConfirmPage { - private final WebDriver webDriver; + private final WebDriver webDriver; - private final LogoutConfirmPage.LogoutForm logoutForm; + private final LogoutConfirmPage.LogoutForm logoutForm; - public LogoutConfirmPage(WebDriver webDriver) { - this.webDriver = webDriver; - this.logoutForm = PageFactory.initElements(this.webDriver, LogoutForm.class); - } + public LogoutConfirmPage(WebDriver webDriver) { + this.webDriver = webDriver; + this.logoutForm = PageFactory.initElements(this.webDriver, LogoutForm.class); + } - public LoginPage logout() { - return this.logoutForm.logout(); - } + public LoginPage logout() { + return this.logoutForm.logout(); + } - public static class LogoutForm { - private WebDriver webDriver; - @FindBy(css = "button[type=submit]") - private WebElement submit; + public static class LogoutForm { - public LogoutForm(WebDriver webDriver) { - this.webDriver = webDriver; - } + private WebDriver webDriver; + + @FindBy(css = "button[type=submit]") + private WebElement submit; + + public LogoutForm(WebDriver webDriver) { + this.webDriver = webDriver; + } + + public LoginPage logout() { + this.submit.click(); + return PageFactory.initElements(this.webDriver, LoginPage.class); + } + + } - public LoginPage logout() { - this.submit.click(); - return PageFactory.initElements(this.webDriver, LoginPage.class); - } - } }