package com.getbeamapp.transit;

import junit.framework.TestCase;

import com.google.android.testing.mocking.AndroidMock;
import com.google.android.testing.mocking.UsesMocks;

@UsesMocks(value = TransitProxy.class)
public class MockTest extends TestCase {

    private final TransitCallable noop;
    private final TransitAdapter noopAdapter;

    public MockTest() {
        this.noop = new TransitCallable() {
            @Override
            public Object evaluate(TransitProxy thisArg, TransitProxy... arguments) {
                return null;
            }
        };

        this.noopAdapter = new TransitAdapter() {

            @Override
            public void initialize() {
                return;
            }

            @Override
            public TransitProxy evaluate(String stringToEvaluate, JavaScriptRepresentable thisArg, JavaScriptRepresentable... arguments) {
                return null;
            }
        };
    }

    public void testMockLibrary() {
        AbstractTransitContext ctx = new TransitContext(noopAdapter);
        TransitProxy proxy = AndroidMock.createMock(TransitProxy.class, ctx);
        AndroidMock.expect(proxy.get()).andReturn(42);
        AndroidMock.replay(proxy);
        assertEquals(42, proxy.get());
        AndroidMock.verify(proxy);
    }
}

@@ -1180,16 +1180,71 @@
 rn(42);%0A
+        AndroidMock.expect(proxy.get()).andReturn(42);%0A
         
@@ -1309,16 +1309,35 @@
 get());%0A
+%0A        try %7B%0A    
         
@@ -1359,20 +1359,419 @@
 ify(proxy);%0A
+            fail();%0A        %7D catch (AssertionError e) %7B%0A            // WORKAROUND: EasyMock creates oddly formatted messages with%0A            // newlines and tabs - let's get rid of multiple whitespace chars.%0A            String msg = e.getMessage().trim().replaceAll(%22%5B%5C%5Cr%5C%5Cn%5C%5Cs%5C%5Ct%5D+%22, %22 %22);%0A            assertEquals(%22Expectation failure on verify: get(): expected: 2, actual: 1%22, msg);%0A        %7D%0A%0A
     %7D%0A%7D%0A

test AndroidMock.verify