Skip to content

Commit

Permalink
some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Sep 30, 2014
1 parent 65fee9f commit 440b54c
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.tngtech.jgiven.impl.util.ReflectionUtil.MethodAction;
import com.tngtech.jgiven.impl.util.ScenarioUtil;
import com.tngtech.jgiven.integration.CanWire;
import com.tngtech.jgiven.report.model.NamedArgument;

/**
* Main class of JGiven for executing scenarios.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.lang.reflect.Method;
import java.util.List;

import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;

public class NoOpScenarioListener implements ScenarioListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.lang.reflect.Method;
import java.util.List;

import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;

public interface ScenarioListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class AssertionUtil {

public static void assertNotNull( Object o ) {
assertNotNull( "Expected a value to not be null, but it apparently was null" );
assertNotNull( o, "Expected a value to not be null, but it apparently was null" );
}

public static void assertNotNull( Object o, String msg ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tngtech.jgiven.impl.util;

import java.io.File;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import com.google.common.base.Charsets;
import com.google.common.base.Throwables;

public class PrintWriterUtil {

public static PrintWriter getPrintWriter( File file ) {
try {
return new PrintWriter( file, Charsets.UTF_8.name() );
} catch( Exception e ) {
throw Throwables.propagate( e );
}
}

public static PrintWriter getPrintWriter( OutputStream outputStream ) {
try {
return new PrintWriter( new OutputStreamWriter( outputStream, Charsets.UTF_8.name() ) );
} catch( UnsupportedEncodingException e ) {
throw Throwables.propagate( e );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.thoughtworks.paranamer.BytecodeReadingParanamer;
import com.thoughtworks.paranamer.ParameterNamesNotFoundException;
import com.thoughtworks.paranamer.Paranamer;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;

public class ScenarioUtil {
private static final Logger log = LoggerFactory.getLogger( ScenarioUtil.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ private void reduceMatrix( ScenarioModel scenarioModel, List<CaseArguments> argu
for( int i = 0; i < replacement.arguments.size(); i++ ) {
Word word = replacement.arguments.get( i );
word.getArgumentInfo().setParameterName( replacement.replacementName );
word.getArgumentInfo().setDerivedParameter( replacement.isStepParameterName );
if( !duplicate ) {
scenarioModel.getCase( i ).addDerivedArguments( word.getFormattedValue() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.io.Files;
import com.tngtech.jgiven.impl.util.PrintWriterUtil;
import com.tngtech.jgiven.impl.util.ResourceUtil;
import com.tngtech.jgiven.impl.util.Version;
import com.tngtech.jgiven.report.impl.CommonReportHelper;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ReportModelVisitor;
import com.tngtech.jgiven.report.model.ReportStatistics;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void visit( ScenarioModel scenarioModel ) {
}

static ReportModelHtmlWriter writeModelToFile( ReportModel model, HtmlTocWriter tocWriter, File file ) {
PrintWriter printWriter = CommonReportHelper.getPrintWriter( file );
PrintWriter printWriter = PrintWriterUtil.getPrintWriter( file );
try {
ReportModelHtmlWriter htmlWriter = new ReportModelHtmlWriter( printWriter );
htmlWriter.write( model, tocWriter );
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.io.PrintWriter;

import com.tngtech.jgiven.impl.util.DurationFormatter;
import com.tngtech.jgiven.impl.util.PrintWriterUtil;
import com.tngtech.jgiven.impl.util.ResourceUtil;
import com.tngtech.jgiven.report.impl.CommonReportHelper;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ReportStatistics;

Expand All @@ -27,7 +27,7 @@ public void write( File toDir ) {

private void writeIndexFile( File toDir ) {
File file = new File( toDir, "index.html" );
printWriter = CommonReportHelper.getPrintWriter( file );
printWriter = PrintWriterUtil.getPrintWriter( file );
utils = new HtmlWriterUtils( printWriter );
try {
ReportModelHtmlWriter htmlWriter = new ReportModelHtmlWriter( printWriter );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.tngtech.jgiven.report.impl;

import java.io.File;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.tngtech.jgiven.impl.Config;
import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser;
import com.tngtech.jgiven.report.json.ScenarioJsonWriter;
Expand Down Expand Up @@ -47,20 +41,4 @@ public void finishReport( ReportModel model ) {
new ScenarioJsonWriter( model ).write( reportFile );
}
}

public static PrintWriter getPrintWriter( File file ) {
try {
return new PrintWriter( file, Charsets.UTF_8.name() );
} catch( Exception e ) {
throw Throwables.propagate( e );
}
}

public static PrintWriter getPrintWriter( OutputStream outputStream ) {
try {
return new PrintWriter( new OutputStreamWriter( outputStream, Charsets.UTF_8.name() ) );
} catch( UnsupportedEncodingException e ) {
throw Throwables.propagate( e );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public class ArgumentInfo {
*/
private String parameterName;

/**
* Whether this argument is actually a derived parameter.
* Note that in that case parameterName is equal to argumentName
*/
private boolean isDerivedParameter;

