Skip to content

Commit

Permalink
Fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Nov 25, 2016
1 parent a819414 commit 19ac7e0
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 37 deletions.
Expand Up @@ -28,11 +28,10 @@ public interface FluentJavascriptActions<T> {
T scrollIntoView(boolean alignWithTop);

/**
* Scrolls centrally the current element into the visible area of the browser window, respecting window size.
* Scrolls center of the current element into the visible area of the browser window, respecting window size.
*
* @return this object reference to chain methods calls
* @see <a href="https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView">element.scrollIntoView</a>
*/
T scrollToElement();
T scrollToCenter();
}

Expand Up @@ -43,13 +43,9 @@ public T scrollIntoView(final boolean alignWithTop) {
}

@Override
public T scrollToElement() {
int y = element.get().getElement().getLocation().getY();
this.scrollCentrallyTo(y);
return self;
}

public void scrollCentrallyTo(int y) {
public T scrollToCenter() {
final int y = element.get().getElement().getLocation().getY();
javascript.executeScript("window.scrollTo(0," + y + " - window.innerHeight / 2)", new Object[0]);
return self;
}
}
Expand Up @@ -85,13 +85,13 @@ public static FluentConditions element(final FluentWait wait, final String conte
final Supplier<? extends FluentWebElement> elementSupplier) {
return (FluentConditions) Proxy
.newProxyInstance(MessageProxy.class.getClassLoader(), new Class<?>[] {FluentConditions.class},
new WaitConditionInvocationHandler(FluentConditions.class, wait, context,
new Supplier<FluentConditions>() {
@Override
public FluentConditions get() {
return new WebElementConditions(elementSupplier.get());
}
}));
new WaitConditionInvocationHandler(FluentConditions.class, wait, context,
new Supplier<FluentConditions>() {
@Override
public FluentConditions get() {
return new WebElementConditions(elementSupplier.get());
}
}));
}

