
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
MyFileWriterTest.java
import static org.junit.Assert.assertEquals;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class MyFileWriterTest {
MyFileWriter myFileWriter1;
MyFileWriter myFileWriter2;
MyFileWriter myFileWriter3;
MyFileWriter myFileWriter4;
@BeforeEach
void setUp() {
this.myFileWriter1 =new MyFileWriter("test1_fw.txt"); // file with multiple words per line
this.myFileWriter2 =new MyFileWriter("test2_fw.txt"); // similar to info.txt file
this.myFileWriter3 =new MyFileWriter("test3_fw.txt"); // similar to info.txt file but with personal info added
this.myFileWriter4 =new MyFileWriter("test4_fw.txt"); // similar to info.txt file but with different info and personal info added
}
@Test
publicvoid testWriteToFile() {
ArrayList<String> actualLines = new ArrayList<String>();
// Test file with multiple words per line
actualLines.add("hello world");
actualLines.add("Course Name and ID");
actualLines.add("The quick brown fox jumps over the lazy dog.");
// Write to file
myFileWriter1.writeToFile(actualLines);
// Read the written file to test its contents
ArrayList<String> expectedLines = readWrittenFile("test1_fw.txt");
assertEquals(expectedLines, actualLines);
// Test original info.txt file
actualLines.removeAll(actualLines);
actualLines.add("Course: MCIT_590");
actualLines.add("CourseID: 590");
actualLines.add("StudentID: 101");
// Write to file
myFileWriter2.writeToFile(actualLines);
// Read the written file to test its contents
expectedLines = readWrittenFile("test2_fw.txt");
assertEquals(expectedLines, actualLines);
// TODO write at least 2 additional test cases using different MyFileWriters
// Recommended: A test similar to info.txt file but with personal info added
// Recommended: A test similar to info.txt file but with different info and personal info added
}
/**
* Helper method for reading in the written file to check its contents.
* @param writtenFilename to read
* @return an ArrayList of the lines from the written file
*/
private ArrayList<String> readWrittenFile(String writtenFilename) {
ArrayList<String> expectedLines = new ArrayList<String>();
try {
BufferedReader file = new BufferedReader(new FileReader(writtenFilename));
String line = file.readLine();
while (line !=null) {
expectedLines.add(line);
line = file.readLine();
}
file.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return expectedLines;
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 5 images

Knowledge Booster
Similar questions
- sandbox $ javac Eggs.javaEggs.java:5: error: cannot find symbol Scanner scan= new Scanner(system.in); ^ symbol: variable system location: class EggsEggs.java:7: error: package system does not exist system.out.println("How many eggs?"); ^Eggs.java:14: error: package system does not exist system.out.println("You ordered "+eggs+" eggs. That's "+dozens+" at $3.25 per dozen and "+ind+" loose eggs at 45 cents for a total of $" +((dozens*3.25)+(ind*0.45))+"."); ^3 errorssandbox $ java EggsError: Could not find or load main class Eggssandbox $ I keep getting errors!arrow_forwardCreate a Java instance class named Rectangle that has two integer fields named length and width. Include two onstructors: a default constructor to initialize each of the fields to 1 and a second constructor that takes two rguments. Define a getter method for each of the fields.arrow_forwardI have 2 java files. Car.java and CarValue.Java. Car.java looks like " public class Car {private int modelYear; // TODO: Declare purchasePrice field (int) private int currentValue;public void setModelYear(int userYear){modelYear = userYear;}public int getModelYear() {return modelYear;}// TODO: Define setPurchasePrice() method// TODO: Define getPurchasePrice() methodpublic void calcCurrentValue(int currentYear) {double depreciationRate = 0.15;int carAge = currentYear - modelYear;// Car depreciation formulacurrentValue = (int) Math.round(purchasePrice * Math.pow((1 - depreciationRate), carAge));}// TODO: Define printInfo() method to output modelYear, purchasePrice, and currentValue}". While CarValue.java looks like " import java.util.Scanner;import java.lang.Math; public class CarValue {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);Car myCar = new Car();int userYear = scnr.nextInt();int userPrice = scnr.nextInt();int userCurrentYear =…arrow_forward
- Class UserPigPlayer java.lang.Object UserPigPlayer All Implemented Interfaces:PigPlayerpublic class UserPigPlayerextends java.lang.Objectimplements PigPlayer UserPigPlayer - text interface to query user for roll/hold decisions Constructor Summary UserPigPlayer() Creates a new UserPigPlayer instance to allow user play via standard inputOutput format: Print an instruction line "Enter nothing to roll; enter anything to hold." Method Summary boolean isRolling(int myScore, int otherScore, int turnTotal) isRolling - return whether or not the player rolls, given the current game state. Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait Constructor Detail UserPigPlayer public UserPigPlayer()Creates a new UserPigPlayer instance to allow user play via standard inputOutput format: Print an instruction line "Enter nothing to roll; enter anything to…arrow_forwardJAVA PROGRAM ASAP Please give me a new program ASAP BECAUSE the program down below does not pass all the test cases when I upload it to hypergrade. The program must pass the test case when uploaded to Hypergrade. I have provided the failed test cases as a screenshot. import java.util.HashMap;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.Scanner;public class MorseCodeConverter { private static HashMap<Character, String> morseMap = new HashMap<>(); public static void main(String[] args) { loadMorseCodes(); Scanner scanner = new Scanner(System.in); System.out.println("Please enter a string to convert to Morse code:"); String input = scanner.nextLine().toUpperCase(); String morseCode = convertToMorse(input); System.out.println(morseCode); } private static void loadMorseCodes() { try (BufferedReader reader = new BufferedReader(new FileReader("morse.txt"))) {…arrow_forwardI need help With this problem for JAVAFX. if possible can it work in eclipse. GeometricObjects code public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } /** Return color */ public String getColor() { return color; } /** Set a new color */ public void setColor(String color) { this.color = color; } /** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; } /** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; } /** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY