Unitils

auto unwrap mock

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0, 2.2
  • Fix Version/s: 2.3
  • Component/s: mock
  • Description:
    Hide
    it would be convenient, and potentially easier to read, if mock objects were automatically 'unwrapped'. This code:
      mockParent.returns(mockChild.getMock()).getChild();
    could instead be written as:
      mockParent.returns(mockChild).getChild();

    Since code-under-test would never expect an org.unitils.mock.Mock instance, it would be nice if returns() automatically called getMock() for us.

    One fast way to implement this: add overloads in MockObject and the Mock interface:

    public T returns(Mock<?> mock) {
        return returns(mock.getMock());
    }

    public T onceReturns(Mock<?> mock) {
        return onceReturns(mock.getMock());
    }
    Show
    it would be convenient, and potentially easier to read, if mock objects were automatically 'unwrapped'. This code:   mockParent.returns(mockChild.getMock()).getChild(); could instead be written as:   mockParent.returns(mockChild).getChild(); Since code-under-test would never expect an org.unitils.mock.Mock instance, it would be nice if returns() automatically called getMock() for us. One fast way to implement this: add overloads in MockObject and the Mock interface: public T returns(Mock<?> mock) {     return returns(mock.getMock()); } public T onceReturns(Mock<?> mock) {     return onceReturns(mock.getMock()); }

Activity

Hide
Filip Neven added a comment - 27/May/09 9:24 AM
This is a very good suggestion, we will certainly do this. Thanks for the feedback.
Show
Filip Neven added a comment - 27/May/09 9:24 AM This is a very good suggestion, we will certainly do this. Thanks for the feedback.
Hide
Brad Cupit added a comment - 27/May/09 1:08 PM
yay! I'm looking forward to it. Thanks for the work you do on this great library!
Show
Brad Cupit added a comment - 27/May/09 1:08 PM yay! I'm looking forward to it. Thanks for the work you do on this great library!
Hide
Brad Cupit added a comment - 04/Jun/09 9:56 PM
verify fixed in 2.3
thanks guys!
Show
Brad Cupit added a comment - 04/Jun/09 9:56 PM verify fixed in 2.3 thanks guys!

People

Dates

  • Created:
    26/May/09 9:32 PM
    Updated:
    04/Jun/09 9:56 PM
    Resolved:
    27/May/09 8:15 PM