Skip to content

Commit

Permalink
now generating java test classes based on the feature file name inste…
Browse files Browse the repository at this point in the history
…ad of same name for all
  • Loading branch information
vincent-fuchs committed Mar 15, 2016
1 parent 5732443 commit c3590d3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>cucumber-jvm-parallel-plugin Maven Plugin</name>
Expand Down Expand Up @@ -55,6 +55,14 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>


<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.List;
import java.util.Properties;

import com.google.common.base.CaseFormat;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
Expand Down Expand Up @@ -54,8 +56,7 @@ void generateCucumberITFiles(final File outputDirectory, final Collection<File>
continue;
}

final String outputFileName = String.format("Parallel%02dIT.java",
fileCounter);
final String outputFileName = generateClassName(file.getName(),fileCounter);

setFeatureFileLocation(file);

Expand Down Expand Up @@ -208,4 +209,17 @@ private String quoteGlueStrings() {
return sb.toString();
}

public static String generateClassName(String featureFileName, int fileCounter) {

String fileNameWithNoExtension= FilenameUtils.removeExtension(featureFileName);

fileNameWithNoExtension=fileNameWithNoExtension.replaceAll("_","-");
fileNameWithNoExtension=fileNameWithNoExtension.replaceAll(" ","");

String className = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, fileNameWithNoExtension);

return String.format(className+"%02dIT.java",fileCounter);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.timm.cucumber.generate;

import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;


public class CucumberITGeneratorTest {

@Test
public void shouldGenerateExpectedTestClassNames() throws Exception {

Map<File,String> inputOutput=new HashMap<File,String>();

inputOutput.put(new File("my-domain_subSetScenarios.feature"), "MyDomainSubsetscenarios01IT.java");
inputOutput.put(new File("my-PERSONNALdomain subSetPersonnalScenarios.feature"), "MyPersonnaldomainsubsetpersonnalscenarios02IT.java");

int fileCounter=1;

for(Map.Entry<File,String> example : inputOutput.entrySet()){

assertThat(CucumberITGenerator.generateClassName(example.getKey().getName(),fileCounter),equalTo(example.getValue()));

fileCounter++;
}
}
}

0 comments on commit c3590d3

Please sign in to comment.