Article:
  Don't Let Hibernate Steal Your Identity
Subject:   What about unit testing?
Date:   2006-11-21 08:03:04
From:   dhicks
I love the ideas and have implemented them. They're working great, except for one problem.


I use RMock for a lot of unit testing, and it likes to verify that the object sent to a method is the same one it expected. Assuming we use equals() to determine object equality, then it blows up because I can't produce two objects and control their id's from the test fixture.


Has anyone else encountered this and come up with a reasonable solution?


Thanks,
Dave

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • What about unit testing?
    2006-12-04 01:54:22  MartinPallmann [View]

    No Problem,

    simply don't instanciate the IdGenerator in the class but reach it in as parameter of the constructor of your class.

    So you can implement a Mock-Id-Generator and have control over the ids.

    like this:

    public AbstractPersistentObject(final IIdGenerator idGenerator) {
    super();
    this.id = idGenerator.generateId(this.getClass());
    }