1111
1212import static java .util .Objects .requireNonNull ;
1313
14+ /**
15+ * DtoTester is an interface for testing Data Transfer Objects (DTOs).
16+ * It provides various methods to set up and execute tests that include
17+ * accessor checks, validation, mutation, and resetting.
18+ */
1419public interface DtoTester {
1520
21+ /**
22+ * Executes all the configured tests on the DTO.
23+ */
1624 void test ();
1725
26+ /**
27+ * Builds a new DtoTester with the given type and constructor.
28+ *
29+ * @param type The class of the DTO.
30+ * @param constructor A supplier that constructs instances of the DTO.
31+ * @return A builder instance to configure the tester.
32+ */
1833 @ NotNull
1934 static <T > Builder <T > builder (@ NotNull final Class <T > type ,
2035 @ NotNull final Supplier <? extends T > constructor ) {
2136 requireNonNull (type );
22-
2337 return new DtoTesterBuilder <>(type , constructor );
2438 }
2539
40+ /**
41+ * Builder interface for configuring and building a DtoTester instance.
42+ *
43+ * @param <T> The type of the DTO.
44+ */
2645 interface Builder <T > {
2746
47+ /**
48+ * Adds accessors to the builder for testing.
49+ *
50+ * @param getter The getter function.
51+ * @param setter The setter function.
52+ * @return This builder, for chaining.
53+ */
2854 @ NotNull <R > Builder <T > withAccessors (@ NotNull Function <? super T , ? extends R > getter ,
2955 @ NotNull BiConsumer <? super T , ? super R > setter );
3056
57+ /**
58+ * Adds a resetter function to the builder.
59+ *
60+ * @param resetter The reset function.
61+ * @return This builder, for chaining.
62+ */
3163 @ NotNull Builder <T > withResetter (@ NotNull Consumer <? super T > resetter );
3264
65+ /**
66+ * Adds a validation function to the builder.
67+ *
68+ * @param validator The validation function.
69+ * @return This builder, for chaining.
70+ */
3371 @ NotNull Builder <T > withValidator (@ NotNull Consumer <? super T > validator );
3472
73+ /**
74+ * Adds a mutator to the builder for testing.
75+ *
76+ * @param type The type of the mutator (MANDATORY/OPTIONAL).
77+ * @param mutatorName The name of the mutator.
78+ * @param mutator The mutation function.
79+ * @return This builder, for chaining.
80+ */
3581 @ NotNull <R > Builder <T > addMutator (@ NotNull MutatorType type ,
3682 @ NotNull String mutatorName ,
3783 @ NotNull Consumer <? super T > mutator );
3884
85+ /**
86+ * Adds a mutator to the builder for testing, with a specified value.
87+ *
88+ * @param mutatorType The type of the mutator (MANDATORY/OPTIONAL).
89+ * @param mutatorName The name of the mutator.
90+ * @param setter The setter function.
91+ * @param value The value to set.
92+ * @return This builder, for chaining.
93+ */
3994 default @ NotNull <R > Builder <T > addMutator (@ NotNull final MutatorType mutatorType ,
4095 @ NotNull final String mutatorName ,
4196 @ NotNull final BiConsumer <? super T , ? super R > setter ,
@@ -46,26 +101,18 @@ interface Builder<T> {
46101 return addMutator (mutatorType , mutatorName , t -> setter .accept (t , value ));
47102 }
48103
49-
50- /*
51- @NotNull Builder<T> addValidationRule(@NotNull String ruleName,
52- @NotNull Predicate<? super T> validator);
53-
54- default @NotNull <R> Builder<T> addValidationRule(@NotNull final String ruleName,
55- @NotNull final Function<? super T, ? extends R> getter,
56- @Nullable final R unexpected) {
57- requireNonNull(ruleName);
58- requireNonNull(getter);
59- return addValidationRule(ruleName, t -> !getter.apply(t).equals(unexpected));
60- }
104+ /**
105+ * Builds the DtoTester instance.
106+ *
107+ * @return The built DtoTester.
61108 */
62-
63109 DtoTester build ();
64-
65110 }
66111
112+ /**
113+ * Enum for defining mutator types.
114+ */
67115 enum MutatorType {
68116 MANDATORY , OPTIONAL ;
69117 }
70-
71118}
0 commit comments