Skip to content

Instantly share code, notes, and snippets.

@1UC1F3R616
Last active July 26, 2024 11:55
Show Gist options
  • Save 1UC1F3R616/232f0298c80f04102c93f7cf3afa7172 to your computer and use it in GitHub Desktop.
Save 1UC1F3R616/232f0298c80f04102c93f7cf3afa7172 to your computer and use it in GitHub Desktop.
scrape-book

Must be one of the following:

feat: A new feature. fix: A bug fix. docs: Documentation only changes. style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc). refactor: A code change that neither fixes a bug nor adds a feature. perf: A code change that improves performance. test: Adding missing tests. chore: Changes to the build process or auxiliary tools and libraries such as documentation generation.

Initial commit πŸŽ‰ πŸŽ‰

New feature ✨ ✨

Bugfix πŸ› πŸ›

Documentation πŸ“š πŸ“š

Performance 🐎 🐎

Tests 🚨 🚨

Refactor code πŸ”¨ πŸ”¨

Removing code/files πŸ”₯ πŸ”₯

Adding CI build system πŸ‘· πŸ‘·

Security πŸ”’ πŸ”’

Upgrading dependencies ⬆️ ⬆️

Downgrading dependencies ⬇️ ⬇️

Critical hotfix πŸš‘ πŸš‘

Work in progress 🚧 🚧

Lint πŸ‘• πŸ‘•

Configuration files πŸ”§ πŸ”§

@1UC1F3R616
Copy link
Author

FROM tomcat:8
WORKDIR /usr/local/tomcat/webapps/
ADD https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war ./sample.war
EXPOSE 8080
CMD ["catalina.sh", "run"]

@1UC1F3R616
Copy link
Author

docker run -itd -p 8080:8080 tomcat:1
curl localhost:8080

@1UC1F3R616
Copy link
Author

@ExtendWith(MockitoExtension.class)
public class NotAllNullParametersValidatorTest {

    @Mock
    private NotAllNullParameters constraintAnnotation;

    @Mock
    private ConstraintValidatorContext context;

    @Mock
    private ConstraintValidatorContext.ConstraintViolationBuilder constraintViolationBuilder;

    private NotAllNullParametersValidator validator;

    @BeforeEach
    public void setup() throws NoSuchFieldException, IllegalAccessException {
        validator = new NotAllNullParametersValidator();
        when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(constraintViolationBuilder);
        when(constraintViolationBuilder.addConstraintViolation()).thenReturn(context); // Return the context for chaining
        
        // Inject the mocked paramNames to avoid NullPointerException
        String[] paramNames = {"param1", "param2"};
        Field paramNamesField = NotAllNullParametersValidator.class.getDeclaredField("paramNames");
        paramNamesField.setAccessible(true);
        paramNamesField.set(validator, paramNames);

        validator.initialize(constraintAnnotation);
    }

    @Test
    public void testAllNullValues() {
        Object[] values = {null, null};
        assertFalse(validator.isValid(values, context));
    }

    @Test
    public void testNullValuesArray() {
        assertThrows(IllegalArgumentException.class, () -> validator.isValid(null, context));
    }

    @Test
    public void testInvalidValuesLength() {
        Object[] values = {"value1"}; // Less than the number of parameters
        assertThrows(IllegalArgumentException.class, () -> validator.isValid(values, context));
    }

    @Test
    public void testBooleanFalseValue() {
        Object[] values = {false, null};
        assertFalse(validator.isValid(values, context));
    }
    
    @Test
    public void testOneValueNonNull() {
        Object[] values = {"value1", null};
        assertTrue(validator.isValid(values, context));
    }

    @Test
    public void testBooleanTrueValue() {
        Object[] values = {true, null};
        assertTrue(validator.isValid(values, context));
    }

    @Test
    public void testAllNonNullValues() {
        Object[] values = {"value1", 2};
        assertTrue(validator.isValid(values, context));
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment