Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is ArgumentCaptor changing the value of a generated field?

I have an object with a field id, that is a generated UUID:

id = UUID.randomUUID().toString()

I use this in a method where I save the object:

saveObject(SomeObject someObject) {
    someRepository.saveObject(someTestObject.id, //other fields)
}

But when I use ArgumentCaptor in my test:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

verify(someRepository, times(1)).save(ntCaptor.capture());
aasertThat(ntCaptor.getValue(),
    allOf(
        hasProperty("id", is(someObject.getId),
        // other fields
    )

I get a different id that I save. Is this a bug or is there a different approach to capture generated values?

>Solution :

In this:

saveObject(SomeObject someObject) {
    someRepository.saveObject(someTestObject.id, //other fields)
}

maybe because you are not using the someObject, you are using someTestObject.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading