Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorkw7 committed Dec 6, 2023
1 parent ed59d68 commit 8e1aee2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/cse/gradle/Server/APIs/DallEApi.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package cse.gradle.Server.APIs;

public interface DallEApi {

public String generateChatResponse(String[] messages);
}
17 changes: 17 additions & 0 deletions app/src/main/java/cse/gradle/Server/APIs/MockDallEApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
}
}
30 changes: 28 additions & 2 deletions app/src/test/java/cse/gradle/Feature11Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,38 @@
package cse.gradle;

import org.junit.jupiter.api.Test;

import cse.gradle.Server.APIs.ChatGPTApi;
import cse.gradle.Server.APIs.DallEApi;
import cse.gradle.Server.APIs.MockDallEApiClient;
import cse.gradle.Server.APIs.MockGPT;

import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;


class Feature11Tests {
/* --------------------------------- UNIT TESTS --------------------------------- */

/* --------------------------------- BDD TESTS --------------------------------- */
}
@Test
public void testDalleGenerateResponse() {
// Create an instance of the MockGPT for testing
DallEApi dallEApi = new MockDallEApiClient();

try {
// Test the generateResponse method with mock data
String mockResponse = dallEApi.generateChatResponse("Mock prompt");

// Add assertions to verify the correctness of the response
assertNotNull(mockResponse);
// Check if the response is a valid URL
mockResponse = mockResponse.toLowerCase();
assertTrue(mockResponse.startsWith("http"));
assertTrue(mockResponse.contains(".jpg"));
} catch (Exception e) {
// Handle exceptions or fail the test if an unexpected exception occurs
fail("Exception occurred: " + e.getMessage());
}
}

}

0 comments on commit 8e1aee2

Please sign in to comment.