package com.getbeamapp.transit;

import junit.framework.TestCase;

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

@UsesMocks(value = { TransitJSObject.class, TransitAdapter.class })
public class MockTest extends TestCase {

    public void testMockLibrary() {
        TransitJSObject proxy = AndroidMock.createMock(TransitJSObject.class);
        AndroidMock.expect(proxy.get("answer")).andReturn("42");
        AndroidMock.expect(proxy.get("answer")).andReturn("42");
        AndroidMock.replay(proxy);
        assertEquals("42", proxy.get("answer"));

        try {
            AndroidMock.verify(proxy);
            fail();
        } catch (AssertionError e) {
            // WORKAROUND: EasyMock creates oddly formatted messages with
            // newlines and tabs - let's get rid of multiple whitespace chars.
            String msg = TestHelpers.reduceWhitespace(e.getMessage());
            assertEquals("Expectation failure on verify: get(\"answer\"): expected: 2, actual: 1", msg);
        }
    }

    public void testProxyRelase() throws InterruptedException {
        TransitAdapter adapter = AndroidMock.createNiceMock(TransitAdapter.class);
        adapter.releaseProxy("1");
        AndroidMock.replay(adapter);

        AndroidTransitContext ctx = new AndroidTransitContext(adapter);

        ctx.proxify("__TRANSIT_JS_FUNCTION_1");
        System.gc();
        AndroidMock.verify(adapter);
    }

}

@@ -1471,10 +1471,655 @@
 %0A    %7D%0A%0A
+    public void testTransitObject() %7B%0A        TransitAdapter adapter = AndroidMock.createMock(TransitAdapter.class);%0A        AndroidMock.expect(adapter.evaluate(%22window%5B%5C%22title%5C%22%5D%22)).andReturn(%22Untitled%22);%0A        AndroidMock.expect(adapter.evaluate(%22window%5B%5C%22alert%5C%22%5D.apply(window, %5B42%5D)%22)).andReturn(true);%0A        AndroidMock.replay(adapter);%0A%0A        AndroidTransitContext ctx = new AndroidTransitContext(adapter);%0A        Object title = ctx.get(%22title%22);%0A        Object alertResult = ctx.callMember(%22alert%22, 42);%0A%0A        AndroidMock.verify(adapter);%0A        assertEquals(%22Untitled%22, title);%0A        assertEquals(true, alertResult);%0A    %7D%0A%0A
 %7D%0A

Test for TransitObject functions