Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verifications break default Expectations cascading #355

Closed
Milbor-zz opened this issue Oct 12, 2016 · 1 comment
Closed

Verifications break default Expectations cascading #355

Milbor-zz opened this issue Oct 12, 2016 · 1 comment
Assignees
Labels

Comments

@Milbor-zz
Copy link

@Milbor-zz Milbor-zz commented Oct 12, 2016

I tried to use Verifications instead of Expectations for invocations with redundant recording warning as discussed in #352 and found this strange behavior. Following test nondeterministicaly fails in 1.28.
Try to run it couple of times, sometimes it passes, sometimes fails with
java.lang.ClassCastException: SpikeTest$User cannot be cast to SpikeTest$Bank
using testng 6.9.10

public class SpikeTest {
    @Injectable
    private Manager manager;
    @Injectable
    private User user;
    @Injectable
    private Bank bank;

    public interface Entity {
        String getCode();
    }

    static class User implements Entity {
        @Override
        public String getCode() {
            return null;
        }
    }

    static class Bank implements Entity {
        @Override
        public String getCode() {
            return null;
        }
    }

    public interface Manager {
        <T extends Entity, V> T find(Class<T> clazz, V param);
    }

    @Test
    public void test() throws Exception {
        new Expectations() {{
            bank.getCode();
            result = "xxx";
        }};
        final Bank actual = manager.find(Bank.class, 17);
        assertEquals(actual.getCode(), "xxx");
        new Verifications() {{
            manager.find(Bank.class, 17);
        }};
    }
}
@Milbor-zz
Copy link
Author

@Milbor-zz Milbor-zz commented Oct 12, 2016

Also this redundant recording warning is shown non-deterministically if expectation is moved from Verifications to Expectations:

new Expectations() {{
            manager.find(Bank.class, 17);
            result = bank;
            bank.getCode();
            result = "xxx";
        }};
        final Bank actual = manager.find(Bank.class, 17);
        assertEquals(actual.getCode(), "xxx");

Perhaps IllegalStateException as you proposed in #352 is desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants