Skip to content

Don't mock interface default methods #729

@chrylis

Description

@chrylis

I have an interface that has a default method overload that can transform an instance of any sort of bar (in this case, message format) into a canonical format for processing.

interface Foo {
  void doThing(SpecificType bar);

  default void doThing(SuperType bar) {
    doThing(new SpecificType(bar));
  }
}

I want to test that when I call Foo#doThing with a SomeOtherBar, the message gets correctly transformed and sent out the SpecificType overload. However, Spock's Mock() intercepts all methods, including default methods.

Since one main purpose of default methods is to support adaptation onto legacy APIs, this behavior will prevent backwards-compatibility bridges from working if a provider API is upgraded. Instead, it should be possible to either by default (my preference) or explicitly exclude default interface methods from being implemented by the mock proxy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions