Search in sources :

Example 1 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowBackgroundThread method reset.

@Resetter
public static void reset() {
    _BackgroundThread_ _backgroundThreadStatic_ = reflector(_BackgroundThread_.class);
    BackgroundThread instance = _backgroundThreadStatic_.getInstance();
    if (instance != null) {
        instance.quit();
        _backgroundThreadStatic_.setInstance(null);
        _backgroundThreadStatic_.setHandler(null);
    }
}
Also used : BackgroundThread(com.android.internal.os.BackgroundThread) Resetter(org.robolectric.annotation.Resetter)

Example 2 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowDeviceConfig method reset.

@Resetter
public static void reset() {
    Object lock = ReflectionHelpers.getStaticField(DeviceConfig.class, "sLock");
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (lock) {
        if (RuntimeEnvironment.getApiLevel() == Build.VERSION_CODES.Q) {
            Map singleListeners = ReflectionHelpers.getStaticField(DeviceConfig.class, "sSingleListeners");
            singleListeners.clear();
        }
        Map listeners = ReflectionHelpers.getStaticField(DeviceConfig.class, "sListeners");
        listeners.clear();
        Map namespaces = ReflectionHelpers.getStaticField(DeviceConfig.class, "sNamespaces");
        namespaces.clear();
    }
}
Also used : Map(java.util.Map) Resetter(org.robolectric.annotation.Resetter)

Example 3 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowFontBuilder method reset.

@Resetter
public static void reset() {
    for (Map.Entry<Long, FontInternal> entry : resettableByteBuffers.entrySet()) {
        FontInternal fontInternal = entry.getValue();
        if (fontInternal == null || fontInternal.buffer == null) {
            continue;
        }
        ByteBuffer buffer = fontInternal.buffer;
        buffer.rewind();
        buffer.clear();
    }
    resettableByteBuffers.clear();
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer) Resetter(org.robolectric.annotation.Resetter)

Example 4 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowLegacyLooper method resetThreadLoopers.

@Resetter
public static synchronized void resetThreadLoopers() {
    // do not use looperMode() here, because its cached value might already have been reset
    if (ConfigurationRegistry.get(LooperMode.Mode.class) == LooperMode.Mode.PAUSED) {
        // ignore if realistic looper
        return;
    }
    // from being garbage collected.
    if (!isMainThread()) {
        throw new IllegalStateException("you should only be calling this from the main thread!");
    }
    synchronized (loopingLoopers) {
        for (Looper looper : loopingLoopers.values()) {
            synchronized (looper) {
                if (!shadowOf(looper).quit) {
                    looper.quit();
                } else {
                    // Reset the schedulers of all loopers. This prevents un-run tasks queued up in static
                    // background handlers from leaking to subsequent tests.
                    shadowOf(looper).getScheduler().reset();
                    shadowOf(looper.getQueue()).reset();
                }
            }
        }
    }
    // prepareMainLooper() is called, this might be null on that occasion.
    if (mainLooper != null) {
        shadowOf(mainLooper).reset();
    }
}
Also used : Looper(android.os.Looper) LooperMode(org.robolectric.annotation.LooperMode) Resetter(org.robolectric.annotation.Resetter)

Example 5 with Resetter

use of org.robolectric.annotation.Resetter in project robolectric by robolectric.

the class ShadowPausedLooper method resetLoopers.

@Resetter
public static synchronized void resetLoopers() {
    // do not use looperMode() here, because its cached value might already have been reset
    if (ConfigurationRegistry.get(LooperMode.Mode.class) != LooperMode.Mode.PAUSED) {
        // ignore if not realistic looper
        return;
    }
    Collection<Looper> loopersCopy = new ArrayList(loopingLoopers);
    for (Looper looper : loopersCopy) {
        ShadowPausedMessageQueue shadowQueue = Shadow.extract(looper.getQueue());
        shadowQueue.reset();
    }
}
Also used : Looper(android.os.Looper) LooperMode(org.robolectric.annotation.LooperMode) ArrayList(java.util.ArrayList) Resetter(org.robolectric.annotation.Resetter)

Aggregations

Resetter (org.robolectric.annotation.Resetter)7 Looper (android.os.Looper)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LooperMode (org.robolectric.annotation.LooperMode)2 WindowManagerImpl (android.view.WindowManagerImpl)1 BackgroundThread (com.android.internal.os.BackgroundThread)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 RealObject (org.robolectric.annotation.RealObject)1