Skip to content

Commit

Permalink
merging updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aditijainn committed Dec 7, 2023
1 parent 260ce3c commit 4168263
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/test/java/AudioRecorderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public void setUp() {
// Mockito.verify(targetDataLine).stop();
// Mockito.verify(targetDataLine).close();
// }

}
48 changes: 48 additions & 0 deletions src/test/java/AutoLoginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import server.MongoDB;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

import org.bson.Document;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static com.mongodb.client.model.Filters.eq;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class AutoLoginTest {
private static MongoClient mongoClient;
private static MongoDatabase PantryPalDB;

@BeforeAll
public static void setUp() {
String testUri = "mongodb+srv://sraswan:[email protected]/?retryWrites=true&w=majority";
mongoClient = MongoClients.create(testUri);
PantryPalDB = mongoClient.getDatabase("PantryPal");
}

@Test
public void testAutoLoginSuccess() {
String username = "test";
String password = "password";
String userID = server.Account.loginAccount(username, password, false);
assertNotNull((userID));
}

@Test
public void testAutoLoginUnsuccessful() {
String username = "testuser";
String password = "testpasswordd";
String userID = server.Account.loginAccount(username, password, false);
assertEquals(userID, null);
}

@Test
public void testLoginE2E() {
testAutoLoginSuccess();
testAutoLoginUnsuccessful();
}
}

39 changes: 22 additions & 17 deletions src/test/java/ChatGPTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,26 @@ public void testGenerateSuccess() throws IOException, InterruptedException, URIS
assertEquals(expectedResponse, response);
}

// @Test
// public void testHandle() throws IOException, InterruptedException, URISyntaxException {
// String requestText = "Test Prompt";
// String responseText = "Generated Response";
// ByteArrayInputStream bis = new ByteArrayInputStream(requestText.getBytes());
// ByteArrayOutputStream bos = new ByteArrayOutputStream();

// when(exchange.getRequestBody()).thenReturn(bis);
// when(exchange.getResponseBody()).thenReturn(bos);
// doReturn(responseText).when(chatGPT).generate(anyString());

// chatGPT.handle(exchange);

// verify(chatGPT, times(1)).generate(requestText);
// String responseBody = bos.toString();
// assertEquals(responseText, responseBody.trim());
// }
// @Test
// public void testHandle() throws IOException, InterruptedException, URISyntaxException {
// String requestText = "Test Prompt";
// String responseText = "Generated Response";
// ByteArrayInputStream bis = new ByteArrayInputStream(requestText.getBytes());
// ByteArrayOutputStream bos = new ByteArrayOutputStream();

// when(exchange.getRequestBody()).thenReturn(bis);
// when(exchange.getResponseBody()).thenReturn(bos);
// doReturn(responseText).when(chatGPT).generate(anyString());

// chatGPT.handle(exchange);

// verify(chatGPT, times(1)).generate(requestText);
// String responseBody = bos.toString();
// assertEquals(responseText, responseBody.trim());
// }

@Test
public void testChatGPTE2E() throws IOException, InterruptedException, URISyntaxException {
testGenerateSuccess();
}
}
20 changes: 19 additions & 1 deletion src/test/java/CreateAccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static com.mongodb.client.model.Filters.and;
import static com.mongodb.client.model.Filters.eq;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -24,7 +25,7 @@ public static void setUp() {
}

