Skip to content

avoid casts on calls to mock methods #27027

Closed
@jmesserly

Description

@jmesserly

For example:

  class Monster {
    // Returns current health after applying [hp] damage to this monster.
    int damage(int hp);

    // Returns current health after applying [f()] damage to this monster.
    int damageFromClosure(int f());
  }
  class MockMonster extends Mock implements Monster {}

  var mock = new MockMonster();
  when(mock.damage(argThat(isPositive))).thenReturn(100);
  when(mock.damageFromClosure(argThat(isFunction))).thenReturn(200);

We'll want to allow mock.damage to avoid the cast to int. This is safe because when using nSM to implement abstract methods, the method is conceptually implemented by a method that forwards to nSM, and that method can widen the argument types to Object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onclosed-obsoleteClosed as the reported issue is no longer relevantlegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions