Java Code Examples for com.twofortyfouram.spackle.ThreadUtil

The following are top voted examples for showing how to use com.twofortyfouram.spackle.ThreadUtil. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: android-plugin-client-sdk-for-locale   File: AbstractAsyncReceiver.java   Source Code and License 6 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB)
/* package */ final void goAsyncWithCallback(@NonNull final AsyncCallback callback,
        final boolean isOrdered) {
    assertNotNull(callback, "callback"); //$NON-NLS-1$

    final PendingResult pendingResult = goAsync();
    if (null == pendingResult) {
        throw new AssertionError(
                "PendingResult was null.  Was goAsync() called previously?"); //$NON-NLS-1$
    }

    final Handler.Callback handlerCallback = new AsyncHandlerCallback();
    final HandlerThread thread = ThreadUtil.newHandlerThread(getClass().getName(),
            ThreadPriority.BACKGROUND);
    final Handler handler = new Handler(thread.getLooper(), handlerCallback);

    final Object obj = new Pair<PendingResult, AsyncCallback>(pendingResult, callback);
    final int isOrderedInt = isOrdered ? 1 : 0;
    final Message msg = handler
            .obtainMessage(AsyncHandlerCallback.MESSAGE_HANDLE_CALLBACK, isOrderedInt, 0, obj);

    final boolean isMessageSent = handler.sendMessage(msg);
    if (!isMessageSent) {
        throw new AssertionError();
    }
}
 
Example 2
Project: android-plugin-client-sdk-for-locale   File: AbstractPluginConditionReceiverTest.java   Source Code and License 6 votes vote down vote up
/**
 * @param intent             Intent to send to the receiver implementation under test.
 * @param initialResultCode  Normally this should be
 *                           com.twofortyfouram.locale.api.Intent#RESULT_CONDITION_UNKNOWN, but
 *                           can be overridden to verify the receiver under test.
 * @param expectedResultCode Result code to assert comes back.
 */
private void assertOrderedBroadcastResultCode(final Intent intent,
        final int initialResultCode, final int expectedResultCode) {

    final HandlerThread handlerThread = ThreadUtil.newHandlerThread(getName(),
            ThreadPriority.DEFAULT);

    try {
        final QueryResultReceiver resultReceiver = new QueryResultReceiver();
        mContext.sendOrderedBroadcast(intent, null, resultReceiver,
                new Handler(handlerThread.getLooper()), initialResultCode, null, null);

        try {
            assertTrue(resultReceiver.mLatch.await(6 * DateUtils.SECOND_IN_MILLIS,
                    TimeUnit.MILLISECONDS));
        } catch (final InterruptedException e) {
            throw new AssertionError(e);
        }

        assertEquals(expectedResultCode + "!=" + resultReceiver.mQueryResult.get(), expectedResultCode, resultReceiver.mQueryResult.get());
    } finally {
        handlerThread.getLooper().quit();
    }

}
 
Example 3
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Initially loads the registry.
 *
 * @see #MESSAGE_INIT
 */
@Slow(Speed.SECONDS)
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
/* package */void handleInit() {
    mReceiverHandlerThread = ThreadUtil.newHandlerThread(
            RegistryReceiver.class.getName(),
            ThreadPriority.BACKGROUND);
    final Handler receiverHandler = new Handler(mReceiverHandlerThread.getLooper());
    {
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addDataScheme("package"); //$NON-NLS-1$

        mContext.registerReceiver(mReceiver, filter, null, receiverHandler);
    }

    {
        final IntentFilter externalStorageFilter = new IntentFilter();
        externalStorageFilter
                .addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
        externalStorageFilter
                .addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
        mContext.registerReceiver(mReceiver, externalStorageFilter, null,
                receiverHandler);
    }

    mMutableConditionMap = PluginPackageScanner.loadPluginMap(mContext,
            PluginType.CONDITION, null);
    mMutableSettingMap = PluginPackageScanner.loadPluginMap(mContext,
            PluginType.SETTING, null);

    setConditions();
    setSettings();

    sendBroadcast();
}
 