@Test
public void testCreateAccount() {
public void testCreateAccountSuccessful() {
String username = "testuser";
String password = "testpassword";
server.Account.createAccount(username, password);
Expand All @@ -34,4 +35,21 @@ public void testCreateAccount() {
assertEquals(username, queryDocument.getString("username"), "Username should match");
assertEquals(password, queryDocument.getString("password"), "Password should match");
}

@Test
public void testCreateAccountUnsuccessful() {
String username = "test";
String password = "password";
String output = server.Account.createAccount(username, password);
MongoCollection<Document> accountsCollection = PantryPalDB.getCollection("accounts");
Document queryDocument = accountsCollection.find(and(eq("username", username), eq("password", password))).first();
assertEquals(queryDocument.toString(), "Document{{_id=65714a6024ebf878f9f2b35e, username=test, password=password}}");
assertEquals(output, null);
}

@Test
public void testCreateAccountE2E() {
testCreateAccountSuccessful();
testCreateAccountUnsuccessful();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.*;

public class FilterTest extends ApplicationTest {
public class FilterByMealTest extends ApplicationTest {

@BeforeAll
public static void initJFX() {
Expand All @@ -44,7 +44,7 @@ public void stop() throws Exception {
}

@Test
public void filterByOneMealType() {
public void testFilterByOneMealType() {
AppFrame mockAppFrame = Mockito.mock(AppFrame.class);
RecipeList list = new RecipeList(mockAppFrame);
Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list);
Expand Down Expand Up @@ -90,7 +90,7 @@ public void filterByOneMealType() {
}

@Test
public void filterByMultiMealType() {
public void testFilterByMultiMealType() {
AppFrame mockAppFrame = Mockito.mock(AppFrame.class);
RecipeList list = new RecipeList(mockAppFrame);
Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list);
Expand Down Expand Up @@ -138,7 +138,7 @@ public void filterByMultiMealType() {
}

@Test
public void deselectFilter() {
public void testDeselectFilter() {
AppFrame mockAppFrame = Mockito.mock(AppFrame.class);
RecipeList list = new RecipeList(mockAppFrame);
Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list);
Expand Down Expand Up @@ -175,4 +175,11 @@ public void deselectFilter() {
list.mealOptions.getCheckModel().clearCheck("Breakfast");
assertEquals(0, list.mealOptions.getCheckModel().getCheckedItems().size());
}

@Test
public void testFilterByMealE2E() {
testFilterByOneMealType();
testFilterByMultiMealType();
testDeselectFilter();
}
}
8 changes: 5 additions & 3 deletions src/test/java/ImagePreviewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public void testGenerateImage() {
assertTrue(recipe.isComplete());
}




@Test
public void testImagePreviewE2E() {
testGenerateImage();
}

}
18 changes: 16 additions & 2 deletions src/test/java/LoginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@ public static void setUp() {

@Test
public void testLoginAccount() {
String username = "testuser";
String password = "testpassword";
String username = "test";
String password = "password";
String userID = server.Account.loginAccount(username, password, false);
assertNotNull((userID));
}

@Test
public void testLoginAccountUnsuccessful() {
String username = "testuser";
String password = "testpasswordd";
String userID = server.Account.loginAccount(username, password, false);
assertEquals(userID, null);
}

@Test
public void testLoginE2E() {
testLoginAccount();
testLoginAccountUnsuccessful();
}
}
16 changes: 5 additions & 11 deletions src/test/java/RecipeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@ public void testRecipeCompletion() {
// assertTrue(recipe.isComplete());
}

/*
* this test case doesn't pass
*/

// @Test
// public void testRecipeIncomplete() {
// Recipe rec1 = new Recipe();
// rec1.getName().setText("Chicken Stir-Fry");

// assertFalse(rec1.isComplete());
// }
@Test
public void testRecipeTestE2E() {
testRecipeInitialization();
testRecipeCompletion();
}
}
6 changes: 6 additions & 0 deletions src/test/java/ShareURLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ public void testHandleGet() throws Exception {
assertEquals(expectedHtml, capturedOutput);
}

@Test
public void testShareURLE2E() throws Exception {
testbuildRecipeUrl();
testfetchRecipeDetails();
testHandleGet();
}
}
5 changes: 5 additions & 0 deletions src/test/java/WhisperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public void testGenerate() {
assertNotNull(generatedText);
assertEquals(location, generatedText);
}

@Test
public void testWhisperE2E() {
testGenerate();
}
}

0 comments on commit 4168263

Please sign in to comment.