Skip to content

Commit

Permalink
chore: General refactoring and fixing minor performance issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jun 2, 2016
1 parent 17e4b33 commit de85892
Show file tree
Hide file tree
Showing 47 changed files with 79 additions and 80 deletions.
Expand Up @@ -12,8 +12,7 @@ public abstract class EnterValue implements Action {

protected final String theText;
protected final List<Keys> followedByKeys;
protected String followedBy;
private final String ENTER_KEYS_INTRO_TEXT = " then hits ";
private static final String ENTER_KEYS_INTRO_TEXT = " then hits ";

public EnterValue(String theText) {
this.theText = theText;
Expand All @@ -22,7 +21,6 @@ public EnterValue(String theText) {

public EnterValue thenHit(Keys... keys) {
this.followedByKeys.addAll(Lists.newArrayList(keys));
this.followedBy = getFollowedByKeysDescriptionFor(followedByKeys);
return this;
}

Expand Down
Expand Up @@ -6,6 +6,8 @@
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;

import java.util.Arrays;

import static net.serenitybdd.screenplay.Tasks.instrumented;

public class Hit {
Expand All @@ -17,7 +19,7 @@ public Hit(Keys[] keys) {
}

public static Hit the(Keys... keys) {
return new Hit(keys);
return new Hit(Arrays.copyOf(keys,keys.length));
}

public Performable into(String cssOrXpathForElement) {
Expand Down
Expand Up @@ -5,14 +5,16 @@
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;

import java.util.Arrays;

public class HitBy extends ByAction {

private Keys[] keys;
private String pluraliser;

public HitBy(Keys[] keys, By... locators) {
super(locators);
this.keys = keys;
this.keys = Arrays.copyOf(keys,keys.length);
}

@Step("{0} hits the '#keys' key#pluraliser")
Expand Down
Expand Up @@ -6,14 +6,16 @@
import net.thucydides.core.annotations.Step;
import org.openqa.selenium.Keys;

import java.util.Arrays;

public class HitElement implements Action {

private Keys[] keys;
private String pluraliser;
private WebElementFacade element;

public HitElement(Keys[] keys, WebElementFacade element) {
this.keys = keys;
this.keys = Arrays.copyOf(keys,keys.length);
this.element = element;
}

Expand Down
Expand Up @@ -6,13 +6,15 @@
import net.thucydides.core.annotations.Step;
import org.openqa.selenium.Keys;

import java.util.Arrays;

public class HitTarget implements Action {

private Keys[] keys;
private Target target;

public HitTarget(Keys[] keys, Target target) {
this.keys = keys;
this.keys = Arrays.copyOf(keys,keys.length);
this.target = target;
}

Expand Down
Expand Up @@ -3,6 +3,8 @@
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;

import java.util.Arrays;

public class JavaScript extends UIState<String> {

private final String expression;
Expand All @@ -11,7 +13,7 @@ public class JavaScript extends UIState<String> {
public JavaScript(String expression, Object[] parameters, Actor actor) {
super(actor);
this.expression = expression;
this.parameters = parameters;
this.parameters = Arrays.copyOf(parameters,parameters.length);
}

public static JavaScriptBuilder evaluate(String expression) {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class SerenityReportingTask extends Task {
*/
public String jiraProject;

private final String DEFAULT_SOURCE = "target/site/serenity";
private static final String DEFAULT_SOURCE = "target/site/serenity";

private PathProcessor pathProcessor = new PathProcessor();

Expand Down
Expand Up @@ -19,10 +19,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

import static io.appium.java_client.remote.MobilePlatform.ANDROID;
import static io.appium.java_client.remote.MobilePlatform.IOS;
Expand Down Expand Up @@ -421,7 +418,7 @@ private static String getFilledValue(Annotation mobileBy) {
}
throw new IllegalArgumentException("@"
+ mobileBy.getClass().getSimpleName() + ": one of "
+ Strategies.strategyNames().toString() + " should be filled");
+ Arrays.toString(Strategies.strategyNames()) + " should be filled");
}

private static Method[] prepareAnnotationMethods(
Expand Down
Expand Up @@ -2,10 +2,7 @@

import net.thucydides.core.annotations.At;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Pattern;

/**
Expand Down
Expand Up @@ -487,7 +487,7 @@ public String getFoundBy() {
}


class ExtractText implements Converter<WebElement, String> {
static class ExtractText implements Converter<WebElement, String> {
public String convert(WebElement from) {
return from.getText();
}
Expand Down
Expand Up @@ -9,9 +9,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class DarkroomProcessingLine implements Runnable {

Expand All @@ -29,15 +30,17 @@ public void terminate() {

}

private final Queue<ScreenshotNegative> queue;
private final List<ScreenshotNegative> queue;

DarkroomProcessingLine(List<? extends PhotoFilter> processors) {
this.processors = processors;
this.queue = new ConcurrentLinkedQueue<>();
this.queue = Collections.synchronizedList(new LinkedList<ScreenshotNegative>());
// this.queue = new ConcurrentLinkedQueue<>();
}

public ScreenshotReceipt addToProcessingQueue(ScreenshotNegative negative) {
queue.offer(negative);
// queue.offer(negative);
queue.add(negative);
synchronized (queue) {
queue.notifyAll();
}
Expand Down Expand Up @@ -72,7 +75,8 @@ private void finishProcessingNegatives() {

private void processNegative() {
while (!queue.isEmpty()) {
ScreenshotNegative negative = queue.poll();
Queue q;
ScreenshotNegative negative = queue.get(0);
if (negative != null) {
process(negative);
}
Expand Down
Expand Up @@ -9,7 +9,7 @@
*/
public class ScreenshotPhoto {

public static ScreenshotPhoto None = new ScreenshotPhoto(null);
public final static ScreenshotPhoto None = new ScreenshotPhoto(null);

private final Path pathToScreenshot;

Expand Down
Expand Up @@ -830,7 +830,7 @@ public int integerFrom(EnvironmentVariables environmentVariables, int defaultVal
= Optional.fromNullable(environmentVariables.getProperty(withSerenityPrefix(getPropertyName())));

if (isDefined(newPropertyValue)) {
return Integer.valueOf(newPropertyValue.get());
return Integer.parseInt(newPropertyValue.get());
} else {
Optional<String> legacyValue = legacyPropertyValueIfPresentIn(environmentVariables);
return (isDefined(legacyValue)) ? Integer.valueOf(legacyValue.get()) : defaultValue;
Expand Down
Expand Up @@ -129,7 +129,7 @@ private FieldValueProvider fieldValueFrom(Field field) {
return new FieldValueProvider(field, object);
}

private class FieldValueProvider {
private static class FieldValueProvider {
Field field;
Object object;

Expand Down
Expand Up @@ -46,8 +46,6 @@ class ThucydidesContext {

private String defaultDriver;

private WebDriverFactory webDriverFactory;

private Pages pages;

/**
Expand All @@ -67,7 +65,6 @@ private ThucydidesContext(String defaultDriver, StepListener... additionalListen
outputDirectory = configuration.getOutputDirectory();
this.defaultDriver = defaultDriver;
if (defaultDriver != null) {
webDriverFactory = new WebDriverFactory();
pages = new Pages(getDriver());
stepFactory = new StepFactory(pages);
} else {
Expand Down
Expand Up @@ -27,8 +27,7 @@ public <T> Matcher<T> getMatcher() {
@Override
public String toString() {
String matcherDescription = matcher.toString();
String htmlFriendlyMatcherDescription
= (matcherDescription != null) ? matcherDescription.replaceAll("\"", "'") : "";
String htmlFriendlyMatcherDescription = matcherDescription.replaceAll("\"", "'");
return fieldName + " " + htmlFriendlyMatcherDescription;
}
}
Expand Up @@ -244,7 +244,7 @@ private List<Object> rowDataFrom(Map<String, ? extends Object> mappedRow) {

}

public class RowValueAccessor {
public static class RowValueAccessor {
private final DataTable dataTable;
private final int rowNumber;

Expand Down
Expand Up @@ -60,7 +60,7 @@ public HtmlFormattedInfo getHtml() {
return new HtmlFormattedInfo(description);
}

public class HtmlFormattedInfo {
public static class HtmlFormattedInfo {
private final String description;

public HtmlFormattedInfo(String description) {
Expand Down
Expand Up @@ -71,7 +71,7 @@
*/
public class TestOutcome {

private static final int RECENT_TEST_RUN_COUNT = 10;
private static final Integer RECENT_TEST_RUN_COUNT = 10;
private static final String ISSUES = "issues";
private static final String NEW_LINE = System.getProperty("line.separator");

Expand Down Expand Up @@ -2032,7 +2032,7 @@ public void causedBy(Class<? extends Throwable> expected) {
}
}

private class SpecificTagFinder {
private static class SpecificTagFinder {
private final TestTag tag;

public SpecificTagFinder(TestTag tag) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ private static String exceptionClassName(Throwable cause) {
public FailureCause(String errorType, String message, StackTraceElement[] stackTrace) {
this.errorType = errorType;
this.message = parseErrorMessage(message);
this.stackTrace = stackTrace;
this.stackTrace = Arrays.copyOf(stackTrace,stackTrace.length);
}

private String parseErrorMessage(String message) {
Expand Down Expand Up @@ -91,11 +91,11 @@ public String asString() {
}

public StackTraceElement[] getStackTrace() {
return stackTrace;
return Arrays.copyOf(stackTrace, stackTrace.length);
}

public void setStackTrace(StackTraceElement[] stackTrace) {
this.stackTrace = stackTrace;
this.stackTrace = Arrays.copyOf(stackTrace,stackTrace.length);
}

public Class<? extends Throwable> exceptionClass() {
Expand Down
Expand Up @@ -5,6 +5,7 @@
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.util.EnvironmentVariables;

import java.util.Arrays;
import java.util.List;

import static net.thucydides.core.ThucydidesSystemProperty.SIMPLIFIED_STACK_TRACES;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class StackTraceSanitizer {

public StackTraceSanitizer(EnvironmentVariables environmentVariables, StackTraceElement[] stackTrace) {
this.environmentVariables = environmentVariables;
this.stackTrace = stackTrace;
this.stackTrace = Arrays.copyOf(stackTrace,stackTrace.length);
}

public static StackTraceSanitizer forStackTrace(StackTraceElement[] stackTrace) {
Expand Down
Expand Up @@ -94,7 +94,7 @@ public HtmlTable inTable(WebElement table) {
}
}

private class EnoughCellsCheck {
private static class EnoughCellsCheck {
private final int minimumNumberOfCells;

private EnoughCellsCheck(List<String> headings) {
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class FormatConfiguration {

private final static Logger LOGGER = LoggerFactory.getLogger(FormatConfiguration.class);

public static String DEFAULT_FORMATS = "json,xml,html";
public final static String DEFAULT_FORMATS = "json,xml,html";

private final List<OutcomeFormat> formats;

Expand Down
Expand Up @@ -323,7 +323,7 @@ public TestOutcomes withRequirementsTags() {
return new TestOutcomes(testOutcomesWithRequirements, estimatedAverageStepCount, label, rootOutcomes.orNull(), environmentVariables);
}

private class TagFinder {
private static class TagFinder {
private final String tagType;

private TagFinder(String tagType) {
Expand Down Expand Up @@ -759,7 +759,7 @@ public TestOutcomeMatcher findMatchingTags() {
return new TestOutcomeMatcher(this);
}

public final class TestOutcomeMatcher {
public static final class TestOutcomeMatcher {

private final TestOutcomes outcomes;
private Optional<List<Matcher<String>>> nameMatcher = Optional.absent();
Expand Down
Expand Up @@ -116,7 +116,7 @@ private Document parseDocument(File xUnitReport) throws IOException {
}
}

private class ExceptionElementBuilder {
private static class ExceptionElementBuilder {
private final Element testCaseElement;

public ExceptionElementBuilder(Element testCaseElement) {
Expand Down
Expand Up @@ -396,7 +396,7 @@ private List<String> sortByDecreasingSize(List<String> issues) {
Collections.sort(sortedIssues, new Comparator<String>() {
@Override
public int compare(String a, String b) {
return new Integer(-a.length()).compareTo(new Integer(b.length()));
return Integer.valueOf(-a.length()).compareTo(new Integer(b.length()));
}
});
return sortedIssues;
Expand Down

0 comments on commit de85892

Please sign in to comment.