@Test public void testEventLog() throws IOException {
		readNewEvents(CondomCore.CondomEvent.CONCERN);

		condom.getBaseContext();
		Object[] data = readLastEvent(CondomCore.CondomEvent.CONCERN);
		assertEquals(condom.getPackageName(), data[0]);
		assertEquals(condom.TAG, data[1]);
		assertEquals("getBaseContext", data[2]);
		assertCallerMatch(data);

		((Application) condom.getApplicationContext()).getBaseContext();
		data = readLastEvent(CondomCore.CondomEvent.CONCERN);
		assertEquals("Application.getBaseContext", data[2]);
		assertCallerMatch(data);

		condom.getPackageManager().getInstalledApplications(0);
		data = readLastEvent(CondomCore.CondomEvent.CONCERN);
		assertEquals("PackageManager.getInstalledApplications", data[2]);
		assertCallerMatch(data);

		condom.getPackageManager().getInstalledPackages(0);
		data = readLastEvent(CondomCore.CondomEvent.CONCERN);
		assertEquals("PackageManager.getInstalledPackages", data[2]);
		assertCallerMatch(data);

		final Intent intent = new Intent().setPackage("a.b.c");
		condom.bindService(intent, SERVICE_CONNECTION, 0);
		data = readLastEvent(CondomCore.CondomEvent.BIND_PASS);
		assertEquals(condom.getPackageName(), data[0]);
		assertEquals("Condom." + TAG, data[1]);
		assertEquals(intent.getPackage(), data[2]);
		assertEquals(intent.toString(), data[3]);

		condom.startService(intent);
		data = readLastEvent(CondomCore.CondomEvent.START_PASS);
		assertEquals(condom.getPackageName(), data[0]);
		assertEquals("Condom." + TAG, data[1]);
		assertEquals(intent.getPackage(), data[2]);
		assertEquals(intent.toString(), data[3]);

		if (SDK_INT < O) {
			final List<ResolveInfo> result = condom.getPackageManager().queryIntentServices(intent.setPackage(null).setComponent(null), 0);
			assertEquals(1, result.size());		// 1 left: non.bg.service
			final List<EventLog.Event> events = readNewEvents(CondomCore.CondomEvent.FILTER_BG_SERVICE);
			assertEquals(2, events.size());		// 2 filtered: bg.service.*
			data = (Object[]) events.get(0).getData();
			assertEquals(condom.getPackageName(), data[0]);
			assertEquals("Condom." + TAG, data[1]);
			assertEquals("bg.service.1", data[2]);
			final String expected_intent = new Intent(intent).toString();	// Flags altered
			assertEquals(expected_intent, data[3]);
			data = (Object[]) events.get(1).getData();
			assertEquals(condom.getPackageName(), data[0]);
			assertEquals("Condom." + TAG, data[1]);
			assertEquals("bg.service.2", data[2]);
			assertEquals(expected_intent, data[3]);

			final ResolveInfo resolve = condom.getPackageManager().resolveService(intent, 0);
            assertEquals("non.bg.service", requireNonNull(resolve).serviceInfo.applicationInfo.packageName);
			data = readLastEvent(CondomCore.CondomEvent.FILTER_BG_SERVICE);
			assertEquals(condom.getPackageName(), data[0]);
			assertEquals("Condom." + TAG, data[1]);
			assertEquals("bg.service.1", data[2]);
			assertEquals(expected_intent, data[3]);
		}

		final CondomContext condom_wo_tag = CondomContext.wrap(new ContextWrapper(ApplicationProvider.getApplicationContext()) {
			@Override public boolean bindService(final Intent service, final ServiceConnection conn, final int flags) { return true; }
			@Override public ComponentName startService(final Intent service) {
				return service.getComponent() != null ? service.getComponent()
                        : new ComponentName(requireNonNull(service.getPackage()), "A");
			}
		}, null);

		final ComponentName component = new ComponentName("x.y.z", "O");
		intent.setPackage(null).setComponent(component);
		condom_wo_tag.bindService(intent, SERVICE_CONNECTION, 0);
		data = readLastEvent(CondomCore.CondomEvent.BIND_PASS);
		assertEquals(condom_wo_tag.getPackageName(), data[0]);
		assertEquals("Condom", data[1]);
		assertEquals(requireNonNull(intent.getComponent()).getPackageName(), data[2]);
		assertEquals(intent.toString(), data[3]);

		condom_wo_tag.startService(intent);
		data = readLastEvent(CondomCore.CondomEvent.START_PASS);
		assertEquals(condom_wo_tag.getPackageName(), data[0]);
		assertEquals("Condom", data[1]);
		assertEquals(intent.getComponent().getPackageName(), data[2]);
		assertEquals(intent.toString(), data[3]);
	}
Miscellaneous test cases

Created by Oasis on 2017/4/10.
library/src/androidTest/java/com/oasisfeng/condom/CondomMiscTest.java