react-native-navigation的迁移库

MockPromise.java 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.reactnativenavigation.mocks;
  2. import com.facebook.react.bridge.*;
  3. import javax.annotation.*;
  4. public class MockPromise implements Promise {
  5. private boolean invoked;
  6. @Override
  7. public void resolve(@Nullable Object value) {
  8. throwIfInvoked();
  9. invoked = true;
  10. }
  11. @Override
  12. public void reject(String code, String message) {
  13. throwIfInvoked();
  14. invoked = true;
  15. }
  16. @Override
  17. public void reject(String code, Throwable e) {
  18. throwIfInvoked();
  19. invoked = true;
  20. }
  21. @Override
  22. public void reject(String code, String message, Throwable e) {
  23. throwIfInvoked();
  24. invoked = true;
  25. }
  26. @Override
  27. public void reject(String message) {
  28. throwIfInvoked();
  29. invoked = true;
  30. }
  31. @Override
  32. public void reject(Throwable reason) {
  33. throwIfInvoked();
  34. invoked = true;
  35. }
  36. private void throwIfInvoked() {
  37. if (invoked) throw new RuntimeException("Promise can be resolved or rejected only once");
  38. }
  39. }