Skip to content

Commit

Permalink
Sonar fixes (#72)
Browse files Browse the repository at this point in the history
* various sonar related fixes
  • Loading branch information
iantmoore committed Nov 10, 2017
1 parent fe53973 commit 309dd56
Show file tree
Hide file tree
Showing 62 changed files with 336 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,64 @@
* nodes which have tags, if not overridden these nodes will call
* visit(NodeWithChildren) or visit(IExecutionNode) depending on type.
*
* @param <RETURN_TYPE> the type of class this visitor returns
* @author rbarefield
*/
public abstract class AbstractExecutionNodeVisitor<RETURN_TYPE> implements ExecutionNodeVisitor<RETURN_TYPE> {

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(RootNode rootNode) {

return visit((NodeWithChildren<?>) rootNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(FeatureNode featureNode) {

return visit((TaggedNode) featureNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(BasicScenarioNode basicScenarioNode) {

return visit((TaggedNode) basicScenarioNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(OutlineScenarioNode outlineNode) {

return visit((TaggedNode) outlineNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(OutlineScenarioRowNode outlineScenarioRowNode) {

return visit((TaggedNode) outlineScenarioRowNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(SubstepNode substepNode) {

return visit((TaggedNode) substepNode);
}

/**
* {@inheritDoc}
*/
@Override
public RETURN_TYPE visit(StepImplementationNode stepImplementationNode) {

return visit((TaggedNode) stepImplementationNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void setScreenshot(byte[] screenshot) {
this.screenshot = screenshot;
}

public void setChildFailure(SubstepExecutionFailure substepExecutionFailure) {
public void setChildFailure() {

recordComplete();
// this is to prevent a failure from overwriting a parse or setup / tear down failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,69 @@

import com.technophobia.substeps.execution.node.*;

/**
* Interface of visitor pattern for traversing the tree of ExecutionNodes, extend the AbstractExecutionNodeVisitor
* to then just implement the interesting nodes
*
* @param <RETURN_TYPE> the type returned by the visitor implementation
*/
public interface ExecutionNodeVisitor<RETURN_TYPE> {


/**
* Visit the root node
*
* @param rootNode the root node
* @return the return type
*/
RETURN_TYPE visit(RootNode rootNode);

/**
* Visit a feature node
*
* @param featureNode the feature node
* @return the return type
*/
RETURN_TYPE visit(FeatureNode featureNode);

/**
* Visit a basic scenario node
*
* @param basicScenarioNode the basic scenario node
* @return the return type
*/
RETURN_TYPE visit(BasicScenarioNode basicScenarioNode);

/**
* Visit an outline scenario node.
*
* @param outlineNode the outline node
* @return the return type
*/
RETURN_TYPE visit(OutlineScenarioNode outlineNode);

/**
* Visit an outline scenario row node
*
* @param outlineScenarioRowNode the outline scenario row node
* @return the return type
*/
RETURN_TYPE visit(OutlineScenarioRowNode outlineScenarioRowNode);

/**
* Visit a substep node
*
* @param substepNode the substep node
* @return the return type
*/
RETURN_TYPE visit(SubstepNode substepNode);

/**
* Visit a step implementation node
*
* @param stepImplementationNode the step implementation node
* @return the return type
*/
RETURN_TYPE visit(StepImplementationNode stepImplementationNode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public RootNode(String featureSetDescription, List<FeatureNode> features, String
this.nonFatalTags = nonFatalTags;
}

@Override
public ExecutionNodeResult getResult() {
return super.getResult();
}

@Override
public <RETURN_TYPE> RETURN_TYPE dispatch(ExecutionNodeVisitor<RETURN_TYPE> executionNodeVisitor) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@

package com.technophobia.substeps.model;

import com.typesafe.config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.typesafe.config.Config;
import org.substeps.runner.NewSubstepsExecutionConfig;

import java.net.URL;

/**
* @author ian
*/
Expand All @@ -41,20 +37,6 @@ public Config getConfig(){
return NewSubstepsExecutionConfig.threadLocalConfig();
}


/**
* Implementors of substep libraries should call this with default
* properties for their library
*
* @param url to a properties file containing default values
* @param name to name of the properties file that is being added
*/
@Deprecated
public void addDefaultProperties(final URL url, final String name) {
throw new IllegalArgumentException("method no longer supported, rename default substep library properties to reference.conf and they will be loaded by Typesafe config");
}


public String getString(final String key) {
return getConfig().getString(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private SubSteps(){
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public static @interface StepImplementations {
public @interface StepImplementations {
// no op
Class<?>[] requiredInitialisationClasses() default {};
}
Expand All @@ -51,7 +51,7 @@ private SubSteps(){
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public static @interface AdditionalStepImplementations {
public @interface AdditionalStepImplementations {
Class<?>[] value();
}

Expand All @@ -60,13 +60,13 @@ private SubSteps(){
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public static @interface Step {
public @interface Step {
String value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public static @interface StepParameter {
public @interface StepParameter {
Class<? extends Converter<?>> converter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void addExecutionResult(RootNode rootNode) {

}

private String getBuildInfoString(final String msg, final List<List<IExecutionNode>> failures) {
private static String getBuildInfoString(final String msg, final List<List<IExecutionNode>> failures) {

final StringBuilder buf = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ public final class ExecutionContext {
protected ExecutionContext initialValue() {
return new ExecutionContext();
}

;
};

private Map<Scope, Map<String, Object>> scopedData = null;

private ExecutionContext() {
scopedData = new EnumMap<>(Scope.class);
}

private Map<Scope, Map<String, Object>> scopedData = null;

public static void put(final Scope scope, final String key, final Object value) {
executionContextThreadLocal.get().putInternal(scope, key, value);
Expand All @@ -65,7 +64,7 @@ private void putInternal(final Scope scope, final String key, final Object value

Map<String, Object> map = scopedData.get(scope);
if (map == null) {
map = new HashMap<String, Object>();
map = new HashMap<>();
scopedData.put(scope, map);
}
map.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@
*/
public class SubstepExecutionFailure implements Serializable {

public static final Function<SubstepExecutionFailure, Long> GET_NODE_ID = new Function<SubstepExecutionFailure, Long>() {

@Override
public Long apply(final SubstepExecutionFailure failure) {
return failure == null || failure.getExeccutionNode() == null ? null : failure.getExeccutionNode().getId();
}

};

private static final long serialVersionUID = 4981517213059529046L;

private IExecutionNode executionNode;
Expand All @@ -60,30 +51,7 @@ private SubstepExecutionFailure(Throwable cause, IExecutionNode executionNode, b
}




public static SubstepExecutionFailure criticalFailure(Throwable cause, IExecutionNode node, byte[] screenshotBytes) {
SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, false, screenshotBytes);

node.getResult().setFailure(sef);

return sef;

}


public static SubstepExecutionFailure nonCriticalFailure(final Throwable cause, final IExecutionNode node, byte[] screenshotBytes) {

SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, true, screenshotBytes);

node.getResult().setFailure(sef);

return sef;
}


public SubstepExecutionFailure(final Throwable cause) {

this.throwableInfo = new ThrowableInfo(cause);
}

Expand Down Expand Up @@ -122,6 +90,25 @@ public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node,
node.getResult().setResult(result);
}

public static SubstepExecutionFailure criticalFailure(Throwable cause, IExecutionNode node, byte[] screenshotBytes) {
SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, false, screenshotBytes);

node.getResult().setFailure(sef);

return sef;

}


public static SubstepExecutionFailure nonCriticalFailure(final Throwable cause, final IExecutionNode node, byte[] screenshotBytes) {

SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, true, screenshotBytes);

node.getResult().setFailure(sef);

return sef;
}



public static void setResult(final Throwable cause, final IExecutionNode node, final ExecutionResult result) {
Expand Down Expand Up @@ -203,4 +190,13 @@ public void setScreenshot(final byte[] screenshot) {
this.screenshot = screenshot;
}

public static final Function<SubstepExecutionFailure, Long> GET_NODE_ID = new Function<SubstepExecutionFailure, Long>() {

@Override
public Long apply(final SubstepExecutionFailure failure) {
return failure == null || failure.getExeccutionNode() == null ? null : failure.getExeccutionNode().getId();
}

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void addImplementationClasses(final Class<?>... implementationClasses) {
* @throws InstantiationException
* @throws InvocationTargetException
*/
private Object instantiateClass(final Class<?> clazz) throws IllegalAccessException, InstantiationException, InvocationTargetException {
private static Object instantiateClass(final Class<?> clazz) throws IllegalAccessException, InstantiationException, InvocationTargetException {

Class<?> enclosingClass = clazz.getEnclosingClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void addFailure(final SubstepExecutionFailure failure) {
/**
* @param failure
*/
private void logFailure(final SubstepExecutionFailure failure) {
private static void logFailure(final SubstepExecutionFailure failure) {

final Throwable here = new Throwable();

Expand Down
Loading

0 comments on commit 309dd56

Please sign in to comment.