@SuppressLint("InlinedApi") @Test public void testLowMemoryDispatch() { MatomoTestApplication app = (MatomoTestApplication) Robolectric.application; final PacketSender packetSender = mock(PacketSender.class); app.getMatomo().setDispatcherFactory(new DefaultDispatcherFactory() { @Override public Dispatcher build(Tracker tracker) { return new DefaultDispatcher( new EventCache(new EventDiskCache(tracker)), new Connectivity(tracker.getMatomo().getContext()), new PacketFactory(tracker.getAPIUrl()), packetSender ); } }); Tracker tracker = app.getTracker(); assertNotNull(tracker); tracker.setDispatchInterval(-1); tracker.track(TrackHelper.track().screen("test").build()); tracker.dispatch(); verify(packetSender, timeout(500).times(1)).send(any(Packet.class)); tracker.track(TrackHelper.track().screen("test").build()); verify(packetSender, timeout(500).times(1)).send(any(Packet.class)); app.onTrimMemory(Application.TRIM_MEMORY_UI_HIDDEN); verify(packetSender, timeout(500).atLeast(2)).send(any(Packet.class)); }
@SuppressLint("InlinedApi") @Test public void testLowMemoryDispatch() { MatomoTestApplication app = (MatomoTestApplication) Robolectric.application; final PacketSender packetSender = mock(PacketSender.class); app.getMatomo().setDispatcherFactory(new DefaultDispatcherFactory() { @Override public Dispatcher build(Tracker tracker) { return new DefaultDispatcher( new EventCache(new EventDiskCache(tracker)), new Connectivity(tracker.getMatomo().getContext()), new PacketFactory(tracker.getAPIUrl()), packetSender ); } }); Tracker tracker = app.getTracker(); assertNotNull(tracker); tracker.setDispatchInterval(-1); tracker.track(TrackHelper.track().screen("test").build()); tracker.dispatch(); verify(packetSender, timeout(500).times(1)).send(any(Packet.class)); tracker.track(TrackHelper.track().screen("test").build()); verify(packetSender, timeout(500).times(1)).send(any(Packet.class)); app.onTrimMemory(Application.TRIM_MEMORY_UI_HIDDEN); verify(packetSender, timeout(500).atLeast(2)).send(any(Packet.class)); }
@Test public void testVisitCustomVariables() throws Exception { CustomVariables visitVars = new CustomVariables(); visitVars.put(1, "visit", "valueX"); CustomVariables _screen = new CustomVariables(); _screen.put(1, "screen", "valueY"); final TrackMe trackMe = TrackHelper.track(visitVars.toVisitVariables()) .screen("/path") .variable(1, "screen", "valueY") .build(); assertEquals(visitVars.toString(), trackMe.get(QueryParams.VISIT_SCOPE_CUSTOM_VARIABLES)); assertEquals(_screen.toString(), trackMe.get(QueryParams.SCREEN_SCOPE_CUSTOM_VARIABLES)); assertEquals("/path", trackMe.get(QueryParams.URL_PATH)); }
@Test public void testVisitCustomVariables() throws Exception { CustomVariables visitVars = new CustomVariables(); visitVars.put(1, "visit", "valueX"); CustomVariables _screen = new CustomVariables(); _screen.put(1, "screen", "valueY"); final TrackMe trackMe = TrackHelper.track(visitVars.toVisitVariables()) .screen("/path") .variable(1, "screen", "valueY") .build(); assertEquals(visitVars.toString(), trackMe.get(QueryParams.VISIT_SCOPE_CUSTOM_VARIABLES)); assertEquals(_screen.toString(), trackMe.get(QueryParams.SCREEN_SCOPE_CUSTOM_VARIABLES)); assertEquals("/path", trackMe.get(QueryParams.URL_PATH)); }
@Test(expected = IllegalArgumentException.class) public void testSetScreem_empty_path() throws Exception { TrackHelper.track().screen((String) null).build(); }
@Test(expected = IllegalArgumentException.class) public void testSetScreem_empty_path() throws Exception { TrackHelper.track().screen((String) null).build(); }