Example 4
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void loadCompleteNotification() {
    final String intentAction = getIntentAction();

    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            intentAction);

    final HandlerThread backgroundThread = ThreadUtil.newHandlerThread(intentAction,
            ThreadUtil.ThreadPriority.DEFAULT);
    try {
        final CountDownLatch latch = new CountDownLatch(1);

        final BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(final Context context, final Intent intent) {
                Lumberjack.v("Received %s", intent); //$NON-NLS-1$
                latch.countDown();
            }
        };

        InstrumentationRegistry.getContext()
                .registerReceiver(receiver, new IntentFilter(intentAction), null,
                        new Handler(backgroundThread.getLooper()));

        registry.init();

        try {
            assertThat(latch.await(REGISTRY_LOAD_WAIT_MILLIS, TimeUnit.MILLISECONDS), is(true));
        } catch (final InterruptedException e) {
            throw new RuntimeException(e);
        }

        InstrumentationRegistry.getContext().unregisterReceiver(receiver);
    } finally {
        registry.destroy();
        backgroundThread.quit();
    }
}
 
Example 5
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleInit() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        assertThat(registryHandler.mMutableConditionMap, nullValue());
        assertThat(registryHandler.mMutableSettingMap, nullValue());

        registryHandler.handleInit();

        assertThat(registryHandler.mMutableConditionMap, notNullValue());
        assertThat(registryHandler.mMutableSettingMap, notNullValue());

        assertThat(registryHandler.mMutableConditionMap.isEmpty(), is(false));
        assertThat(registryHandler.mMutableSettingMap.isEmpty(), is(false));

        /*
         * Verify the debug plug-in condition and debug plug-in setting were
         * detected.
         */
        assertThat(registryHandler.mMutableConditionMap, hasKey(Plugin
                .generateRegistryName(context.getPackageName(),
                        PluginConditionActivity.class.getName())));
        assertThat(registryHandler.mMutableSettingMap, hasKey(Plugin.generateRegistryName(
                context.getPackageName(), PluginSettingActivity.class.getName())));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 6
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleRemovePackage_no_plugin() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                        .handlePackageRemoved("com.twofortyfouram.locale.hack"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 7
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_package() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                        .handlePackageAdded("com.twofortyfouram.locale.hack"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 8
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_plugin() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler.handlePackageAdded("com.google.maps"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 9
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_condition() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final ComponentName disabledComponent = new ComponentName(context,
            PluginSettingActivity.class.getName());

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                .handlePackageAdded(
                        context.getPackageName()), is(PackageResult.CONDITIONS_CHANGED));

        final String conditionKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginConditionActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap, hasKey(conditionKey));
        assertThat(registryHandler.mMutableSettingMap.isEmpty(), is(true));
    } finally {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 10
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final ComponentName disabledComponent = new ComponentName(context,
            PluginConditionActivity.class.getName());

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                .handlePackageAdded(
                        context.getPackageName()), is(PackageResult.SETTINGS_CHANGED));

        final String settingKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginSettingActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap.isEmpty(), is(true));
        assertThat(registryHandler.mMutableSettingMap, hasKey(settingKey));
    } finally {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 11
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_condition_and_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                        .handlePackageAdded(
                                context.getPackageName()),
                is(PackageResult.CONDITIONS_AND_SETTINGS_CHANGED));

        final String conditionKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginConditionActivity.class.getName());
        final String settingKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginSettingActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap, hasKey(conditionKey));
        assertThat(registryHandler.mMutableSettingMap, hasKey(settingKey));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 12
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_change() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                .handlePackageChanged(
                        context.getPackageName()), is(PackageResult.NOTHING_CHANGED));

        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 13
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleChangePackage_no_change() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler.handlePackageChanged("com.google.maps"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
    }
}
 
