aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPausedMessage.java
blob: a23cae497f68529f55699ed5bb7d23d788e10638 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static org.robolectric.util.reflector.Reflector.reflector;

import android.os.Handler;
import android.os.Message;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.LooperMode;
import org.robolectric.annotation.RealObject;

/**
 * The shadow {@link Message} for {@link LooperMode.Mode.PAUSED}.
 *
 * <p>This class should not be referenced directly. Use {@link ShadowMessage} instead.
 */
@Implements(value = Message.class, isInAndroidSdk = false)
public class ShadowPausedMessage extends ShadowMessage {

  @RealObject private Message realMessage;

  @Implementation
  protected long getWhen() {
    return reflector(MessageReflector.class, realMessage).getWhen();
  }

  Message internalGetNext() {
    return reflector(MessageReflector.class, realMessage).getNext();
  }

  // TODO: Reconsider this being exposed as a public method
  @Override
  @Implementation
  public void recycleUnchecked() {
    if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) {
      reflector(MessageReflector.class, realMessage).recycleUnchecked();
    } else {
      reflector(MessageReflector.class, realMessage).recycle();
    }
  }

  @Override
  public void setScheduledRunnable(Runnable r) {
    throw new UnsupportedOperationException("Not supported in PAUSED LooperMode");
  }

  // We could support these methods, but intentionally do not for now as its unclear what the
  // use case is.

  @Override
  public Message getNext() {
    throw new UnsupportedOperationException("Not supported in PAUSED LooperMode");
  }

  @Override
  public void setNext(Message next) {
    throw new UnsupportedOperationException("Not supported in PAUSED LooperMode");
  }

  @Implementation
  protected Handler getTarget() {
    return reflector(MessageReflector.class, realMessage).getTarget();
  }
}