diff --git a/app/src/main/java/cse/gradle/Server/APIs/DallEApi.java b/app/src/main/java/cse/gradle/Server/APIs/DallEApi.java index 2bf1db9..f08433d 100644 --- a/app/src/main/java/cse/gradle/Server/APIs/DallEApi.java +++ b/app/src/main/java/cse/gradle/Server/APIs/DallEApi.java @@ -1,5 +1,5 @@ package cse.gradle.Server.APIs; public interface DallEApi { - + public String generateChatResponse(String[] messages); } diff --git a/app/src/main/java/cse/gradle/Server/APIs/MockDallEApiClient.java b/app/src/main/java/cse/gradle/Server/APIs/MockDallEApiClient.java new file mode 100644 index 0000000..0e732d3 --- /dev/null +++ b/app/src/main/java/cse/gradle/Server/APIs/MockDallEApiClient.java @@ -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 + } +} \ No newline at end of file diff --git a/app/src/test/java/cse/gradle/Feature11Tests.java b/app/src/test/java/cse/gradle/Feature11Tests.java index f286dc4..0bebb93 100644 --- a/app/src/test/java/cse/gradle/Feature11Tests.java +++ b/app/src/test/java/cse/gradle/Feature11Tests.java @@ -7,6 +7,12 @@ 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; @@ -14,5 +20,25 @@ 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()); + } + } + +} \ No newline at end of file