Example 14
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleChangePackage_no_package() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                        .handlePackageChanged("com.twofortyfouram.locale.hack"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 15
Project: android-plugin-client-sdk-for-locale   File: AbstractPluginSettingReceiverTest.java   Source Code and License 5 votes vote down vote up
/**
 * @param intent             Intent to send to the receiver implementation under test.
 * @param initialResultCode  Normally this should be
 *                           com.twofortyfouram.locale.api.Intent#RESULT_CONDITION_UNKNOWN, but
 *                           can be overridden to verify the receiver under test.
 * @param expectedResultCode The expected result code.
 * @param isAsync            True if the plug-in receiver should handle its work in a
 *                           background thread.
 */
private void assertOrderedBroadcast(final Intent intent, final int initialResultCode,
        final int expectedResultCode, final boolean isAsync, final int expectedFireCount,
        final Bundle expectedBundle) {

    final HandlerThread handlerThread = ThreadUtil.newHandlerThread(getName(),
            ThreadPriority.DEFAULT);

    final PluginSettingReceiverImpl receiverImpl = new PluginSettingReceiverImpl(isAsync);

    final IntentFilter filter = new IntentFilter(
            com.twofortyfouram.locale.api.Intent.ACTION_FIRE_SETTING);
    filter.addAction(ALTERNATIVE_ACTION_FOR_TEST);

    mContext.registerReceiver(receiverImpl, filter);
    try {

        final QueryResultReceiver resultReceiver = new QueryResultReceiver();
        mContext.sendOrderedBroadcast(intent, null, resultReceiver,
                new Handler(handlerThread.getLooper()), initialResultCode, null, null);

        try {
            assertTrue(resultReceiver.mLatch.await(5 * DateUtils.SECOND_IN_MILLIS,
                    TimeUnit.MILLISECONDS));
        } catch (final InterruptedException e) {
            throw new AssertionError(e);
        }

        assertTrue(BundleComparer.areBundlesEqual(expectedBundle,
                receiverImpl.mFireBundle.get()));
        assertEquals(expectedFireCount, receiverImpl.mFireCount.get());
    } finally {
        handlerThread.getLooper().quit();
        mContext.unregisterReceiver(receiverImpl);
    }

}
 
Example 16
Project: android-display-condition-plugin-for-locale   File: QueryReceiverTest.java   Source Code and License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    final HandlerThread h = ThreadUtil
            .newHandlerThread(getName(), ThreadUtil.ThreadPriority.DEFAULT);
    mLooper = h.getLooper();
}
 
Example 17
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 4 votes vote down vote up
@MediumTest
@Test
public void handleRemovePackage_condition_and_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        /*
         * Insert a fake condition
         */
        final Plugin testPluginCondition = new Plugin(
                PluginType.CONDITION,
                "com.twofortyfouram.locale.condition.hack",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.EditActivity",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.QueryReceiver",//$NON-NLS
                1, PluginConfigurationFixture
                .newPluginConfiguration());
        registryHandler.mMutableConditionMap.put(testPluginCondition.getRegistryName(),
                testPluginCondition);

        /*
         * Insert a fake setting
         */
        final Plugin testPluginSetting = new Plugin(
                PluginType.CONDITION,
                "com.twofortyfouram.locale.condition.hack",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.EditActivity",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.FireReceiver",//$NON-NLS
                1, PluginConfigurationFixture
                .newPluginConfiguration());
        registryHandler.mMutableSettingMap.put(testPluginSetting.getRegistryName(),
                testPluginCondition);

        assertThat(registryHandler.handlePackageRemoved(
                "com.twofortyfouram.locale.condition.hack"),
                is(PackageResult.CONDITIONS_AND_SETTINGS_CHANGED)); //$NON-NLS-1$

        /*
         * Verify the maps are back to their original states
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 18
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 4 votes vote down vote up
@MediumTest
@Test
public void handleRemovePackage_condition() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        /*
         * Insert a fake condition
         */
        final Plugin testPlugin = new Plugin(
                PluginType.CONDITION,
                "com.twofortyfouram.locale.condition.hack",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.EditActivity",//$NON-NLS
                "com.twofortyfouram.locale.condition.hack.QueryReceiver",//$NON-NLS
                1, PluginConfigurationFixture
                .newPluginConfiguration());
        registryHandler.mMutableConditionMap.put(testPlugin.getRegistryName(), testPlugin);

        assertThat(registryHandler
                        .handlePackageRemoved(
                                "com.twofortyfouram.locale.condition.hack"), //$NON-NLS-1$
                is(PackageResult.CONDITIONS_CHANGED));

        /*
         * Verify the maps are back to their original states
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 19
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 4 votes vote down vote up
@MediumTest
@Test
public void handleRemovePackage_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        /*
         * Insert a fake setting
         */
        final Plugin testPlugin = new Plugin(
                PluginType.SETTING,
                "com.twofortyfouram.locale.setting.hack", //$NON-NLS
                "com.twofortyfouram.locale.setting.hack.EditActivity",//$NON-NLS
                "com.twofortyfouram.locale.setting.hack.FireReceiver",//$NON-NLS
                1, PluginConfigurationFixture
                .newPluginConfiguration());
        registryHandler.mMutableSettingMap.put(testPlugin.getRegistryName(), testPlugin);

        assertThat(registryHandler.handlePackageRemoved(
                "com.twofortyfouram.locale.setting.hack"), //$NON-NLS-1$
                is(PackageResult.SETTINGS_CHANGED));

        /*
         * Verify the maps are back to their original states
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }

}