-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/Tests' into Feature-11-Tests
- Loading branch information
Showing
26 changed files
with
682 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/cse/gradle/Server/APIs/MockDallEApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cse.gradle.Server.APIs; | ||
|
||
public class MockDallEApiClient extends DallEApiClient { | ||
@Override | ||
public String generateChatResponse(String prompt) { | ||
// BEGIN: Mock generateChatResponse | ||
// Check if the prompt is valid | ||
if (prompt == null || prompt.isEmpty()) { | ||
throw new IllegalArgumentException("Prompt cannot be null or empty"); | ||
} | ||
|
||
// Return a preset image URL provided by wikipedia | ||
return "https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg?20070224000419"; | ||
// END: Mock generateChatResponse | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cse.gradle.Server.APIs; | ||
|
||
public class MockGPT implements ChatGPTApi { | ||
public String[] generateResponse(String mealType, String ingredients) throws Exception { | ||
String[] response = new String[4]; | ||
|
||
response[0] = "Mock Title"; | ||
response[1] = mealType; | ||
response[2] = ingredients; | ||
response[3] = "Mock Instructions"; | ||
|
||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cse.gradle.Server.APIs; | ||
|
||
import java.io.File; | ||
import java.nio.file.NoSuchFileException; | ||
|
||
public class MockWhisper implements WhisperApi { | ||
@Override | ||
public String generateResponse(String filePath) throws Exception { | ||
|
||
File file = new File(filePath); | ||
if (!file.exists()) { | ||
throw new NoSuchFileException(filePath); | ||
} | ||
|
||
return "Mock Transcription Result"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
abc | ||
abc | ||
login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cse.gradle; | ||
|
||
import cse.gradle.Server.APIs.MockGPT; | ||
import cse.gradle.Server.APIs.MockWhisper; | ||
import cse.gradle.Server.APIs.ChatGPTApi; | ||
import cse.gradle.Server.APIs.WhisperApi; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.nio.file.NoSuchFileException; | ||
|
||
public class APITests { | ||
|
||
@Test | ||
public void testChatGPTGenerateResponse() { | ||
// Create an instance of the MockGPT for testing | ||
ChatGPTApi chatGPTApi = new MockGPT(); | ||
|
||
try { | ||
// Test the generateResponse method with mock data | ||
String[] mockResponse = chatGPTApi.generateResponse("Dinner", "Pasta, Sauce, Cheese"); | ||
|
||
// Add assertions to verify the correctness of the response | ||
assertNotNull(mockResponse); | ||
assertEquals(4, mockResponse.length); | ||
assertEquals("Mock Title", mockResponse[0]); | ||
assertEquals("Dinner", mockResponse[1]); | ||
assertEquals("Pasta, Sauce, Cheese", mockResponse[2]); | ||
assertEquals("Mock Instructions", mockResponse[3]); | ||
} catch (Exception e) { | ||
// Handle exceptions or fail the test if an unexpected exception occurs | ||
fail("Exception occurred: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testWhisperGenerateResponse() { | ||
// Create an instance of the MockWhisper for testing | ||
WhisperApi whisperApi = new MockWhisper(); | ||
|
||
try { | ||
// Test the generateResponse method with mock data | ||
String mockTranscription = whisperApi.generateResponse("src/test/java/cse/gradle/APITests.java"); | ||
|
||
// Add assertions to verify the correctness of the response | ||
assertNotNull(mockTranscription); | ||
assertEquals("Mock Transcription Result", mockTranscription); | ||
} catch (Exception e) { | ||
// Handle exceptions or fail the test if an unexpected exception occurs | ||
fail("Exception occurred: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testWhisperGenerateResponseWithInvalidFile() { | ||
// Create an instance of the MockWhisper for testing | ||
WhisperApi whisperApi = new MockWhisper(); | ||
|
||
try { | ||
// Test the generateResponse method with an invalid file path | ||
assertThrows(NoSuchFileException.class, | ||
() -> whisperApi.generateResponse("nonexistentFilePath")); | ||
} catch (Exception e) { | ||
fail("Unexpected exception: " + e.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
* | ||
* | ||
* Functionality: Includes Unit and BDD Scenario Testing for User Story #10: Automatic Login | ||
*/ | ||
package cse.gradle; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.util.ArrayList; | ||
|
||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
* | ||
* | ||
* Functionality: Includes Unit and BDD Scenario Testing for User Story #_: ___________ | ||
*/ | ||
package cse.gradle; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.util.ArrayList; | ||
|
||
|
||
class Feature11Tests { | ||
/* --------------------------------- UNIT TESTS --------------------------------- */ | ||
|
||
/* --------------------------------- BDD TESTS --------------------------------- */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* This Java source file was generated by the Gradle 'init' task. | ||
* | ||
* | ||
* Functionality: Includes Unit and BDD Scenario Testing for User Story #12: Regenerate recipe | ||
*/ | ||
package cse.gradle; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import cse.gradle.Server.Server; | ||
import cse.gradle.Server.APIs.MockGPT; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.util.ArrayList; | ||
|
||
|
||
class Feature12Tests { | ||
@Test | ||
void testRegenerateRecipe() throws Exception { | ||
MockGPT chGpt = new MockGPT(); | ||
String[] response = chGpt.generateResponse("Lunch","meat, potatoes"); | ||
assertEquals("meat, potatoes", response[2]); | ||
response = chGpt.generateResponse("Breakfast","bread"); | ||
assertEquals("bread", response[2]); | ||
} | ||
} |
Oops, something went wrong.