Skip to content

Commit

Permalink
Created Gradle tasks for unit, integration, and all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davenicolette committed Dec 18, 2020
1 parent de225dd commit d42ab4a
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 33 deletions.
30 changes: 23 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ repositories {
}

test {
description 'Runs all tests'
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
}
useJUnitPlatform()
}

dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.1')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.7.0')
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.6.0'
}
tasks.withType(JavaCompile) {
options.compilerArgs << "--enable-preview"
options.compilerArgs << '-Xlint:preview'
Expand All @@ -41,3 +35,25 @@ tasks.withType(JavaExec) {
jvmArgs += "--enable-preview"
}

dependencies {
implementation 'org.jetbrains:annotations:15.0'
testImplementation('org.junit.jupiter:junit-jupiter:5.6.1')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.7.0')
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.6.28'
}

def unitTest = tasks.register("unitTest", Test) {
description 'Run unit tests only'
useJUnitPlatform()
filter {
includeTestsMatching "com.neopragma.cobolcheck.*Test"
}
}
def integrationTest = tasks.register("integrationTest", Test) {
description 'Run integration tests only'
useJUnitPlatform()
filter {
includeTestsMatching "com.neopragma.cobolcheck.*IT"
}
}
6 changes: 0 additions & 6 deletions config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ application.copybook.filename.suffix = none
# Cobol Check can expand the application program's copybooks if the inserted code is necessary for test cases
copybook.expansion = false

# If your application uses COPY with the REPLACING option to assign prefixes to data element names,
# and you want cobol-check to expand copybooks (copybook.expansion = true), then
# specify the text replacement pattern(s) you are using.
# Example:
# copy.replacing.patterns = ==(X)==, ::X::

2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
rootProject.name = 'cobol-check'
include 'src:intTest'
findProject(':src:intTest')?.name = 'intTest'

2 changes: 2 additions & 0 deletions src/main/java/com/neopragma/cobolcheck/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface Constants {
String COLON = ":";
String SPACE = " ";
String COMMA = ",";
String PSEUDO_TEXT_DELIMITER_EQUALS = "==";
String PSEUDO_TEXT_DELIMITER_COLON = "::";
}
5 changes: 5 additions & 0 deletions src/main/java/com/neopragma/cobolcheck/CopybookExpander.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public Writer expand(Writer expandedSource,
// COPY REPLACING
if (!textReplacement[0].isEmpty()) {
for (StringTuple replace : textReplacement) {
for (String pseudoTextDelimiter : List.of (PSEUDO_TEXT_DELIMITER_EQUALS, PSEUDO_TEXT_DELIMITER_COLON)) {
if (sourceLine.contains(pseudoTextDelimiter)) {
sourceLine = sourceLine.replaceAll(replace.getFirst(), replace.getSecond());
}
}
for (String followingCharacter : List.of(PERIOD, SPACE)) {
String textToReplace = SPACE + replace.getFirst() + followingCharacter;
String replacementText = SPACE + replace.getSecond() + followingCharacter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand All @@ -13,12 +16,12 @@
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;


@ExtendWith(MockitoExtension.class)
public class CopybookExpanderTest implements Constants, StringHelper {
public class CopybookExpanderIT implements Constants, StringHelper {
private CopybookExpander copybookExpander;
private String expectedResult;
private String testCopybookFilename;
Expand All @@ -38,6 +41,9 @@ public static void oneTimeSetup() {
// when(messages.get(anyString())).thenReturn(EMPTY_STRING);
// doReturn(EMPTY_STRING).when(messages).get(anyString(), anyString());
// config = new Config(messages);

System.out.println("********** CopybookExpanderIT **********");

config = new Config(new Messages());

config.load("testconfig.properties");
Expand Down Expand Up @@ -82,7 +88,7 @@ public void it_handles_lower_case_and_mixed_case_code() throws IOException {
}

@Test
public void it_handles_copy_replacing_with_whole_words() throws IOException {
public void it_handles_copy_replacing() throws IOException {
Writer expandedSource =
runTestCase("COPYR001-padded",
"EXR001-padded",
Expand All @@ -93,6 +99,27 @@ public void it_handles_copy_replacing_with_whole_words() throws IOException {
assertEquals(expectedResult, expandedSource.toString());
}

@ParameterizedTest
@MethodSource("textPatternAndTestFilenameProvider")
public void it_handles_pseudo_text_replacement(
String pseudoTextPattern,
String replacementText,
String testCopybookFilename,
String expectedResultFilename) throws IOException {
Writer expandedSource =
runTestCase(testCopybookFilename + "-padded",
expectedResultFilename + "-padded",
new StringTuple(pseudoTextPattern, replacementText));
assertEquals(expectedResult, expandedSource.toString());
}
private static Stream<Arguments> textPatternAndTestFilenameProvider() {
return Stream.of(
Arguments.of("==XXX==", "NEW-TEXT","COPYP001", "EXP01"),
Arguments.of("::XXX::", "NEW-TEXT", "COPYP002", "EXP01")
);
}


private Writer runTestCase(String testCopybookBasename,
String expectedExpansionBasename) throws IOException {
return runTestCase(testCopybookBasename,
Expand Down Expand Up @@ -128,7 +155,7 @@ private static String getPathFor(String configPropertyName, String defaultValue)
pathString =
config.getString("resources.directory")
+ FILE_SEPARATOR
+ CopybookExpanderTest.class.getPackageName().replace(".", FILE_SEPARATOR)
+ CopybookExpanderIT.class.getPackageName().replace(".", FILE_SEPARATOR)
+ FILE_SEPARATOR
+ directoryName
+ FILE_SEPARATOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(MockitoExtension.class)
public class GeneratorTestCodeInsertionTest implements Constants {
public class GeneratorTestCodeInsertionIT implements Constants {

private Generator generator;
private static final Messages messages = new Messages();
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void oneTimeSetup() {
pathToTestCobolSources =
config.getString("resources.directory")
+ FILE_SEPARATOR
+ GeneratorTestCodeInsertionTest.class.getPackageName().replace(".", FILE_SEPARATOR)
+ GeneratorTestCodeInsertionIT.class.getPackageName().replace(".", FILE_SEPARATOR)
+ FILE_SEPARATOR
+ config.getString("application.source.directory")
+ FILE_SEPARATOR;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/neopragma/cobolcheck/TupleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void it_handles_two_strings() {
Tuple<String, String> tuple = new StringTuple("A", "B");
assertEquals("A", tuple.getFirst());
assertEquals("B", tuple.getSecond());

}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
01 ==XXX==-GROUP-1.
05 ==XXX==-ITEM-1-1.
10 ==XXX==-ITEM-1-1-1.
10 ==XXX==-ITEM-1-1-2.
05 ==XXX==-ITEM-1-2.
10 ==XXX==-ITEM-1-2-1.
10 ==XXX==-ITEM-1-2-2.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
05 ==XXX==-ITEM-1-1.
10 ==XXX==-ITEM-1-1-1.
10 ==XXX==-ITEM-1-1-2.
05 ==XXX=-ITEM-1-2.
05 ==XXX==-ITEM-1-2.
10 ==XXX==-ITEM-1-2-1.
10 ==XXX==-ITEM-1-2-2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
01 ::XXX::-GROUP-1.
05 ::XXX::-ITEM-1-1.
10 ::XXX::-ITEM-1-1-1.
10 ::XXX::-ITEM-1-1-2.
05 ::XXX::-ITEM-1-2.
10 ::XXX::-ITEM-1-2-1.
10 ::XXX::-ITEM-1-2-2.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
01 ==XXX==-GROUP-1.
05 ==XXX==-ITEM-1-1.
10 ==XXX==-ITEM-1-1-1.
10 ==XXX==-ITEM-1-1-2.
05 ==XXX==-ITEM-1-2.
10 ==XXX==-ITEM-1-2-1.
10 ==XXX==-ITEM-1-2-2.
01 ::XXX::-GROUP-1.
05 ::XXX::-ITEM-1-1.
10 ::XXX::-ITEM-1-1-1.
10 ::XXX::-ITEM-1-1-2.
05 ::XXX::-ITEM-1-2.
10 ::XXX::-ITEM-1-2-1.
10 ::XXX::-ITEM-1-2-2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
01 NEW-TEXT-GROUP-1.
05 NEW-TEXT-ITEM-1-1.
10 NEW-TEXT-ITEM-1-1-1.
10 NEW-TEXT-ITEM-1-1-2.
05 NEW-TEXT-ITEM-1-2.
10 NEW-TEXT-ITEM-1-2-1.
10 NEW-TEXT-ITEM-1-2-2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
01 NEW-TEXT-GROUP-1.
05 NEW-TEXT-ITEM-1-1.
10 NEW-TEXT-ITEM-1-1-1.
10 NEW-TEXT-ITEM-1-1-2.
05 NEW-TEXT-ITEM-1-2.
10 NEW-TEXT-ITEM-1-2-1.
10 NEW-TEXT-ITEM-1-2-2.
6 changes: 0 additions & 6 deletions testconfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ locale.country = JP

# Cobol Check can expand the application program's copybooks if the inserted code is necessary for test cases
copybook.expansion = false

# If your application uses COPY with the REPLACING option to assign prefixes to data element names,
# and you want cobol-check to expand copybooks (copybook.expansion = true), then
# specify the text replacement pattern(s) you are using.
# Example:
# copy.replacing.patterns = ==(X)==, ::X::

0 comments on commit d42ab4a

Please sign in to comment.