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

UniAsserter - make it easier to share data between assertions #29584

Closed
mkouba opened this issue Nov 30, 2022 · 6 comments · Fixed by #29613
Closed

UniAsserter - make it easier to share data between assertions #29584

mkouba opened this issue Nov 30, 2022 · 6 comments · Fixed by #29613

Comments

@mkouba
Copy link
Contributor

mkouba commented Nov 30, 2022

Description

Currently, if you want to share some data the only way is to use some "external" holder, e.g.

@RunOnVertxContext
public void testSomething(UniAsserter asserter) {
   AtomicReference<Foo> holder = new AtomicReference<>();
   asserter.execute(() -> {
      Foo f = new Foo();
      // do something with Foo
      holder.set(f);
   }
   asserter.assertThat(() -> findAnotherFoo(), f -> assertEquals(f.getName(), holder.get().getName()));
}

Implementation ideas

We could add some method directly to the UniAsserter or even consider Mutiny context passing API.

@mkouba
Copy link
Contributor Author

mkouba commented Nov 30, 2022

CC @geoand

@geoand
Copy link
Contributor

geoand commented Nov 30, 2022

Do you have examples of how you want to use this?

@mkouba
Copy link
Contributor Author

mkouba commented Dec 1, 2022

Do you have examples of how you want to use this?

The simplest possible example could be:

@RunOnVertxContext
public void testSomething(UniAsserter asserter) {
   asserter.execute(() -> {
      Foo f = new Foo();
      asserter.putData(f);
   }
   asserter.assertThat(() -> findAnotherFoo(), f -> assertEquals(f.getName(), asserter.getData().getName()));
}

The asserted data can be stored in a concurrent Map<String,Object> in UniAsserter; asserter.getData() could delegate to asserter.getData("defaultKey") and asserter.putData(value) could delegate to asserter.putData("defaultKey", value). This way you would not need any external holder.

@geoand
Copy link
Contributor

geoand commented Dec 1, 2022

Sounds good to me. Do you have something already?

@mkouba
Copy link
Contributor Author

mkouba commented Dec 1, 2022

Not yet but I can send a pull request later today ;-).

@geoand
Copy link
Contributor

geoand commented Dec 1, 2022

Cool, thanks!

mkouba added a commit to mkouba/quarkus that referenced this issue Dec 1, 2022
mkouba added a commit to mkouba/quarkus that referenced this issue Dec 1, 2022
@quarkus-bot quarkus-bot bot added this to the 2.16 - main milestone Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants