Skip to content

Commit

Permalink
refactor - third part
Browse files Browse the repository at this point in the history
  • Loading branch information
issacto committed Aug 10, 2023
1 parent 58a1f87 commit 1941861
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class InterpreterController {
private boolean insideSectionOrParagraphMockBody;
private TreeMap<Integer,String> currentDataStructure;
private final String stubTag;
private Block block;
private SectionOrParagraph sectionOrParagraph;

public InterpreterController(BufferedReader sourceReader) {
if (sourceReader == null) {
Expand All @@ -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
Expand Down Expand Up @@ -507,27 +507,27 @@ private void resetPossibleMockValues(){
possibleMockType = null;
}

public List<String> getBlockLines(){
return block.getLines();
public List<String> 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<String> lines){
public void addSectionOrParagraphLines(List<String> lines){
for (String line : lines){
block.addLine(line);
sectionOrParagraph.addLine(line);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.util.ArrayList;
import java.util.List;

public class Block {
public class SectionOrParagraph {

private List<String> lines;

public Block(){
public SectionOrParagraph(){
lines = new ArrayList<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,9 @@ public String getCurrentFieldName() {
return currentFieldName;
}

public WhenOther getWhenOtherBlock(String type, List<String> lines, String itdentifier, boolean withComments){
WhenOther whenOther = new WhenOther(currentTestSuiteName ,currentTestCaseName, testSuiteNumber, testCaseNumber,whenOtherNumber);
public WhenOther getWhenOtherSectionOrParagraph(String type, List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ public void prepareNextParse() {
Config.setDecimalPointIsCommaFromFile();
}

public List<String> generateWhenOtherBlock(String type, List<String> blocklines, String sourceLine, String identifier, boolean withComments) throws IOException{
public List<String> generateWhenOtherSectionOrParagraph(String type, List<String> sectionOrParagraphlines, String sourceLine, String identifier, boolean withComments) throws IOException{
List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ public class WhenOther {
private String identifier;
private String type;
private List<String> 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;
Expand All @@ -41,10 +36,6 @@ public void addLines(List<String> lines) {
this.lines.addAll(lines);
}

public void setScope(MockScope scope) {
this.scope = scope;
}

public void setType(String type) {
this.type = type;
}
Expand All @@ -65,11 +56,7 @@ public void setIdentifier(String identifier) {
public List<String> getCommentText(){
List<String> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ String generateWhenOtherCall(WhenOther whenOther) {

List<String> generateWhenOther(WhenOther whenOther, boolean withComments){
List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand Down Expand Up @@ -206,9 +206,9 @@ private void processingAfterEchoingSourceLineToOutput() throws IOException {
List<String> 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)){
Expand All @@ -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()){
Expand Down
Loading

0 comments on commit 1941861

Please sign in to comment.