Skip to content
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

Open
1 task
onacit opened this issue Nov 21, 2024 · 0 comments
Open
1 task

Add method to Arguments for getting payloads #4144

onacit opened this issue Nov 21, 2024 · 0 comments

Comments

@onacit
Copy link

onacit commented Nov 21, 2024

Say, I have the following methods.

    class Some {

        static Stream<Arguments> getNameAndAgeArgumentsStream() {
            return Stream.of(
                    Arguments.of(
                            Named.of("Whatever", "John"), // <<<<<<<<<<<<<<<<<
                            1
                    );
        }
    }

    class Other {

        static Stream<Arguments> getNameAndAgeArgumentsStream() {
            return Stream.of(
                    Arguments.of(
                            "Jane",  // <<<<<<<<<<<<<<<<<<<<<<<
                            1
                    );
        }
    }

Now I want to use those two methods in other class.

    class Another {

        static Stream<Arguments> getPrefixedNameAndAgeArguemntsStream() {
            return Stream.concat(
                            Some.getNameAndAgeArgumentsStream(),
                            Other.getNameAndAgeArgumentsStream()
                    )
                    .map(a -> {
                        var arguments = a.get();
                        var name = arguments[0] instanceof Named ? ((Named<String>) arguments[0]).getPayload() : arguments[0];
                        return Arguments.of(
                                "prefix" + name,
                                arguments[1]
                        );
                    });
        }
    }

I had to use a method looks like this.

    public static <T> T payload(final Object argument) {
        Objects.requireNonNull(argument, "argument is null");
        if (argument instanceof Named<?>) {
            return payload(((Named<?>) argument).getPayload());
        }
        return (T) argument;
    }

Deliverables

  • Add a method returns ultimate payload values from an Arguments, say, getPayloads()[Ljava.lang.Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant