Skip to content

Commit

Permalink
introduce quickcheck and fix #177
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Dec 22, 2015
1 parent 66a1603 commit 62aafb6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ subprojects {
springVersion = '3.2.4.RELEASE'
checkstyleVersion = '2.12.1'
jacocoVersion = '0.7.2.201409121644'
quickcheckVersion = '0.6'
}

dependencies {
Expand All @@ -81,14 +82,12 @@ subprojects {
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.assertj', name: 'assertj-core', version: assertjVersion
testCompile group: 'com.tngtech.java', name: 'junit-dataprovider', version: junitDataproviderVersion
testCompile group: 'net.java.quickcheck', name: 'quickcheck', version: quickcheckVersion
}

tasks.withType(JavaCompile) {
// needed for DeSzenarioTest.java as it has Umlauts in the code
options.encoding = 'UTF-8'
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
options.compilerArgs << "-parameters"
}
}

tasks.withType(Jar) {
Expand Down Expand Up @@ -283,7 +282,6 @@ subprojects {
javadoc.onlyIf {
JavaVersion.current().isJava8Compatible()
}

}

task overallJacocoReport(type: JacocoReport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String description( String value, List<String> parameterNames, List<?> pa
replacement = "\\$";
} else {
int i = Integer.parseInt( group );
replacement = String.valueOf( parameterValues.get( i ) );
replacement = Matcher.quoteReplacement( String.valueOf( parameterValues.get( i ) ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.tngtech.jgiven.impl.params;

import static net.java.quickcheck.generator.CombinedGenerators.lists;
import static net.java.quickcheck.generator.PrimitiveGenerators.strings;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.common.collect.Lists;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.DataProviders;
import com.tngtech.java.junit.dataprovider.UseDataProvider;

import junit.framework.TestCase;
import net.java.quickcheck.junit.SeedInfo;

@RunWith( value = DataProviderRunner.class )
public class DefaultCaseDescriptionProviderTest extends TestCase {

@Rule
public SeedInfo seed = new SeedInfo();

@DataProvider
public static Object[][] randomStrings() {
return DataProviders.testForEach( lists( strings(), 20 ).next() );
}

@UseDataProvider( "randomStrings" )
@Test
public void test( String someString ) throws Exception {
seed.restore( -5294091015527388791L );
DefaultCaseDescriptionProvider provider = new DefaultCaseDescriptionProvider();
String description = provider.description( "$0", Lists.newArrayList( "someName" ), Lists.newArrayList( someString ) );
assertThat( description ).isEqualTo( someString );
}
}

0 comments on commit 62aafb6

Please sign in to comment.