Skip to content

Instantly share code, notes, and snippets.

@searchformyusername
Last active October 25, 2024 08:11
Show Gist options
  • Save searchformyusername/232f0298c80f04102c93f7cf3afa7172 to your computer and use it in GitHub Desktop.
Save searchformyusername/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 πŸ”§ πŸ”§

@searchformyusername
Copy link
Author

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import javax.validation.ConstraintValidatorContext;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

class NotAllNullParametersValidatorTest {

    private NotAllNullParametersValidator validator;
    private ConstraintValidatorContext context; // Mocked for simplicity

    @BeforeEach
    void setUp() {
        validator = new NotAllNullParametersValidator();
        context = mock(ConstraintValidatorContext.class);

        // Simulate initialization with parameter names
        NotAllNullParameters annotation = new NotAllNullParameters() {
            @Override
            public String[] paramNames() {
                return new String[]{"param1", "param2"};
            }

            // ... other annotation methods ...
        };
        validator.initialize(annotation);
    }

    @ParameterizedTest
    @MethodSource("validParametersProvider")
    void isValid_withValidParameters_returnsTrue(Object[] values) {
        assertTrue(validator.isValid(values, context));
    }

    static Stream<Arguments> validParametersProvider() {
        return Stream.of(
            Arguments.of(new Object[]{null, true}),
            Arguments.of(new Object[]{false, null}),
            Arguments.of(new Object[]{true, "not null"})
        );
    }

    @ParameterizedTest
    @MethodSource("invalidParametersProvider")
    void isValid_withInvalidParameters_returnsFalse(Object[] values) {
        assertFalse(validator.isValid(values, context));
    }

    static Stream<Arguments> invalidParametersProvider() {
        return Stream.of(
            Arguments.of(new Object[]{null, null}),
            Arguments.of(new Object[]{null}),
            Arguments.of(new Object[]{})
        );
    }

    @ParameterizedTest
    @MethodSource("mismatchedLengthParametersProvider")
    void isValid_withMismatchedLength_throwsException(Object[] values) {
        assertThrows(IllegalArgumentException.class, () -> validator.isValid(values, context));
    }

    static Stream<Arguments> mismatchedLengthParametersProvider() {
        return Stream.of(
            Arguments.of(new Object[]{null, null, null}),
            Arguments.of(new Object[]{null, null, null, null})
        );
    }
}

@searchformyusername
Copy link
Author

@searchformyusername
Copy link
Author

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