/**
Expand Down
Expand Up @@ -17,8 +17,9 @@ public class ParsedUrlTemplate {
/**
* Creates a new url parameters parsed.
*
* @param matches true if matches, false otherwise
* @param parameters parameter values
* @param matches true if matches, false otherwise
* @param parameters parameter values
* @param queryParameters query parameter values
*/
ParsedUrlTemplate(final boolean matches, final Map<String, String> parameters, final List<NameValuePair> queryParameters) {
this.matches = matches;
Expand Down
Expand Up @@ -16,13 +16,13 @@ public class UrlParameter {
private final String match;
private final boolean optional;


/**
* Creates a new parameter
*
* @param name parameter name
* @param group parameter match group
* @param path parameter path
* @param group parameter match group
* @param path parameter path
* @param match parameter matche
* @param optional optional parameter
*/
public UrlParameter(final String name, final String group, final String path, final String match, final boolean optional) {
Expand Down
Expand Up @@ -111,10 +111,11 @@ public UrlTemplate put(final String name, final String value) {
* @param values property properties
* @return {@code this} reference to chain calls
*/
public void addAll(final List<String> values) {
public UrlTemplate addAll(final List<String> values) {
for (final String value : values) {
add(value);
}
return this;
}

/**
Expand All @@ -131,7 +132,7 @@ public UrlTemplate put(final Map<String, String> values) {
/**
* Render the string.
*
* @return
* @return rendered url, based on template with parameters applied.
*/
public String render() {
String rendered = template;
Expand All @@ -145,7 +146,8 @@ public String render() {
buildRenderReplacement(parameter, value == null ? null : String.valueOf(value)));
}

} return rendered;
}
return rendered;
}

private String buildRenderReplacement(final UrlParameter parameter, final String value) {
Expand Down Expand Up @@ -173,13 +175,13 @@ private String buildParsePattern() {
fixedTemplate = fixedTemplate + "/?";
}


for (final UrlParameter parameter : parameters.values()) {
String replacementPattern = "%s([^/]+)";
if (parameter.isOptional()) {
replacementPattern = "(?:" + replacementPattern + ")?";
}
fixedTemplate = fixedTemplate.replaceAll(Pattern.quote(parameter.getMatch()), String.format(replacementPattern, parameter.getPath() == null ? "" : parameter.getPath()));
fixedTemplate = fixedTemplate.replaceAll(Pattern.quote(parameter.getMatch()),
String.format(replacementPattern, parameter.getPath() == null ? "" : parameter.getPath()));
}

return fixedTemplate;
Expand Down
Expand Up @@ -56,7 +56,7 @@ public static String concat(String baseUriSpec, String uriSpec) { // NOPMD Cyclo
*
* @param baseUriSpec base URI
* @param uriSpec current URI
* @return
* @return Sanitized base url
*/
public static String sanitizeBaseUrl(final String baseUriSpec, final String uriSpec) {
if (baseUriSpec == null) {
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class AnnotationConfigurationTest {
ConfigurationProperties.TriggerMode.AUTOMATIC_ON_FAIL, htmlDumpPath = "/html-path", implicitlyWait = 1000,
pageLoadTimeout = 2000, awaitPollingEvery = 10, awaitAtMost = 100, screenshotMode = ConfigurationProperties
.TriggerMode.MANUAL, screenshotPath = "/screenshot-path", scriptTimeout = 3000, webDriver = "firefox", custom =
@CustomProperty(name = "key", value = "value"))
@CustomProperty(name = "key", value = "value"))
public static class ConfiguredClass {
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ public class FluentJavascriptActionsTest {
@Before
public void before() {
when(fluentWebElement.getElement()).thenReturn(element);
when(fluentWebElement.getElement().getLocation()).thenReturn(new Point(1024,768));
when(fluentWebElement.getElement().getLocation()).thenReturn(new Point(1024, 768));
actions = new FluentJavascriptActionsImpl(self, javascript, Suppliers.ofInstance(fluentWebElement));
}

Expand All @@ -50,8 +50,8 @@ public void testWithArgument() {
}

@Test
public void testToElement() {
actions.scrollToElement();
public void testToCenter() {
actions.scrollToCenter();
verify(javascript).executeScript("window.scrollTo(0,768 - window.innerHeight / 2)");
}
}
Expand Up @@ -94,10 +94,10 @@ public static class FluentWebElementContainer {
}

@SuppressWarnings("PMD.FieldDeclarationsShouldBeAtStartOfClass")
private static final FluentWebElement existingElement = mock(FluentWebElement.class);
private static final FluentWebElement EXISTING_ELEMENT = mock(FluentWebElement.class);

public static class ExistingFluentWebElementContainer {
private final FluentWebElement element = existingElement;
private final FluentWebElement element = EXISTING_ELEMENT;
}

public static class FluentWebElementSubClassContainer {
Expand Down Expand Up @@ -168,7 +168,7 @@ public void testExistingFluentWebElement() {

when(webDriver.findElement(any(By.class))).thenReturn(webElement);

assertThat(container.element).isSameAs(existingElement);
assertThat(container.element).isSameAs(EXISTING_ELEMENT);
}

@Test
Expand Down
Expand Up @@ -190,6 +190,8 @@ public void testParseMatchingWithTrailingSlash() {

@Test
public void testDuplicateParameters() {
assertThatThrownBy(() -> new UrlTemplate("/abc/{param1}{?/def/param1}{?/ghi/param3}")).isInstanceOf(IllegalStateException.class).hasMessage("Multiple parameters are defined with the same name (param1).");
assertThatThrownBy(() -> new UrlTemplate("/abc/{param1}{?/def/param1}{?/ghi/param3}"))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Multiple parameters are defined with the same name (param1).");
}
}
@@ -1,7 +1,6 @@
package org.fluentlenium.utils;

import org.assertj.core.api.Assertions;
import org.fluentlenium.integration.util.UrlUtil;
import org.junit.Test;

public class UrlUtilsTest {
Expand Down

0 comments on commit 19ac7e0

Please sign in to comment.