jeudi 31 mars 2016

how to unit test a code which uses Java UUID

I have a piece of code which is expected to populated one attribute of response object with java UUID (UUID.randomUUID())

How can I unit test this code from outside to check this behaviour as I don't know the UUID that would be generated inside it?

Any suggestions please?

Sample code which needs to be tested

//To test whether x attribute was set using an UUID
// instead of hardcode value in the response
    class A {
    String x;
    String y;
    }
    public a doSomething() {
    //Does something
    A a = new A();
    a.setX( UUID.randomUUID());
    return a;
    }

Thanks, Harish

Aucun commentaire:

Enregistrer un commentaire