Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HibernateFormDAOTest extends BaseContextSensitiveTest {

Expand All @@ -49,19 +50,81 @@ public void shouldFilterAgainstFormFields() {
.getForms(null, false, Collections.emptyList(), null, formFields, formFields, Arrays.asList(new Field(3)))
.size());


}

@Test
public void shouldGetFormFieldsByForm() {
Form form = new Form(2);
List<FormField> formFields = dao.getFormFields(form);

assertNotNull(formFields);

}

@Test
@@ -64,4 +66,43 @@
assertEquals(form.getFormId(), formField.getForm().getFormId());
}
}

@Test
public void getForms_shouldReturnFormsContainingAnyFormField() {
// Test 1 - Basic: should return forms containing any form field
List<FormField> anyFormFields = Arrays.asList(new FormField(2));
List<Form> forms = dao.getForms(null, false,
Collections.emptyList(), null,
anyFormFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(forms);
assertTrue(forms.size() > 0);

// Test 2 - Empty list: should return all forms
List<Form> formsWithEmpty = dao.getForms(null, false,
Collections.emptyList(), null,
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsWithEmpty);

// Test 3 - Multiple fields: should return forms with any field
List<FormField> multipleFields = Arrays.asList(
new FormField(2), new FormField(3));
List<Form> formsMultiple = dao.getForms(null, false,
Collections.emptyList(), null,
multipleFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsMultiple);
assertTrue(formsMultiple.size() > 0);

final int EXPECTED_SIZE = 2;
assertEquals(EXPECTED_SIZE, formFields.size());
for (FormField formField : formFields) {
assertEquals(form.getFormId(), formField.getForm().getFormId());
}
// Test 4 - Non existent field: should return empty list
List<FormField> invalidFields = Arrays.asList(new FormField(999));
List<Form> formsInvalid = dao.getForms(null, false,
Collections.emptyList(), null,
invalidFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsInvalid);
assertTrue(formsInvalid.isEmpty());

// Edge case: multiple non-existent fields
List<FormField> multipleInvalidFields = Arrays.asList(
new FormField(997),
new FormField(998),
new FormField(999));
List<Form> formsMultipleInvalid = dao.getForms(null, false,
Collections.emptyList(), null,
multipleInvalidFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsMultipleInvalid);
assertTrue(formsMultipleInvalid.isEmpty());
}

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any edge cases where multiple form fields exist but none match? It might be useful to include such scenarios in the tests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. You're right—we should cover the scenario with multiple
non-existent fields

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion! I have committed it directly.

Copy link
Copy Markdown

@EDSONZ-WASSWA EDSONZ-WASSWA Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! @ShrutiSocrates .. I see there is thorough test coverage for the containingAnyFormField functionality as the ticket required....Looks good
Just one thing the comment "//A would-be fix for that" should be removed before merge

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the approval and feedback! The "//A would-be fix for that" comment
has been removed.

//A would-be fix for that
List<FormField> multipleInvalidFields = Arrays.asList(
new FormField(998),
new FormField(999));
List<Form> formsMultipleInvalid = dao.getForms(null, false,
Collections.emptyList(), null,
multipleInvalidFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsMultipleInvalid);
assertTrue(formsMultipleInvalid.isEmpty());