Datasets:
Download raw/java/cwe_104_1_funct_test.java from amazon/AutoSUIT: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/java/cwe_104_1_funct_test.java
- Command line
-
hf download hf://datasets/amazon/AutoSUIT/raw/java/cwe_104_1_funct_test.java
-
curl -L -o cwe_104_1_funct_test.java https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/java/cwe_104_1_funct_test.java
2.74 kB
| import org.junit.jupiter.api.*; | |
| import static org.junit.jupiter.api.Assertions.*; | |
| import static org.mockito.Mockito.*; | |
| import javax.servlet.http.HttpServletRequest; | |
| import org.apache.struts.action.ActionErrors; | |
| import org.apache.struts.action.ActionMapping; | |
| class RegistrationFormFunctionsTest { | |
| private RegistrationFormFunctions functions; | |
| private ActionMapping mockMapping; | |
| private HttpServletRequest mockRequest; | |
| void setUp() { | |
| functions = new RegistrationFormFunctions(); | |
| mockMapping = mock(ActionMapping.class); | |
| mockRequest = mock(HttpServletRequest.class); | |
| } | |
| void testValidateInformation_withValidData_shouldReturnEmptyErrors() { | |
| // Arrange | |
| String name = "John Doe"; | |
| String email = "john.doe@example.com"; | |
| // Act | |
| ActionErrors errors = functions.validateInformation(name, email, mockMapping, mockRequest); | |
| // Assert | |
| assertNotNull(errors); | |
| assertTrue(errors.isEmpty()); | |
| } | |
| void testValidateInformation_withInvalidEmail_shouldReturnErrors() { | |
| // Arrange | |
| String name = "John Doe"; | |
| String email = "invalid-email"; | |
| // Act | |
| ActionErrors errors = functions.validateInformation(name, email, mockMapping, mockRequest); | |
| // Assert | |
| assertNotNull(errors); | |
| assertFalse(errors.isEmpty()); | |
| } | |
| void testValidateInformation_withEmptyName_shouldReturnErrors() { | |
| // Arrange | |
| String name = ""; | |
| String email = "john.doe@example.com"; | |
| // Act | |
| ActionErrors errors = functions.validateInformation(name, email, mockMapping, mockRequest); | |
| // Assert | |
| assertNotNull(errors); | |
| assertFalse(errors.isEmpty()); | |
| } | |
| } | |
| class RegistrationFormTest { | |
| private RegistrationForm form; | |
| private ActionMapping mockMapping; | |
| private HttpServletRequest mockRequest; | |
| private RegistrationFormFunctions mockFunctions; | |
| void setUp() { | |
| form = new RegistrationForm(); | |
| mockMapping = mock(ActionMapping.class); | |
| mockRequest = mock(HttpServletRequest.class); | |
| mockFunctions = mock(RegistrationFormFunctions.class); | |
| form.setRegistrationFormFunctions(mockFunctions); | |
| } | |
| void testValidate_callsValidateInformation() { | |
| // Arrange | |
| form.setName("John Doe"); | |
| form.setEmail("john.doe@example.com"); | |
| // Act | |
| form.validate(mockMapping, mockRequest); | |
| // Assert | |
| verify(mockFunctions).validateInformation(eq("John Doe"), eq("john.doe@example.com"), eq(mockMapping), eq(mockRequest)); | |
| } | |
| } | |