jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
465 stars 240 forks source link

Cascading issue? #98

Closed ihoro closed 10 years ago

ihoro commented 10 years ago

I cannot tell what exactly is a problem here, but in the following example a() and b() are passed but c() fails. If you remove "extends Serializable" then all of them will be passed. Windows7 x64, OracleJDK 1.8.0_25, TestNG 6.8.8, JMockit 1.13 Any idea what it can be?

package mockit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.Serializable;
import static org.testng.Assert.assertNull;

class Parent<T extends Serializable> {
  private T id;
  public T getId() { return id; }
}
class Foo extends Parent<Long> {}
class Bar extends Parent<Long> {}
interface FooService { Foo getFoo(); }
interface BarService { Bar getBar(); }

public class CascadingTest {
  @Mocked FooService fooService;
  @Mocked BarService barService;

  @BeforeMethod void beforeMethod() {
    new NonStrictExpectations() {{
      barService.getBar();
    }};
  }

  @Test public void a() {
    assertNull(new Foo().getId());
  }

  @Test public void b() {
    new NonStrictExpectations() {{
      fooService.getFoo();
    }};
    assertNull(new Foo().getId());
  }

  @Test public void c() {
    assertNull(new Foo().getId());
  }
}
java.lang.AssertionError: expected [null] but found [java.lang.Long@19b02dfd]
        at mockit.CascadingTest.c(CascadingTest.java:38)
ihoro commented 10 years ago

Tried different JMockit versions:

@Cascading was used for older versions.

rliesenfeld commented 10 years ago

Thanks for the report; it appears to be a bug.