Skip to content

feat: Inject individual objects and validate the constructors#866

Merged
lionel-nj merged 1 commit intoMobilityData:masterfrom
aababilov:inject-date
Apr 26, 2021
Merged

feat: Inject individual objects and validate the constructors#866
lionel-nj merged 1 commit intoMobilityData:masterfrom
aababilov:inject-date

Conversation

@aababilov
Copy link
Copy Markdown
Collaborator

@aababilov aababilov commented Apr 22, 2021

  1. Inject individual objects like CurrentDateTime instead
    of the whole ValidationContext. This makes dependencies
    more explicit since a validator requires just a
    certain part of the potentially large ValidationContext.
  2. Validate that all validator constructors accept parameters
    of supported types and throw an exception for any invalid
    validator. This prevents hidden bugs when a validator cannot
    be instantiated but nobody notices that because a file for
    the corresponding validator is not present.

@aababilov aababilov requested a review from lionel-nj April 22, 2021 23:20
@aababilov aababilov mentioned this pull request Apr 22, 2021
4 tasks
@aababilov aababilov force-pushed the inject-date branch 2 times, most recently from aac032d to bcaf1f5 Compare April 23, 2021 05:31
@aababilov aababilov changed the title feat: Inject individual objects instead of the whole ValidationContext feat: Inject individual objects and validate the constructors Apr 23, 2021
Copy link
Copy Markdown
Contributor

@lionel-nj lionel-nj left a comment

Choose a reason for hiding this comment

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

Thanks @aababilov ! If I understand correctly the logic between tables and constructor parameters has been "inverted", .get method allows passing the correct parameter (CurrentDateTime or CountryCode. And there is an additional check to verify constructors are corretly defined?

public static <T> T createValidatorWithContext(
Class<T> clazz, ValidationContext validationContext) throws ReflectiveOperationException {
return createValidator(clazz, parameter -> validationContext);
return createValidator(clazz, parameter -> validationContext.get(parameter));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ooh okay! I see it now!

@@ -0,0 +1,12 @@
package org.mobilitydata.gtfsvalidator.validator;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose you might want to add a copyright header here :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @aababilov ! If I understand correctly the logic between tables and constructor parameters has been "inverted", .get method allows passing the correct parameter (CurrentDateTime or CountryCode. And there is an additional check to verify constructors are corretly defined?

Yes, that's right!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added the copyright :)

I work on a laptop and a desktop, so the laptop inserts copyrights automatically but the desktop does not yet :)

parameterClass.isAssignableFrom(ValidationContext.class) ? validationContext : table);
parameterClass.isAssignableFrom(table.getClass())
? table
: validationContext.get(parameterClass));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👀📝

1. Inject individual objects like CurrentDateTime instead
   of the whole ValidationContext. This makes dependencies
   more explicit since a validator requires just a
   certain part of the potentially large ValidationContext.
2. Validate that all validator constructors accept parameters
   of supported types and throw an exception for any invalid
   validator. This prevents hidden bugs when a validator cannot
   be instantiated but nobody notices that because a file for
   the corresponding validator is not present.
@aababilov
Copy link
Copy Markdown
Collaborator Author

Thanks for review! I addressed your comment and resolved merge conflicts.

Can we merge that now?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants