mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
@ -0,0 +1,106 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MainActivityUnitTest {
|
||||
|
||||
@Test
|
||||
public void TestSubdomainUrl() {
|
||||
|
||||
|
||||
Instrumentation mInstrumentation = getInstrumentation();
|
||||
// We register our interest in the activity
|
||||
Instrumentation.ActivityMonitor monitor = mInstrumentation.addMonitor(MainActivity.class.getName(), null, false);
|
||||
// We launch it
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setClassName(mInstrumentation.getTargetContext(), MainActivity.class.getName());
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
MainActivity mainActivity = (MainActivity) getInstrumentation().waitForMonitor(monitor);
|
||||
|
||||
// We register our interest in the next activity from the sequence in this use case
|
||||
mInstrumentation.removeMonitor(monitor);
|
||||
|
||||
|
||||
final String exp = "https://m.facebook.com/events/261145401687844";
|
||||
|
||||
String url = "https://www.facebook.com/events/261145401687844";
|
||||
String act = mainActivity.checkURI(url);
|
||||
assertEquals(exp, act);
|
||||
|
||||
url = "https://de-de.facebook.com/events/261145401687844";
|
||||
act = mainActivity.checkURI(url);
|
||||
assertEquals(exp, act);
|
||||
|
||||
url = "https://m.facebook.com/events/261145401687844";
|
||||
act = mainActivity.checkURI(url);
|
||||
assertEquals(exp, act);
|
||||
|
||||
url = "https://www.facebook.com/events/261145401687844/?active_tab=discussion";
|
||||
act = mainActivity.checkURI(url);
|
||||
assertEquals(exp, act);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTimeToEpoch() {
|
||||
|
||||
|
||||
Instrumentation mInstrumentation = getInstrumentation();
|
||||
// We register our interest in the activity
|
||||
Instrumentation.ActivityMonitor monitor = mInstrumentation.addMonitor(MainActivity.class.getName(), null, false);
|
||||
// We launch it
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setClassName(mInstrumentation.getTargetContext(), MainActivity.class.getName());
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
MainActivity mainActivity = (MainActivity) getInstrumentation().waitForMonitor(monitor);
|
||||
|
||||
// We register our interest in the next activity from the sequence in this use case
|
||||
mInstrumentation.removeMonitor(monitor);
|
||||
|
||||
|
||||
String in = "2020-07-29T12:00:00+00:00";
|
||||
|
||||
Long exp = new Long(1596024000);
|
||||
exp = exp* 1000;
|
||||
Long act = mainActivity.convertTimeToEpoch(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
|
||||
in = "2020-07-29T12:00:00+02:00";
|
||||
exp = new Long(1596016800);
|
||||
exp = exp* 1000;
|
||||
act = mainActivity.convertTimeToEpoch(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
|
||||
in = "1970-01-01T00:00:00+00:00";
|
||||
exp = new Long(0);
|
||||
exp = exp* 1000;
|
||||
act = mainActivity.convertTimeToEpoch(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
in = "1970-01-01T02:00:00+02:00";
|
||||
exp = new Long(0);
|
||||
exp = exp* 1000;
|
||||
act = mainActivity.convertTimeToEpoch(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ScraperUnitTest {
|
||||
|
||||
@Test
|
||||
public void TestLocation() {
|
||||
|
||||
FbScraper scraper = new FbScraper(null, "");
|
||||
|
||||
String exp = "Deutschland";
|
||||
String json = "{'@type': 'Place', 'name': 'Deutschland'}";
|
||||
String act = scraper.fixLocation(json);
|
||||
assertEquals(exp, act);
|
||||
|
||||
exp = "Example name, Example Street 1, 12345 Example city";
|
||||
json = "{'@type': 'Place', 'name': 'Example name', 'address': {'@type': 'PostalAddress', 'addressCountry': 'DE', 'addressLocality': 'Example city', 'postalCode': '12345', 'streetAddress': 'Example Street 1'}}";
|
||||
act = scraper.fixLocation(json);
|
||||
assertEquals(exp, act);
|
||||
|
||||
exp = "";
|
||||
json = "";
|
||||
act = scraper.fixLocation(json);
|
||||
assertEquals(exp, act);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTimezone() {
|
||||
|
||||
FbScraper scraper = new FbScraper(null, "");
|
||||
|
||||
String exp = "2020-10-23T05:00:00+02:00";
|
||||
String in = "2020-10-23T05:00:00+0200";
|
||||
String act = scraper.fixTimezone(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
|
||||
exp = "";
|
||||
in = "";
|
||||
act = scraper.fixTimezone(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestLinks() {
|
||||
|
||||
FbScraper scraper = new FbScraper(null, "");
|
||||
|
||||
String in = "foo @[152580919265:274:MagentaMusik 360] bar";
|
||||
String exp = "foo m.facebook.com/152580919265 (MagentaMusik 360) bar";
|
||||
String act = scraper.fixLinks(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
in = "foo @[152580919265:274:MagentaMusik 360] bar @[666666666666:274:NoOfTheBeast]";
|
||||
exp = "foo m.facebook.com/152580919265 (MagentaMusik 360) bar m.facebook.com/666666666666 (NoOfTheBeast)";
|
||||
act = scraper.fixLinks(in);
|
||||
assertEquals(exp, act);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user