spat1978 / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

verify with timeout: VerificationWithTimeoutImpl doesn't catches MockitoAssertionError wrapped for junit #436

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
=What steps will reproduce the problem?
1. Use Mockito with junit
2. Observe with Mockito.spy a class with overloaded methods and nested calls
3. verify with timeout may exit with 
org.mockito.exceptions.verification.junit.ArgumentsAreDifferent
Example code is below.

=What is the expected output?
Expected that test will pass. 
Problem extracted from https://code.google.com/p/mockito/issues/detail?id=266, 
which has different summary. 
"The code in VerificationWithTimeoutImpl catches MockitoAssertionError, sleeps 
and then attempts to verify once more (until the timeout is reached).  
Unfortunateky, if you have JUnit, an AssertionError is thrown instead, so the 
catch/sleep does not function."

=What version of the product are you using? On what operating system?
1.9.5

=Code sample:

class Calc {
    public int minus(int param1) {
        try {
            Thread.sleep(150);
        } catch (InterruptedException supressed) {
        }
        return minus(0, param1);
    }

    public int minus(int param1, int param2) {
        try {
            Thread.sleep(150);
        } catch (InterruptedException supressed) {
        }
        return param1 - param2;
    }
}

public class CalcTest {
    private final Calc calc = spy(new Calc());

    @Test
    public void pollsPeriodically() throws Exception {
        ExecutorService service = Executors.newCachedThreadPool();
        service.submit(new Runnable() {
            @Override
            public void run() {
                calc.minus(-1);
            }
        });

        verify(calc, timeout(1000).times(1)).minus(0, 1);
    }
}

Original issue reported on code.google.com by cee...@gmail.com on 5 Jun 2013 at 3:54

GoogleCodeExporter commented 8 years ago
Fixed in master.

Original comment by szcze...@gmail.com on 12 Apr 2014 at 3:21

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 16 Aug 2014 at 2:43

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 24 Aug 2014 at 3:14

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 24 Aug 2014 at 3:50