java.lang.NullPointerException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(430)

本文整理了Java中java.lang.NullPointerException.getMessage()方法的一些代码示例,展示了NullPointerException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NullPointerException.getMessage()方法的具体详情如下:
包路径:java.lang.NullPointerException
类名称:NullPointerException
方法名:getMessage

NullPointerException.getMessage介绍

暂无

代码示例

代码示例来源:origin: ReactiveX/RxAndroid

@Test
public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() {
  try {
    RxAndroidPlugins.initMainThreadScheduler(null);
    fail();
  } catch (NullPointerException e) {
    assertEquals("scheduler == null", e.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void overrideInitSingleSchedulerCrashes() {
  // fail when Callable is null
  try {
    RxJavaPlugins.initSingleScheduler(null);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable can't be null", npe.getMessage());
  }
  // fail when Callable result is null
  try {
    RxJavaPlugins.initSingleScheduler(nullResultCallable);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable result can't be null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void overrideInitComputationSchedulerCrashes() {
  // fail when Callable is null
  try {
    RxJavaPlugins.initComputationScheduler(null);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable can't be null", npe.getMessage());
  }
  // fail when Callable result is null
  try {
    RxJavaPlugins.initComputationScheduler(nullResultCallable);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable result can't be null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void overrideInitIoSchedulerCrashes() {
  // fail when Callable is null
  try {
    RxJavaPlugins.initIoScheduler(null);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable can't be null", npe.getMessage());
  }
  // fail when Callable result is null
  try {
    RxJavaPlugins.initIoScheduler(nullResultCallable);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable result can't be null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void overrideInitNewThreadSchedulerCrashes() {
  // fail when Callable is null
  try {
    RxJavaPlugins.initNewThreadScheduler(null);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    // expected
    assertEquals("Scheduler Callable can't be null", npe.getMessage());
  }
  // fail when Callable result is null
  try {
    RxJavaPlugins.initNewThreadScheduler(nullResultCallable);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException npe) {
    assertEquals("Scheduler Callable result can't be null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void schedulePeriodicallyDirectNullRunnable() {
    try {
      getScheduler().schedulePeriodicallyDirect(null, 5, 10, TimeUnit.MILLISECONDS);
      fail();
    } catch (NullPointerException npe) {
      assertEquals("run is null", npe.getMessage());
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void scheduleDirectNullRunnable() {
  try {
    getScheduler().scheduleDirect(null);
    fail();
  } catch (NullPointerException npe) {
    assertEquals("run is null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void scheduleDirectWithDelayNullRunnable() {
  try {
    getScheduler().scheduleDirect(null, 10, TimeUnit.MILLISECONDS);
    fail();
  } catch (NullPointerException npe) {
    assertEquals("run is null", npe.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void nullActionShouldBeCheckedInConstructor() {
  try {
    Flowable.empty().doAfterTerminate(null);
    fail("Should have thrown NullPointerException");
  } catch (NullPointerException expected) {
    assertEquals("onAfterTerminate is null", expected.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void sourceThrowsNPE() {
  try {
    Maybe.unsafeCreate(new MaybeSource<Object>() {
      @Override
      public void subscribe(MaybeObserver<? super Object> observer) {
        throw new NullPointerException("Forced failure");
      }
    }).test();
    fail("Should have thrown!");
  } catch (NullPointerException ex) {
    assertEquals("Forced failure", ex.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxAndroid

@Test
public void fromNullThrowsTwoArg() {
  try {
    AndroidSchedulers.from(null, false);
    fail();
  } catch (NullPointerException e) {
    assertEquals("looper == null", e.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("rawtypes")
@Test
public void pluginNull() {
  RxJavaPlugins.setOnObservableSubscribe(new BiFunction<Observable, Observer, Observer>() {
    @Override
    public Observer apply(Observable a, Observer b) throws Exception {
      return null;
    }
  });
  try {
    try {
      Observable.just(1).test();
      fail("Should have thrown");
    } catch (NullPointerException ex) {
      assertEquals("The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage());
    }
  } finally {
    RxJavaPlugins.reset();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void onErrorNull() {
    FlowableProcessor<T> p = create();

    try {
      p.onError(null);
      fail("No NullPointerException thrown");
    } catch (NullPointerException ex) {
      assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
    }

    p.test().assertEmpty().cancel();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void nullThrowable() {
  CompletableSubject cs = CompletableSubject.create();
  try {
    cs.onError(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  cs.test().assertEmpty().cancel();;
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextNull() {
  Subject<T> p = create();
  try {
    p.onNext(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  p.test().assertEmpty().cancel();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void nullValue() {
  SingleSubject<Integer> ss = SingleSubject.create();
  try {
    ss.onSuccess(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  ss.test().assertEmpty().cancel();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void nullThrowable() {
  SingleSubject<Integer> ss = SingleSubject.create();
  try {
    ss.onError(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  ss.test().assertEmpty().cancel();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void onNextNull() {
  FlowableProcessor<T> p = create();
  try {
    p.onNext(null);
    fail("No NullPointerException thrown");
  } catch (NullPointerException ex) {
    assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
  }
  p.test().assertEmpty().cancel();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void onErrorNull() {
    Subject<T> p = create();

    try {
      p.onError(null);
      fail("No NullPointerException thrown");
    } catch (NullPointerException ex) {
      assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage());
    }

    p.test().assertEmpty().cancel();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("rawtypes")
@Test
public void pluginNull() {
  RxJavaPlugins.setOnFlowableSubscribe(new BiFunction<Flowable, Subscriber, Subscriber>() {
    @Override
    public Subscriber apply(Flowable a, Subscriber b) throws Exception {
      return null;
    }
  });
  try {
    try {
      Flowable.just(1).test();
      fail("Should have thrown");
    } catch (NullPointerException ex) {
      assertEquals("The RxJavaPlugins.onSubscribe hook returned a null FlowableSubscriber. Please check the handler provided to RxJavaPlugins.setOnFlowableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins", ex.getMessage());
    }
  } finally {
    RxJavaPlugins.reset();
  }
}

相关文章