Question: Create test cases for following classes using JUnit4. public class Parser extends AbstractParser{ @Override public UMLSequenceDiagram parse(String csvFilePath) { super.readFile(csvFilePath); super.checkFormat(); for (CSVRecord rec :

Create test cases for following classes using JUnit4.

public class Parser extends AbstractParser{

@Override public UMLSequenceDiagram parse(String csvFilePath) { super.readFile(csvFilePath); super.checkFormat(); for (CSVRecord rec : super.records) { // UMLSequenceDiagram // UMLSymbols: // UMLActor // UMLClass (Boundary, Entity, Control) // UMLLifeline // UMLActivationBox // UMLMessage (SynchronousMessage, UMLReturnMessage, UMLSelfMessage, UMLCreateMessage, UMLDeleteMessage) // UMLContainer (UMLAlternatives, UMLOption, UMLLoop, UMLCondition, UMLElse)

//Creation Conditions: if (rec.get("Name").equals("Actor")) { super.objectCr.createActor(rec); } if (rec.get("Name").equals("Object")) { super.objectCr.createClass(rec); } } return super.objectCr.getSequenceDiagram(); } }

public class ObjectCreator { private UMLSequenceDiagram seqDiagram; public ObjectCreator() { this.seqDiagram = new UMLSequenceDiagram(); } // UMLSequenceDiagram // UMLSymbols: // UMLActor // UMLClass (Boundary, Entity, Control) // UMLLifeline // UMLActivationBox // UMLMessage (SynchronousMessage, UMLReturnMessage, UMLSelfMessage, UMLCreateMessage, UMLDeleteMessage) // UMLContainer (UMLAlternatives, UMLOption, UMLLoop, UMLCondition, UMLElse) public UMLSequenceDiagram getSequenceDiagram() { return this.seqDiagram; } private UMLSymbol getByHeader(CSVRecord record, List allRecords, String header) { UMLSymbol result = null; String aHeader = record.get(header); if (!aHeader.isEmpty()) { for (CSVRecord rec : allRecords) { if (rec.get("Id").equals(aHeader)) { for (UMLSymbol symbol : this.seqDiagram.getUMLSymbols()) { if (symbol.getId() == Integer.parseInt(aHeader)) { result = symbol; } } } } } return result; } public UMLSymbol getSouce(CSVRecord record, List allRecords) { return getByHeader(record, allRecords, "Line Source"); } public UMLSymbol getDestination(CSVRecord record, List allRecords) { return getByHeader(record, allRecords, "Line Destination"); } //Make sure to add your classes to the overall sequence diagram (constructor, etc.) public void createActor(CSVRecord record) { String name = ""; String dataType = ""; String txtBox1 = record.get("Text Area 1"); if (!txtBox1.isEmpty()) { if (txtBox1.contains(":")) { dataType = txtBox1.substring(txtBox1.lastIndexOf(":") + 1); name = txtBox1.substring(0, txtBox1.lastIndexOf(":")); } else { name = txtBox1; } } new UMLActor(name, dataType, this.seqDiagram); } public void createClass(CSVRecord record) { String className = ""; String instanceName = ""; String txtBox1 = record.get("Text Area 1"); if (!txtBox1.isEmpty()) { if (txtBox1.contains(":")) { className = txtBox1.substring(txtBox1.lastIndexOf(":") + 1).trim(); instanceName = txtBox1.substring(0, txtBox1.lastIndexOf(":")).trim(); } else { instanceName = txtBox1; } } new UMLClass(className, instanceName, this.seqDiagram); } }

public class FormatManager { private INotifier notifier; public void addNotifier(INotifier notifier) { this.notifier = notifier; } public boolean checkFormat(CSVRecord header) { boolean result = true; if (!header.get(0).equals("Id")) { result = false; } if (!header.get(1).equals("Name")) { result = false; } if (!header.get(2).equals("Shape Library")) { result = false; } if (!header.get(3).equals("Page ID")) { result = false; } if (!header.get(4).equals("Contained By")) { result = false; } if (!header.get(5).equals("Line Source")) { result = false; } if (!header.get(6).equals("Line Destination")) { result = false; } if (!header.get(7).equals("Source Arrow")) { result = false; } if (!header.get(8).equals("Destination Arrow")) { result = false; } if (!header.get(9).equals("Text Area 1")) { result = false; } if (result = true && this.notifier != null) { sendNotification(); } return result; } private void sendNotification() { this.notifier.notifyFormatChange(); } }

public class CSVFileReader { private File csvFile; private List csvRecs; private Reader reader; public List getRecords() { return this.csvRecs; } public List readFile(String csvFilePath) { this.csvFile = new File(csvFilePath); if (csvFile.exists() && csvFile.isFile()) { try { this.reader = new FileReader(this.csvFile); readRecords(); } catch (FileNotFoundException e) { e.printStackTrace(); } } return this.csvRecs; } private void readRecords() { try { this.csvRecs = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(this.reader).getRecords(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } }

} public abstract class AbstractParser { private CSVFileReader csvRead; private FormatManager formatMng; protected ObjectCreator objectCr; protected List records; public AbstractParser() { this.csvRead = new CSVFileReader(); this.formatMng = new FormatManager(); this.objectCr = new ObjectCreator(); } // TODO Return output objects public abstract UMLSequenceDiagram parse(String csvFilePath); protected List readFile(String csvFilePath) { this.records = csvRead.readFile(csvFilePath); return this.records; } public void addNotifier(INotifier notifiers) { this.formatMng.addNotifier(notifiers); } protected boolean checkFormat() { boolean result = false; if (!this.records.isEmpty()) { result = formatMng.checkFormat(this.records.get(0)); } return result; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!