Question: Use JUnit to create Unit Tests for the following Courses class: Courses.java import java.util.ArrayList; import java.util.Iterator; import java.util.stream.Stream; import java.util.*; public class Courses { ArrayList

Use JUnit to create Unit Tests for the following Courses class:

Courses.java

import java.util.ArrayList;

import java.util.Iterator;

import java.util.stream.Stream;

import java.util.*;

public class Courses {

ArrayList courses = new ArrayList();

void loadCourses() {

courses.add(new Course("COSC", "111", "Computer Programming I ",

"Introduction to the design, implementation, and understanding of computer programs. Topics include problem solving, algorithm design, and data and procedural abstraction, with emphasis on the development of working programs. ",

"Prerequisite: A score of 70% or higher in one of PREC 12, MATH 12, MATH 125."));

courses.add(new Course("COSC", "121", "Computer Programming II ",

"Advanced programming in the application of software engineering techniques to the design and implementation of programs manipulating complex data structures. ",

"Prerequisite: A score of 60% or higher in COSC 111"));

courses.add(new Course("COSC", "122", "Computer Fluency ",

"Introduction to computer skills (electronic communication, websites, Internet, document editing, programming, data analysis using spreadsheets/databases) and concepts (information representation, abstraction, algorithmic thinking). Course objectives are life-long productivity and understanding of technology in society ", "Prerequisite: none"));

courses.add(new Course("COSC", "222", "Data Structures ",

"Introduction to the design, implementation and analysis of data structures. Topics will include lists, stacks, queues, trees, and graphs. ",

"Prerequisite: A score of 60% or higher in COSC 121"));

}

public void listAll() {

Course c;

for (int i = 0; i < courses.size(); i++) {

c = courses.get(i);

System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);

}

}

void displayCourse(String number) {

Course c;

for (int i = 0; i < courses.size(); i++) {

c = courses.get(i);

if (c.number.equals(number)) {

System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);

return;

}

}

}

public void listAllIter() {

Iterator iterator = courses.iterator();

Course c;

while (iterator.hasNext()) {

c = iterator.next();

System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);

}

}

public void listAllStream() {

Stream stream = courses.stream();

stream.forEach(

c -> System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq));

}

public void storedStreams() {

Stream stream = courses.stream();

long count = stream.count();

System.out.println("There are " + count + " Courses stored");

}

public void database() {

Course c;

for (int i = 0; i < courses.size(); i++) {

if (courses.get(i).desc.contains("database")) {

c = courses.get(i);

System.out.println(c.accr + " " + c.number + " " + c.title + " " + c.desc + " " + c.prereq);

}

}

}

public void listNumbered() {

courses.sort(new Comparator() {

@Override

public int compare(Course o1, Course o2) {

// TODO Auto-generated method stub

return o1.number.compareTo(o2.number);

}

});

listAll();

}

public static void main(String[] args) {

Courses L = new Courses();

L.loadCourses();

L.listAll();

System.out.println("");

L.listAllIter();

System.out.println("");

L.listAllStream();

System.out.println("");

L.storedStreams();

System.out.println("");

L.database();

System.out.println("");

L.listNumbered();

}

}

Course.java

//extend/modify as needed to complete the lab

public class Course {

String accr, number, title, desc, prereq;

public Course(String accr, String number, String title, String desc, String prereq) {

this.accr = new String(accr);

this.number = new String(number);

this.title = new String(title);

this.desc = new String(desc);

this.prereq = new String(prereq);

}

}

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!