<commit_before>package de.bitdroid.flooding.ods.data;


import android.content.Context;

import java.lang.reflect.Constructor;

import de.bitdroid.flooding.testUtils.BaseAndroidTestCase;
import de.bitdroid.flooding.testUtils.PrefsRenamingDelegatingContext;
import de.bitdroid.flooding.testUtils.SharedPreferencesHelper;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class OdsSourceManagerTest extends BaseAndroidTestCase {

	private static final String PREFIX =  OdsSourceManagerTest.class.getSimpleName();


	private OdsSourceManager sourceManager;
	private GcmManager gcmManager;
	private SyncUtils syncUtils;
	private SyncStatusListener syncListener;

	@Override
	public void beforeClass() {
		setContext(new PrefsRenamingDelegatingContext(getContext(), PREFIX));
		// some love potion for our two friends: dexmaker and mockito
		System.setProperty("dexmaker.dexcache", getContext().getCacheDir().getPath());
	}


	@Override
	public void beforeTest() throws Exception {
		SharedPreferencesHelper.clearAll((PrefsRenamingDelegatingContext) getContext());

		Constructor<OdsSourceManager> constructor = OdsSourceManager.class.getDeclaredConstructor(
				Context.class,
				GcmManager.class,
				SyncUtils.class,
				SyncStatusListener.class);
		constructor.setAccessible(true);

		gcmManager = mock(GcmManager.class);
		syncUtils = mock(SyncUtils.class);
		syncListener = mock(SyncStatusListener.class);
		sourceManager = constructor.newInstance(getContext(), gcmManager, syncUtils, syncListener);
	}


	public void testServerName() {
		String serverName = "http://someServerName.com";

		// simple check
		sourceManager.setOdsServerName(serverName);
		assertEquals(serverName, sourceManager.getOdsServerName());

		// other methods access prefs as well
		when(syncUtils.isPeriodicSyncScheduled()).thenReturn(false).thenReturn(true);
		OdsSource source1 = mock(OdsSource.class);
		OdsSource source2 = mock(OdsSource.class);

		sourceManager.startPolling(100,  source1, source2);
		sourceManager.stopPolling();

		assertEquals(serverName, sourceManager.getOdsServerName());
	}

}<commit_msg>test: added polling test in OdsSourceManagerTest<commit_after>package de.bitdroid.flooding.ods.data;


import android.content.ContentValues;
import android.content.Context;

import org.json.JSONObject;

import java.lang.reflect.Constructor;
import java.util.Map;

import de.bitdroid.flooding.testUtils.BaseAndroidTestCase;
import de.bitdroid.flooding.testUtils.PrefsRenamingDelegatingContext;
import de.bitdroid.flooding.testUtils.SharedPreferencesHelper;
import de.bitdroid.flooding.utils.SQLiteType;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class OdsSourceManagerTest extends BaseAndroidTestCase {

	private static final String PREFIX =  OdsSourceManagerTest.class.getSimpleName();


	private OdsSourceManager sourceManager;
	private GcmManager gcmManager;
	private SyncUtils syncUtils;
	private SyncStatusListener syncListener;

	@Override
	public void beforeClass() {
		setContext(new PrefsRenamingDelegatingContext(getContext(), PREFIX));
		// some love potion for our two friends: dexmaker and mockito
		System.setProperty("dexmaker.dexcache", getContext().getCacheDir().getPath());
	}


	@Override
	public void beforeTest() throws Exception {
		SharedPreferencesHelper.clearAll((PrefsRenamingDelegatingContext) getContext());

		Constructor<OdsSourceManager> constructor = OdsSourceManager.class.getDeclaredConstructor(
				Context.class,
				GcmManager.class,
				SyncUtils.class,
				SyncStatusListener.class);
		constructor.setAccessible(true);

		gcmManager = mock(GcmManager.class);
		syncUtils = mock(SyncUtils.class);
		syncListener = mock(SyncStatusListener.class);
		sourceManager = constructor.newInstance(getContext(), gcmManager, syncUtils, syncListener);
	}


	public void testServerName() {
		String serverName = "http://someServerName.com";

		// simple check
		sourceManager.setOdsServerName(serverName);
		assertEquals(serverName, sourceManager.getOdsServerName());

		// other methods access prefs as well
		when(syncUtils.isPeriodicSyncScheduled()).thenReturn(false).thenReturn(true);
		OdsSource source1 = mock(OdsSource.class);
		OdsSource source2 = mock(OdsSource.class);

		sourceManager.startPolling(100,  source1, source2);
		sourceManager.stopPolling();

		assertEquals(serverName, sourceManager.getOdsServerName());
	}


	public  void testPolling() {
		OdsSource source1 = new MockSource1();
		OdsSource source2 = new MockSource2();
		long pollFrequency = 100;
		when(syncUtils.isPeriodicSyncScheduled())
				.thenReturn(false)
				.thenReturn(false)
				.thenReturn(true)
				.thenReturn(true)
				.thenReturn(false)
				.thenReturn(false);

		assertFalse(sourceManager.isPollingActive());
		assertEquals(0, sourceManager.getPollingSources().size());

		sourceManager.startPolling(pollFrequency, source1, source2);

		assertTrue(sourceManager.isPollingActive());
		assertEquals(2, sourceManager.getPollingSources().size());
		verify(syncUtils).startPeriodicSync(pollFrequency);

		sourceManager.stopPolling();

		assertFalse(sourceManager.isPollingActive());
		assertEquals(0, sourceManager.getPollingSources().size());
		verify(syncUtils).stopPeriodicSync();
	}


	public void testPush() {
	}


	public static abstract class MockSource extends OdsSource {

		private final String id;

		public MockSource(String id) {
			this.id = id;
		}

		@Override
		public String getSourceId() {
			return id;
		}

		@Override
		public String getSourceUrlPath() {
			return "mockSourcePath";
		}

		@Override
		public void getSchema(Map<String, SQLiteType> schema) { }

		@Override
		protected void saveData(JSONObject json, ContentValues values) { }

	}


	public static final class MockSource1 extends MockSource {
		public MockSource1() {
			super("mockId1");
		}
	}


	public static final class MockSource2 extends MockSource {
		public MockSource2() {
			super("mockId2");
		}
	}

}
{'fraction_non_alphanumeric': 0.09960225389459729, 'fraction_numerical': 0.005303281405369572, 'mean_word_length': 5.6906873614190685, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047997', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1772, 'n_words': 350}