package org.robolectric.shadows;

import android.app.QueuedWork;
import android.os.Build;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.util.ReflectionHelpers;

@Implements(value = QueuedWork.class, isInAndroidSdk = false)
public class ShadowQueuedWork {

  @Resetter
  public static void reset() {
    QueuedWork.waitToFinish();
    if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.O) {
      ReflectionHelpers.setStaticField(QueuedWork.class, "sHandler", null);
    } else {
      ReflectionHelpers.setStaticField(QueuedWork.class, "sSingleThreadExecutor", null);
    }
  }
}

@@ -83,16 +83,43 @@
 .Build;%0A
+import android.os.Handler;%0A
 import o
@@ -291,16 +291,40 @@
 lpers;%0A%0A
+import java.util.List;%0A%0A
 @Impleme
@@ -457,39 +457,8 @@
 ) %7B%0A
-    QueuedWork.waitToFinish();%0A
     
@@ -532,96 +532,246 @@
     
-ReflectionHelpers.setStaticField(QueuedWork.class, %22sHandler%22, null);%0A    %7D else %7B%0A     
+resetStateApi26();%0A    %7D else %7B%0A      QueuedWork.waitToFinish();%0A      ReflectionHelpers.setStaticField(QueuedWork.class, %22sSingleThreadExecutor%22, null);%0A    %7D%0A  %7D%0A%0A  private static void resetStateApi26() %7B%0A    Handler queuedWorkHandler =
  Ref
@@ -777,33 +777,33 @@
 flectionHelpers.
-s
+g
 etStaticField(Qu
@@ -824,43 +824,360 @@
 , %22s
-SingleThreadExecutor%22, null);%0A    %7D
+Handler%22);%0A    if (queuedWorkHandler != null) %7B%0A      queuedWorkHandler.removeCallbacksAndMessages(null);%0A    %7D%0A    ((List) ReflectionHelpers.getStaticField(QueuedWork.class, %22sFinishers%22)).clear();%0A    ((List) ReflectionHelpers.getStaticField(QueuedWork.class, %22sWork%22)).clear();%0A    ReflectionHelpers.setStaticField(QueuedWork.class, %22mNumWaits%22, 0);
 %0A  %7D

Update QueuedWork Resetter for API 26