com.segment.analytics.Analytics.setSingletonInstance()方法的使用及代码示例

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

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

Analytics.setSingletonInstance介绍

[英]Set the global instance returned from #with.

This method must be called before any calls to #with and may only be called once.
[中]使用设置从#返回的全局实例。
必须在调用#with之前调用此方法,并且只能调用一次。

代码示例

代码示例来源:origin: segmentio/analytics-android

@Test
public void setSingletonInstanceMayOnlyBeCalledOnce() {
 Analytics.singleton = null;
 Analytics analytics = new Analytics.Builder(RuntimeEnvironment.application, "foo").build();
 Analytics.setSingletonInstance(analytics);
 try {
  Analytics.setSingletonInstance(analytics);
  fail("Can't set singleton instance twice.");
 } catch (IllegalStateException e) {
  assertThat(e).hasMessage("Singleton instance already exists.");
 }
}

代码示例来源:origin: segmentio/analytics-android

@Test
public void setSingletonInstanceAfterWithFails() {
 Analytics.singleton = null;
 Analytics.setSingletonInstance(
   new Analytics.Builder(RuntimeEnvironment.application, "foo") //
     .build());
 Analytics analytics = new Analytics.Builder(RuntimeEnvironment.application, "bar").build();
 try {
  Analytics.setSingletonInstance(analytics);
  fail("Can't set singleton instance after with().");
 } catch (IllegalStateException e) {
  assertThat(e).hasMessage("Singleton instance already exists.");
 }
}

代码示例来源:origin: segmentio/analytics-android

@Test
public void setSingleInstanceReturnedFromWith() {
 Analytics.singleton = null;
 Analytics analytics = new Analytics.Builder(RuntimeEnvironment.application, "foo").build();
 Analytics.setSingletonInstance(analytics);
 assertThat(Analytics.with(RuntimeEnvironment.application)).isSameAs(analytics);
}

代码示例来源:origin: segmentio/analytics-android

@Test
public void shutdownDisallowedOnCustomSingletonInstance() throws Exception {
 Analytics.singleton = null;
 try {
  Analytics analytics = new Analytics.Builder(RuntimeEnvironment.application, "foo").build();
  Analytics.setSingletonInstance(analytics);
  analytics.shutdown();
  fail("Calling shutdown() on static singleton instance should throw");
 } catch (UnsupportedOperationException ignored) {
 }
}

代码示例来源:origin: segmentio/analytics-android

Analytics.setSingletonInstance(builder.build());

相关文章