GithubHelp home page GithubHelp logo

Comments (11)

lukas-krecan avatar lukas-krecan commented on July 17, 2024

Hi, thanks for feedback. To be honest, capturing values does not seem to fit to the library. There are several possible solutions.

  1. Use json-path to access the values
  2. Use Hamcrest matchers. You can already use Hamcrest matchers with JsonUnit like this assertThatJson("{\"test\":\"one\"}").node("test").matches(equalTo("one")); You can use custom capturing matcher (similar to Mockito ArgumentCaptor)

from jsonunit.

k1w1m8 avatar k1w1m8 commented on July 17, 2024

from jsonunit.

lukas-krecan-lt avatar lukas-krecan-lt commented on July 17, 2024

Sure, PRs are always nice.

It reminds me this feature recently added to JsonUnit a2c26ab#diff-6c9cdaf0685d47feb195c5cd7da1eb5aR1021 isn't it what you need?

from jsonunit.

k1w1m8 avatar k1w1m8 commented on July 17, 2024

from jsonunit.

lukas-krecan-lt avatar lukas-krecan-lt commented on July 17, 2024

OK, I see what you mean. You need additional param. Something like

assertJsonEquals("{\"test\": \"${json-unit.matches:mymagic}[param]\"}", "{\"test\":1}", JsonAssert.withMatcher("mymagic", myMagicInstance)); That can be done.

from jsonunit.

lukas-krecan-lt avatar lukas-krecan-lt commented on July 17, 2024

No need for PR, I think I know what to do. If you do not mind, I will base it on matchers, will just add a parameter.

from jsonunit.

lukas-krecan avatar lukas-krecan commented on July 17, 2024

What about this? c85a70f#diff-6c9cdaf0685d47feb195c5cd7da1eb5aR1030

from jsonunit.

k1w1m8 avatar k1w1m8 commented on July 17, 2024

from jsonunit.

lukas-krecan avatar lukas-krecan commented on July 17, 2024

Released as 1.24.0

from jsonunit.

k1w1m8 avatar k1w1m8 commented on July 17, 2024

from jsonunit.

k1w1m8 avatar k1w1m8 commented on July 17, 2024

Finally got around to actually using this for real, worked perfectly. I can now compare both XML documents using XML unit, and JSON documents using JsonUnit and, as a side effect of the comparison, capture values into user defined variables using a similar ${} extension mechanism. Brilliant.

from jsonunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.