/**
* The name of the argument as declared in the step method.
* Should never be {@code null}.
Expand Down Expand Up @@ -61,14 +55,6 @@ public String getArgumentName() {
return argumentName;
}

public void setDerivedParameter( boolean isDerivedParameter ) {
this.isDerivedParameter = isDerivedParameter;
}

public boolean isDerivedParameter() {
return isDerivedParameter;
}

public void setFormattedValue( String formattedValue ) {
this.formattedValue = formattedValue;
}
Expand All @@ -79,7 +65,7 @@ public String getFormattedValue() {

@Override
public int hashCode() {
return Objects.hashCode( parameterName, argumentName, isDerivedParameter );
return Objects.hashCode( parameterName, argumentName );
}

@Override
Expand All @@ -95,8 +81,6 @@ public boolean equals( Object obj ) {
}
ArgumentInfo other = (ArgumentInfo) obj;
return Objects.equal( parameterName, other.parameterName )
&& Objects.equal( argumentName, other.argumentName )
&& ( isDerivedParameter == other.isDerivedParameter );
&& Objects.equal( argumentName, other.argumentName );
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tngtech.jgiven.impl;
package com.tngtech.jgiven.report.model;

import com.google.common.base.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.tngtech.jgiven.config.TagConfiguration;
import com.tngtech.jgiven.format.DefaultFormatter;
import com.tngtech.jgiven.format.PrintfFormatter;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.impl.intercept.InvocationMode;
import com.tngtech.jgiven.impl.intercept.ScenarioListener;
import com.tngtech.jgiven.impl.util.AssertionUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.common.collect.Lists;
import com.tngtech.jgiven.format.ArgumentFormatter;
import com.tngtech.jgiven.format.DefaultFormatter;
import com.tngtech.jgiven.impl.NamedArgument;

public class StepFormatter {
private final String stepDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.io.PrintWriter;

import com.google.common.io.Files;
import com.tngtech.jgiven.impl.util.PrintWriterUtil;
import com.tngtech.jgiven.impl.util.ResourceUtil;
import com.tngtech.jgiven.report.impl.CommonReportHelper;
import com.tngtech.jgiven.report.json.JsonModelTraverser;
import com.tngtech.jgiven.report.json.ReportModelFileHandler;
import com.tngtech.jgiven.report.model.ReportModel;
Expand All @@ -17,7 +17,7 @@ public class PlainTextReportGenerator implements ReportModelFileHandler {
@Override
public void handleReportModel( ReportModel model, File file ) {
String targetFileName = Files.getNameWithoutExtension( file.getName() ) + ".feature";
PrintWriter printWriter = CommonReportHelper.getPrintWriter( new File( toDir, targetFileName ) );
PrintWriter printWriter = PrintWriterUtil.getPrintWriter( new File( toDir, targetFileName ) );

try {
model.accept( new PlainTextScenarioWriter( printWriter, false ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.fusesource.jansi.Ansi.Color;

import com.tngtech.jgiven.impl.Config;
import com.tngtech.jgiven.impl.util.PrintWriterUtil;
import com.tngtech.jgiven.impl.util.ResourceUtil;
import com.tngtech.jgiven.report.impl.CommonReportHelper;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ScenarioModel;

Expand All @@ -37,7 +37,7 @@ public PlainTextReporter() {
}

public PlainTextReporter( boolean withColor ) {
this( CommonReportHelper.getPrintWriter( System.out ), withColor );
this( PrintWriterUtil.getPrintWriter( System.out ), withColor );
}

public PlainTextReporter( PrintWriter printWriter, boolean withColor ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;
import com.tngtech.jgiven.report.model.StepFormatter;
import com.tngtech.jgiven.report.model.StepFormatter.Formatting;
import com.tngtech.jgiven.report.model.Word;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;

@RunWith( DataProviderRunner.class )
public class ScenarioUtilTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Primitives;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.impl.ScenarioBase;
import com.tngtech.jgiven.impl.util.ReflectionUtil;
import com.tngtech.jgiven.impl.util.ScenarioUtil;
import com.tngtech.jgiven.report.model.NamedArgument;
import com.tngtech.jgiven.report.model.ReportModelBuilder;

public class ScenarioExecutionRule implements MethodRule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.tngtech.java.junit.dataprovider.DataProviderFrameworkMethod;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.report.model.NamedArgument;

@RunWith( DataProviderRunner.class )
public class ScenarioTestRuleTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.testng.ITestResult;

import com.tngtech.jgiven.base.ScenarioTestBase;
import com.tngtech.jgiven.impl.NamedArgument;
import com.tngtech.jgiven.impl.ScenarioBase;
import com.tngtech.jgiven.impl.util.ScenarioUtil;
import com.tngtech.jgiven.report.impl.CommonReportHelper;
import com.tngtech.jgiven.report.model.NamedArgument;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ReportModelBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public boolean matches( ScenarioCriteria criteria ) {
return false;
}

if( numberOfSteps != null && numberOfSteps != criteria.numberOfSteps ) {
if( numberOfSteps != null && !numberOfSteps.equals( criteria.numberOfSteps ) ) {
return false;
}

if( numberOfFailingStages != null && numberOfFailingStages != criteria.numberOfFailingStages ) {
if( numberOfFailingStages != null && !numberOfFailingStages.equals( criteria.numberOfFailingStages ) ) {
return false;
}

Expand Down

0 comments on commit 440b54c

Please sign in to comment.