29
29
public class Example <T > {
30
30
31
31
private final T probe ;
32
- private final ExampleSpec <? extends T > exampleSpec ;
32
+ private final ExampleSpec exampleSpec ;
33
33
34
34
/**
35
35
* Create a new {@link Example} including all non-null properties by default.
36
36
*
37
37
* @param probe The probe to use. Must not be {@literal null}.
38
38
*/
39
39
@ SuppressWarnings ("unchecked" )
40
- public Example (T probe ) {
40
+ private Example (T probe ) {
41
41
42
42
Assert .notNull (probe , "Probe must not be null!" );
43
43
44
44
this .probe = probe ;
45
- this .exampleSpec = ExampleSpec .of (( Class < T >) probe . getClass () );
45
+ this .exampleSpec = ExampleSpec .untyped ( );
46
46
}
47
47
48
48
/**
@@ -51,14 +51,46 @@ public Example(T probe) {
51
51
* @param probe The probe to use. Must not be {@literal null}.
52
52
* @param exampleSpec The example specification to use. Must not be {@literal null}.
53
53
*/
54
- public Example (T probe , ExampleSpec <? extends T > exampleSpec ) {
54
+ private Example (T probe , ExampleSpec exampleSpec ) {
55
55
56
56
Assert .notNull (probe , "Probe must not be null!" );
57
57
58
58
this .probe = probe ;
59
59
this .exampleSpec = exampleSpec ;
60
60
}
61
61
62
+ /**
63
+ * Create a new {@link Example} including all non-null properties by default.
64
+ *
65
+ * @param probe must not be {@literal null}.
66
+ * @return
67
+ */
68
+ public static <T > Example <T > of (T probe ) {
69
+ return new Example <T >(probe );
70
+ }
71
+
72
+ /**
73
+ * Create a new {@link Example} with a configured {@link ExampleSpec}.
74
+ *
75
+ * @param probe must not be {@literal null}.
76
+ * @param exampleSpec must not be {@literal null}.
77
+ * @return
78
+ */
79
+ public static <T > Example <T > of (T probe , ExampleSpec exampleSpec ) {
80
+ return new Example <T >(probe , exampleSpec );
81
+ }
82
+
83
+ /**
84
+ * Create a new {@link Example} with a configured {@link TypedExampleSpec}.
85
+ *
86
+ * @param probe must not be {@literal null}.
87
+ * @param exampleSpec must not be {@literal null}.
88
+ * @return
89
+ */
90
+ public static <T , S extends T > Example <S > of (S probe , TypedExampleSpec <T > exampleSpec ) {
91
+ return new Example <S >(probe , exampleSpec );
92
+ }
93
+
62
94
/**
63
95
* Get the example used.
64
96
*
@@ -73,7 +105,7 @@ public T getProbe() {
73
105
*
74
106
* @return never {@literal null}.
75
107
*/
76
- public ExampleSpec <? extends T > getExampleSpec () {
108
+ public ExampleSpec getExampleSpec () {
77
109
return exampleSpec ;
78
110
}
79
111
@@ -90,24 +122,15 @@ public Class<T> getProbeType() {
90
122
}
91
123
92
124
/**
93
- * Create a new {@link Example} including all non-null properties by default.
94
- *
95
- * @param probe must not be {@literal null}.
96
- * @return
97
- */
98
- public static <T > Example <T > of (T probe ) {
99
- return new Example <T >(probe );
100
- }
101
-
102
- /**
103
- * Create a new {@link Example} with a configured {@link ExampleSpec}.
125
+ * Get the actual result type for the query. The result type can be different when using {@link TypedExampleSpec}.
104
126
*
105
- * @param probe must not be {@literal null}.
106
- * @param exampleSpec must not be {@literal null}.
107
127
* @return
128
+ * @see ClassUtils#getUserClass(Class)
108
129
*/
109
- public static <T > Example <T > of (T probe , ExampleSpec <? extends T > exampleSpec ) {
110
- return new Example <T >(probe , exampleSpec );
130
+ @ SuppressWarnings ("unchecked" )
131
+ public <S extends T > Class <S > getResultType () {
132
+ return (Class <S >) (exampleSpec instanceof TypedExampleSpec <?> ? ((TypedExampleSpec <T >) exampleSpec ).getType ()
133
+ : getProbeType ());
111
134
}
112
135
113
136
}
0 commit comments