From 194186164ea8351e0d25dbad2524634c28f62903 Mon Sep 17 00:00:00 2001 From: issacto Date: Thu, 10 Aug 2023 15:07:24 +0100 Subject: [PATCH] refactor - third part --- .../interpreter/InterpreterController.java | 26 ++++++------ .../{Block.java => SectionOrParagraph.java} | 4 +- .../testSuiteParser/TestSuiteParser.java | 5 +-- .../TestSuiteParserController.java | 4 +- .../features/testSuiteParser/WhenOther.java | 17 +------- .../testSuiteParser/WhenOtherGenerator.java | 2 +- .../cobolcheck/workers/Generator.java | 14 +++---- .../cobolcheck/MockIT.java | 42 +++++++------------ 8 files changed, 43 insertions(+), 71 deletions(-) rename src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/{Block.java => SectionOrParagraph.java} (84%) diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java index 37055c4e..ab4db17b 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java @@ -27,7 +27,7 @@ public class InterpreterController { private boolean insideSectionOrParagraphMockBody; private TreeMap currentDataStructure; private final String stubTag; - private Block block; + private SectionOrParagraph sectionOrParagraph; public InterpreterController(BufferedReader sourceReader) { if (sourceReader == null) { @@ -40,7 +40,7 @@ public InterpreterController(BufferedReader sourceReader) { tokenExtractor = new StringTokenizerExtractor(); currentDataStructure = new TreeMap<>(); stubTag = Config.getStubTag(); - block = new Block(); + sectionOrParagraph = new SectionOrParagraph(); } //Getters for lists of specific source lines @@ -507,27 +507,27 @@ private void resetPossibleMockValues(){ possibleMockType = null; } - public List getBlockLines(){ - return block.getLines(); + public List getSectionOrParagraphLines(){ + return sectionOrParagraph.getLines(); } - public void removeBlockLines(){ - block.removeLines(); + public void removeSectionOrParagraphLines(){ + sectionOrParagraph.removeLines(); } - public void addBlockLine(){ + public void addSectionOrParagraphLine(){ if(Interpreter.shouldLineBeStubbed(reader.getCurrentLine(), reader.getState())) - block.addLine(StringHelper.stubLine(reader.getCurrentLine().getUnNumberedString(), stubTag)); - else block.addLine(reader.getCurrentLine().getUnNumberedString()); + sectionOrParagraph.addLine(StringHelper.stubLine(reader.getCurrentLine().getUnNumberedString(), stubTag)); + else sectionOrParagraph.addLine(reader.getCurrentLine().getUnNumberedString()); } - public void addBlockLine(String line){ - block.addLine(line); + public void addSectionOrParagraphLine(String line){ + sectionOrParagraph.addLine(line); } - public void addBlockLines(List lines){ + public void addSectionOrParagraphLines(List lines){ for (String line : lines){ - block.addLine(line); + sectionOrParagraph.addLine(line); } } diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/Block.java b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/SectionOrParagraph.java similarity index 84% rename from src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/Block.java rename to src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/SectionOrParagraph.java index 7a43207f..df74a952 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/Block.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/SectionOrParagraph.java @@ -3,11 +3,11 @@ import java.util.ArrayList; import java.util.List; -public class Block { +public class SectionOrParagraph { private List lines; - public Block(){ + public SectionOrParagraph(){ lines = new ArrayList<>(); } diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java index 1006c435..278d8504 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java @@ -1161,10 +1161,9 @@ public String getCurrentFieldName() { return currentFieldName; } - public WhenOther getWhenOtherBlock(String type, List lines, String itdentifier, boolean withComments){ - WhenOther whenOther = new WhenOther(currentTestSuiteName ,currentTestCaseName, testSuiteNumber, testCaseNumber,whenOtherNumber); + public WhenOther getWhenOtherSectionOrParagraph(String type, List lines, String itdentifier, boolean withComments){ + WhenOther whenOther = new WhenOther(testSuiteNumber, testCaseNumber, whenOtherNumber); whenOther.addLines(lines); - whenOther.setScope(MockScope.Local); whenOther.setType(type); whenOther.setIdentifier(itdentifier); whenOtherNumber += 1; diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java index aabe1568..60581522 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java @@ -317,9 +317,9 @@ public void prepareNextParse() { Config.setDecimalPointIsCommaFromFile(); } - public List generateWhenOtherBlock(String type, List blocklines, String sourceLine, String identifier, boolean withComments) throws IOException{ + public List generateWhenOtherSectionOrParagraph(String type, List sectionOrParagraphlines, String sourceLine, String identifier, boolean withComments) throws IOException{ List lines = new ArrayList<>(); - WhenOther whenOther = testSuiteParser.getWhenOtherBlock(type, blocklines, identifier, true); + WhenOther whenOther = testSuiteParser.getWhenOtherSectionOrParagraph(type, sectionOrParagraphlines, identifier, true); lines.add(whenOtherGenerator.generateWhenOtherCall(whenOther)); lines.addAll(this.getEndEvaluateLine()); lines.add(sourceLine); diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOther.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOther.java index a27012e2..7cdd58f8 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOther.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOther.java @@ -12,17 +12,12 @@ public class WhenOther { private String identifier; private String type; private List lines; - private MockScope scope; - private String testSuiteName; - private String testCaseName; private int testSuiteNumber; private int testCaseNumber; private int mockNumber; - public WhenOther(String testSuiteName, String testCaseName, int testSuiteNumber, int testCaseNumber, int mockNumber) { - this.testSuiteName = testSuiteName; - this.testCaseName = testCaseName; + public WhenOther(int testSuiteNumber, int testCaseNumber, int mockNumber) { this.testSuiteNumber = testSuiteNumber; this.testCaseNumber = testCaseNumber; this.mockNumber = mockNumber; @@ -41,10 +36,6 @@ public void addLines(List lines) { this.lines.addAll(lines); } - public void setScope(MockScope scope) { - this.scope = scope; - } - public void setType(String type) { this.type = type; } @@ -65,11 +56,7 @@ public void setIdentifier(String identifier) { public List getCommentText(){ List newLines = new ArrayList<>(); newLines.add(" *****************************************************************"); - newLines.add( "When other block of: " + type + ": " + identifier); - newLines.add("In testsuite: " + testSuiteName); - if (scope == MockScope.Local){ - newLines.add("In testcase: " + testCaseName); - } + newLines.add( "WhenOther of: " + type + ": " + identifier); newLines.add(" *****************************************************************"); return newLines; diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOtherGenerator.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOtherGenerator.java index 9165eb16..f00a7736 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOtherGenerator.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/WhenOtherGenerator.java @@ -15,7 +15,7 @@ String generateWhenOtherCall(WhenOther whenOther) { List generateWhenOther(WhenOther whenOther, boolean withComments){ List lines = new ArrayList<>(); - lines.addAll(CobolGenerator.generateCommentBlock("WhenOther block called")); + lines.addAll(CobolGenerator.generateCommentBlock("WhenOther Paragraph or Section called")); lines.addAll(generateParagraphsForWhenOther(whenOther, withComments)); lines.add(""); return lines; diff --git a/src/main/java/org/openmainframeproject/cobolcheck/workers/Generator.java b/src/main/java/org/openmainframeproject/cobolcheck/workers/Generator.java index 1122b2d2..ae633ab1 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/workers/Generator.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/workers/Generator.java @@ -143,8 +143,8 @@ private String tryInsertEndEvaluateAtMockedCompomentEnd(String sourceLine) throw if (interpreter.isInsideSectionOrParagraphMockBody()){ if (interpreter.isCurrentLineEndingSectionOrParagraph()){ if (interpreter.canWriteEndEvaluateBeforeCurrentLine()){ - writeWhenOtherBlock(sourceLine); - interpreter.removeBlockLines(); + writeWhenOtherSectionOrParagraph(sourceLine); + interpreter.removeSectionOrParagraphLines(); interpreter.setInsideSectionOrParagraphMockBody(false); return ""; } @@ -206,9 +206,9 @@ private void processingAfterEchoingSourceLineToOutput() throws IOException { List arguments = interpreter.getPossibleMockArgs(); if (testSuiteParserController.mockExistsFor(identifier, type, arguments)){ if(interpreter.isInsideSectionOrParagraphMockBody()){ - interpreter.addBlockLines(testSuiteParserController.generateMockPerformCalls(identifier, type, arguments)); + interpreter.addSectionOrParagraphLines(testSuiteParserController.generateMockPerformCalls(identifier, type, arguments)); if (type.equals(Constants.CALL_TOKEN)){ - interpreter.addBlockLine(" CONTINUE"); + interpreter.addSectionOrParagraphLine(" CONTINUE"); } }else writerController.writeLines(testSuiteParserController.generateMockPerformCalls(identifier, type, arguments)); if (type.equals(Constants.SECTION_TOKEN) || type.equals(Constants.PARAGRAPH_TOKEN)){ @@ -226,14 +226,14 @@ private void closeReadersAndWriters(String programName) { writerController.closeWriter(programName); } - private void writeWhenOtherBlock(String sourceLine) throws IOException{ - writerController.writeLines(testSuiteParserController.generateWhenOtherBlock(currentMockType, interpreter.getBlockLines(), sourceLine, currentIdentifier, true)); + private void writeWhenOtherSectionOrParagraph(String sourceLine) throws IOException{ + writerController.writeLines(testSuiteParserController.generateWhenOtherSectionOrParagraph(currentMockType, interpreter.getSectionOrParagraphLines(), sourceLine, currentIdentifier, true)); } private void echoingSourceLineToOutput(String sourceLine){ try{ if(interpreter.isInsideSectionOrParagraphMockBody()){ - interpreter.addBlockLine(); + interpreter.addSectionOrParagraphLine(); } sourceLine = tryInsertEndEvaluateAtMockedCompomentEnd(sourceLine); if(!interpreter.isInsideSectionOrParagraphMockBody()){ diff --git a/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java b/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java index 91c15e5e..d0cf55b1 100644 --- a/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java +++ b/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java @@ -357,13 +357,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-0-0-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 000-START " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: " + Constants.NEWLINE + + " *WhenOther of: SECTION: 000-START " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Value1\" to VALUE-1 " + Constants.NEWLINE + " EXIT SECTION " + Constants.NEWLINE + @@ -520,13 +518,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-0-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 000-START " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 000-START " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Value1\" to VALUE-1 " + Constants.NEWLINE + " EXIT SECTION. " + Constants.NEWLINE + @@ -547,13 +543,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE+ " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-1-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 100-WELCOME " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 100-WELCOME " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Hello\" to VALUE-1. " + Constants.NEWLINE + " . " + Constants.NEWLINE + @@ -572,13 +566,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE+ " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-2-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 200-GOODBYE " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 200-GOODBYE " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Bye\" to VALUE-1 " + Constants.NEWLINE + " . " + Constants.NEWLINE + @@ -798,13 +790,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-0-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 000-START " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 000-START " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Value1\" to VALUE-1 " + Constants.NEWLINE + " EXIT SECTION. " + Constants.NEWLINE + @@ -824,13 +814,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE+ " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-1-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 100-WELCOME " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 100-WELCOME " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " * CALL 'prog1' USING BY CONTENT VALUE-1, VALUE-2. " + Constants.NEWLINE + " EVALUATE UT-TEST-SUITE-NAME " + Constants.NEWLINE + @@ -860,13 +848,11 @@ private String removeBoilerPlateCode(String code, List boilerPlateTags){ " . " + Constants.NEWLINE + " " + Constants.NEWLINE+ " ***************************************************************** " + Constants.NEWLINE + - " *WhenOther block called " + Constants.NEWLINE + + " *WhenOther Paragraph or Section called " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " UT-1-2-2-WO SECTION. " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + - " *When other block of: SECTION: 200-GOODBYE " + Constants.NEWLINE + - " *In testsuite: \"Mocking tests\" " + Constants.NEWLINE + - " *In testcase: \"Simply a test\" " + Constants.NEWLINE + + " *WhenOther of: SECTION: 200-GOODBYE " + Constants.NEWLINE + " ***************************************************************** " + Constants.NEWLINE + " MOVE \"Bye\" to VALUE-1 " + Constants.NEWLINE + " * CALL bogus USING VALUE-1 " + Constants.NEWLINE +