Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
id "io.freefair.lombok" version "6.3.0"
id 'jacoco'
}

repositories {
Expand All @@ -19,11 +21,12 @@ repositories {
}

dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'

// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'

// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
Expand All @@ -33,18 +36,40 @@ dependencies {
implementation 'org.kordamp.ikonli:ikonli-fontawesome5-pack:12.1.0'
implementation 'org.kordamp.ikonli:ikonli-materialdesign2-pack:12.1.0'
implementation 'org.kordamp.ikonli:ikonli-material2-pack:12.1.0'

//testfx
implementation 'org.testfx:testfx-core:4.0.16-alpha'
implementation 'org.testfx:testfx-junit5:4.0.16-alpha'

//log4j2
implementation group: 'org.apache.logging.log4j', name: 'log4j', version: '2.8.2', ext: 'pom'
}

application {
// Define the main class for the application.
mainClass = 'edu.isu.cs.cs2263.hw02.App'
}

tasks.named('test') {
// Use junit platform for unit tests.
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}

jacoco {
toolVersion = "0.8.7"
reportsDirectory = layout.buildDirectory.dir('customJacocoReportDir')
}


javafx {
version = "17"
modules = ['javafx.controls']
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/edu/isu/cs/cs2263/hw02/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import lombok.Getter;
import lombok.Setter;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.materialdesign2.MaterialDesignF;
import org.kordamp.ikonli.materialdesign2.MaterialDesignP;
Expand All @@ -27,6 +29,7 @@

public class App extends Application {

@Getter @Setter
private Vector<Course> courses;
private AppView currentView;
private final Map<String, AppView> views;
Expand Down Expand Up @@ -64,24 +67,28 @@ public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Course View");

Button display = new Button("Display (dept.)");
display.setId("displayDepts");
display.setOnAction(event -> {
displayList();
});
display.setGraphic(FontIcon.of(MaterialDesignF.FORMAT_LIST_TEXT, 20));

Button newCourse = new Button("New Course");
newCourse.setId("newCourse");
newCourse.setOnAction(event -> {
showCourseForm();
});
newCourse.setGraphic(FontIcon.of(MaterialDesignP.PLAYLIST_PLUS, 20));

Button exit = new Button("Exit");
exit.setId("exit");
exit.setOnAction(event -> {
exit();
});
exit.setGraphic(FontIcon.of(MaterialDesignP.POWER, 20));

depts = new ChoiceBox<>();
depts.setId("dropDown");
depts.setOnAction(event -> {
int selectedIndex = depts.getSelectionModel().getSelectedIndex();
// update the display button
Expand Down Expand Up @@ -126,10 +133,6 @@ public void start(Stage primaryStage) throws Exception {
primaryStage.show();
}

public Vector<Course> getCourses() {
return courses;
}

private void setView(String viewName) {
mainLayout.getChildren().remove(currentView.getView());
currentView = views.get(viewName);
Expand Down
39 changes: 5 additions & 34 deletions app/src/main/java/edu/isu/cs/cs2263/hw02/data/Course.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package edu.isu.cs.cs2263.hw02.data;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter @Setter
public class Course {

public static final String[] CODES = { "CS", "CHEM", "PHYS", "MATH", "BTNY", "ZOO" };
Expand All @@ -10,47 +15,13 @@ public class Course {
private int credits;
private String code;

public Course() {}

public Course(String name, String code, int number, int credits) {
this.name = name;
this.code = code;
this.number = number;
this.credits = credits;
}

public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getCredits() {
return credits;
}

public void setCredits(int credits) {
this.credits = credits;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@Override
public String toString() {
return String.format("%s %d %s (%d)", code, number, name, credits);
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/edu/isu/cs/cs2263/hw02/views/AppView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import edu.isu.cs.cs2263.hw02.App;
import javafx.scene.Node;
import lombok.Getter;
import lombok.Setter;

public abstract class AppView implements IAppView {

@Getter @Setter
protected Node view;
protected App parent;

public AppView(App parent) {
this.parent = parent;
initView();
}

public Node getView() {
return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.TextAlignment;
import lombok.Getter;
import lombok.Setter;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.materialdesign2.MaterialDesignP;
import org.kordamp.ikonli.materialdesign2.MaterialDesignR;

public class CoursesFormView extends AppView {

@Getter @Setter
private TextField tfName;
private Spinner<Integer> spnNumber;
private Spinner<Integer> spnCredits;
Expand All @@ -38,6 +41,7 @@ public void initView() {
tfName = new TextField();
tfName.setPromptText("Enter a course name...");
tfName.setMinWidth(400);
tfName.setId("newName");

Label lblName = new Label("Name:");
lblName.setTextAlignment(TextAlignment.RIGHT);
Expand Down
74 changes: 74 additions & 0 deletions app/src/test/java/edu/isu/cs/cs2263/hw02/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package edu.isu.cs.cs2263.hw02;

import javafx.scene.Node;
import javafx.scene.control.ChoiceBox;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.testfx.api.FxToolkit;
import org.testfx.framework.junit5.*;
import org.junit.jupiter.api.Test;
import javafx.stage.Stage;
import org.testfx.matcher.base.NodeMatchers;

import java.util.concurrent.TimeoutException;
import static org.testfx.api.FxAssert.verifyThat;
import static org.testfx.assertions.api.Assertions.assertThat;

class AppTest extends ApplicationTest {

@BeforeAll
public static void setUpClass() throws Exception {
ApplicationTest.launch(App.class);
}

@Override
public void start(Stage stage) throws Exception{
stage.show();
}

@AfterEach
public void afterEachTest() throws TimeoutException {
FxToolkit.hideStage();
release(new KeyCode[]{});
release(new MouseButton[]{});
}

@Test
public void ensureDropDownShows() throws InterruptedException {
clickOn("#dropDown");
verifyThat("#dropDown", NodeMatchers.isVisible());
}

@Test
public void ensureDropDownContents() throws InterruptedException {
clickOn("#dropDown");
verifyThat("#dropDown", NodeMatchers.hasChild("Computer Science (CS)"));
}

@Test
public void testSetView(){
clickOn("#dropDown");
clickOn("Botany (BTNY)");
clickOn("Display (dept.)");
}

@Test
public void testReset(){
clickOn("New Course");
clickOn("#newName");
write("new one");
clickOn("Reset");
}

@Test
public void testAdd(){
clickOn("New Course");
clickOn("#newName");
write("added name");
clickOn("Add Course");
}

}
65 changes: 65 additions & 0 deletions app/src/test/java/edu/isu/cs/cs2263/hw02/CourseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package edu.isu.cs.cs2263.hw02;

import edu.isu.cs.cs2263.hw02.data.Course;

import org.checkerframework.checker.units.qual.C;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CourseTest {

Course course;

@BeforeEach
public void setup(){
course = new Course("name", "code?", 15, 2);
}

@Test
public void testSetNumber(){
course.setNumber(1);
assertEquals(1, course.getNumber());
}
@Test
public void testGetNumber(){
assertEquals(15, course.getNumber());
course.setNumber(25);
assertEquals(25, course.getNumber());
}
@Test
public void testSetName(){
course.setName("new name");
assertEquals("new name", course.getName());
}
@Test
public void testGetName(){
assertEquals("name", course.getName());
course.setName("different name?");
assertEquals("different name?", course.getName());
}
@Test
public void testSetCredits(){
course.setCredits(5);
assertEquals(5, course.getCredits());
}
@Test
public void testGetCredits(){
assertEquals(2, course.getCredits());
course.setCredits(6);
assertEquals(6, course.getCredits());
}
@Test
public void testSetCode(){
course.setCode("2033");
assertEquals("2033", course.getCode());
}
@Test
public void testGetCode(){
assertEquals("code?", course.getCode());
}

}