From 9b34d8c6ea54537065c6a7f4726d6b703142782d Mon Sep 17 00:00:00 2001 From: Matthew Tan <48768802+Tantime@users.noreply.github.com> Date: Tue, 5 Dec 2023 23:06:11 -0800 Subject: [PATCH 1/3] Created MockAudioRecorder class --- .../main/java/cse/gradle/AudioRecorder.java | 3 +- .../java/cse/gradle/MockAudioRecorder.java | 37 +++++++++++++++++++ app/src/main/java/cse/gradle/MockModel.java | 2 +- app/src/main/java/cse/gradle/Model.java | 2 - 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/cse/gradle/MockAudioRecorder.java diff --git a/app/src/main/java/cse/gradle/AudioRecorder.java b/app/src/main/java/cse/gradle/AudioRecorder.java index 72a369d..64940c4 100644 --- a/app/src/main/java/cse/gradle/AudioRecorder.java +++ b/app/src/main/java/cse/gradle/AudioRecorder.java @@ -52,7 +52,6 @@ public void startRecording(String fileName) { @Override public void run() { try { - // System.out.println("Start recording"); // the format of the TargetDataLine DataLine.Info dataLineInfo = new DataLine.Info( TargetDataLine.class, @@ -67,12 +66,12 @@ public void run() { targetDataLine); // the file that will contain the audio data - // File audioFile = new File("recording.wav"); File audioFile = new File(fileName); AudioSystem.write( audioInputStream, AudioFileFormat.Type.WAVE, audioFile); + audioInputStream.close(); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/app/src/main/java/cse/gradle/MockAudioRecorder.java b/app/src/main/java/cse/gradle/MockAudioRecorder.java new file mode 100644 index 0000000..58f8d72 --- /dev/null +++ b/app/src/main/java/cse/gradle/MockAudioRecorder.java @@ -0,0 +1,37 @@ +package cse.gradle; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import java.io.File; + +public class MockAudioRecorder extends AudioRecorder { + + private boolean isRecordingStarted = false; + + @Override + public void startRecording(String fileName) { + if (!isRecordingStarted) { + isRecordingStarted = true; + // Simulate the start of recording without actual audio capture + simulateRecording(fileName); + } + } + + @Override + public void stopRecording() { + if (isRecordingStarted) { + // Simulate the stop of recording without actual audio capture + isRecordingStarted = false; + } + } + + // Simulate the recording process without actual audio capture + private void simulateRecording(String fileName) { + try { + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(fileName)); + audioInputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/cse/gradle/MockModel.java b/app/src/main/java/cse/gradle/MockModel.java index a6d8a7b..e85018c 100644 --- a/app/src/main/java/cse/gradle/MockModel.java +++ b/app/src/main/java/cse/gradle/MockModel.java @@ -9,7 +9,7 @@ public class MockModel extends Model { public MockModel() { // call the super constructor with the test server url - super(mockUrlString); + super(mockUrlString); // hard code the user id to be the test user this.userId = mockUserId; } diff --git a/app/src/main/java/cse/gradle/Model.java b/app/src/main/java/cse/gradle/Model.java index 9f81ecc..5cba33f 100644 --- a/app/src/main/java/cse/gradle/Model.java +++ b/app/src/main/java/cse/gradle/Model.java @@ -24,9 +24,7 @@ import java.net.URISyntaxException; import java.io.*; -import java.net.*; import java.util.*; -import org.json.*; public class Model implements ModelSubject { protected String userId; From c64b27d673df6789a5552578d0733d3bfdba97b5 Mon Sep 17 00:00:00 2001 From: Igor Aprelev Date: Tue, 5 Dec 2023 23:07:48 -0800 Subject: [PATCH 2/3] Feature10 tests done --- .../main/java/cse/gradle/MockController.java | 33 +++++++++++++++++++ app/src/main/java/cse/gradle/local/login.txt | 3 +- .../test/java/cse/gradle/Feature10Tests.java | 32 +++++++++++++++++- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/cse/gradle/MockController.java diff --git a/app/src/main/java/cse/gradle/MockController.java b/app/src/main/java/cse/gradle/MockController.java new file mode 100644 index 0000000..5bfef7f --- /dev/null +++ b/app/src/main/java/cse/gradle/MockController.java @@ -0,0 +1,33 @@ +package cse.gradle; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import cse.gradle.View.UserLogin; + +public class MockController { + public boolean loginUser(String username, String password) throws IOException { + // Checks if the automic login file exists; if it does, and username matches the + // one in file, do automatic login + if ((new File("src/main/java/cse/gradle/local/login.txt")).exists()) { + File loginFile = new File("src/main/java/cse/gradle/local/login.txt"); + BufferedReader reader = new BufferedReader( + new FileReader(loginFile)); + if (username.equals(reader.readLine())) { + reader.close(); + // String postResponse = model.performLoginRequest(loginFile); + // if (postResponse.equals("Error: Server down")) { + // appScenes.displayServerDownConstructor(); + // return false; + // } + // reader.close(); + return true; + } + reader.close(); + } + return false; + } + +} diff --git a/app/src/main/java/cse/gradle/local/login.txt b/app/src/main/java/cse/gradle/local/login.txt index 6d5e3a7..e9f12b6 100644 --- a/app/src/main/java/cse/gradle/local/login.txt +++ b/app/src/main/java/cse/gradle/local/login.txt @@ -1,2 +1 @@ -bob2000 -2000 \ No newline at end of file +login \ No newline at end of file diff --git a/app/src/test/java/cse/gradle/Feature10Tests.java b/app/src/test/java/cse/gradle/Feature10Tests.java index fde3892..6531206 100644 --- a/app/src/test/java/cse/gradle/Feature10Tests.java +++ b/app/src/test/java/cse/gradle/Feature10Tests.java @@ -13,6 +13,36 @@ class Feature10Tests { /* --------------------------------- UNIT TESTS --------------------------------- */ - + @Test + void automaticLoginChecked() { + MockController controller = new MockController(); + boolean loginStatus = false; + try { + loginStatus = controller.loginUser("abc", "abc"); + } catch (Exception e) { + System.out.println(e); + } + assert(!loginStatus); + } /* --------------------------------- BDD TESTS --------------------------------- */ + @Test + void loginLogoutWithAutoLogin() { + User Joe = new User("abc", "abc"); + MockController controller = new MockController(); + boolean loginStatus = false; + try { + loginStatus = controller.loginUser(Joe.getUsername(), Joe.getPassword()); + } catch (Exception e) { + System.out.println(e); + } + assert(!loginStatus); + Joe = new User("login", "checked"); + loginStatus = true; + try { + loginStatus = controller.loginUser(Joe.getUsername(), Joe.getPassword()); + } catch (Exception e) { + System.out.println(e); + } + assert(loginStatus); + } } From ec9ef65287e9caf97c27034c60c5f0e70fa34668 Mon Sep 17 00:00:00 2001 From: Igor Aprelev Date: Tue, 5 Dec 2023 23:18:42 -0800 Subject: [PATCH 3/3] feature 14 tests done --- .../test/java/cse/gradle/Feature12Tests.java | 3 +- .../test/java/cse/gradle/Feature14Tests.java | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/cse/gradle/Feature12Tests.java b/app/src/test/java/cse/gradle/Feature12Tests.java index cfcc0ec..3dd694a 100644 --- a/app/src/test/java/cse/gradle/Feature12Tests.java +++ b/app/src/test/java/cse/gradle/Feature12Tests.java @@ -2,7 +2,7 @@ * This Java source file was generated by the Gradle 'init' task. * * - * Functionality: Includes Unit and BDD Scenario Testing for User Story #_: ___________ + * Functionality: Includes Unit and BDD Scenario Testing for User Story #12: Regenerate recipe */ package cse.gradle; @@ -14,5 +14,6 @@ class Feature12Tests { /* --------------------------------- UNIT TESTS --------------------------------- */ + /* --------------------------------- BDD TESTS --------------------------------- */ } diff --git a/app/src/test/java/cse/gradle/Feature14Tests.java b/app/src/test/java/cse/gradle/Feature14Tests.java index 9298824..dc954c8 100644 --- a/app/src/test/java/cse/gradle/Feature14Tests.java +++ b/app/src/test/java/cse/gradle/Feature14Tests.java @@ -2,17 +2,47 @@ * This Java source file was generated by the Gradle 'init' task. * * - * Functionality: Includes Unit and BDD Scenario Testing for User Story #_: ___________ + * Functionality: Includes Unit and BDD Scenario Testing for User Story #14: Meal Type Tags */ package cse.gradle; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; +import java.util.List; class Feature14Tests { /* --------------------------------- UNIT TESTS --------------------------------- */ + @Test + void addMealTypeTag() { + Recipe r1 = new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast"); + Recipe r2 = new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch"); + Recipe r3 = new Recipe("potatoes", "boil the potatoes", "dinner", "boiled potatoes"); + List rList = new ArrayList<>(); + + rList.add(r1); + rList.add(r2); + rList.add(r3); + + assertEquals(r1.getCategory(), "breakfast"); + assertEquals(r2.getCategory(), "lunch"); + assertEquals(r3.getCategory(), "dinner"); + } /* --------------------------------- BDD TESTS --------------------------------- */ + @Test + void manipulatingTypeTagsInView() { + Recipe r1 = new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast"); + Recipe r2 = new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch"); + Recipe r3 = new Recipe("potatoes", "boil the potatoes", "dinner", "boiled potatoes"); + List rList = new ArrayList<>(); + + View view = new MockView(rList); + List rList1 = view.getListOfRecipes(); + + assertEquals(rList1.get(0).getCategory(), "breakfast"); + assertEquals(rList1.get(1).getCategory(), "lunch"); + assertEquals(rList1.get(2).getCategory(), "dinner"); + } }