-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method to Arguments for getting payloads #4144
Comments
This is what we currently do to unwrap Lines 121 to 130 in 12bccfd
I think we could expose that as a @onacit Would that be sufficient for you? |
@marcphilipp That's great! Thank you.
If I may, let me share what I've done. // _Named_TestUtils.java
public static <T> T payload(final Object argument) {
Objects.requireNonNull(argument, "argument is null");
if (argument instanceof Named<?>) {
return payload( // <<<<<<<<<<< peel it off until it's not a `Named<?>` anymore
((Named<?>) argument).getPayload()
);
}
@SuppressWarnings({"unchecked"})
final var cast = (T) argument;
return cast;
} // _Arguments_TestUtils.java
public static Arguments ofPayloadsMapped(final Arguments arguments,
final IntFunction<? extends Function<Object, Object>> mapper) {
Objects.requireNonNull(arguments, "arguments is null");
final var got = arguments.get();
return Arguments.of(
IntStream.range(0, got.length)
.mapToObj(i -> mapper.apply(i).apply(_Named_TestUtils.payload(got[i])))
.toArray()
);
}
public static Arguments ofPayloads(final Arguments arguments) {
return ofPayloadsMapped(arguments, i -> Function.identity());
} // may gone to far, but worth it!
static Stream<Arguments> getCipherAndParamsArgumentsStream() {
return Stream.concat(
JinahyaBlockCipherUtils_AES_Test.getCipherAndParamsArgumentsStream(),
JinahyaBlockCipherUtils_ARIA_Test.getCipherAndParamsArgumentsStream()
).map(a -> _Arguments_TestUtils.ofPayloadsMapped( // peel off while remapping into, say, another `Named<?>`
a,
i -> p -> switch (i) {
case 0 -> _BufferedBlockCipher_TestUtils.named(new CTSBlockCipher((BlockCipher) p));
case 1 -> _KeyParameters_TestUtils.named((KeyParameter) p);
default -> p;
}
));
} |
When would |
You're right. Thanks. |
Why did you close the issue? Don't you want the method I suggested in #4144 (comment) to be added? |
Say, I have the following methods.
Now I want to use those two methods in other class.
I had to use a method looks like this.
Deliverables
Arguments
, say,getPayloads()[Ljava.lang.Object
The text was updated successfully, but these errors were encountered: