当前位置: 首页>>代码示例>>Java>>正文


Java TestLogHandler类代码示例

本文整理汇总了Java中com.google.common.testing.TestLogHandler的典型用法代码示例。如果您正苦于以下问题:Java TestLogHandler类的具体用法?Java TestLogHandler怎么用?Java TestLogHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestLogHandler类属于com.google.common.testing包,在下文中一共展示了TestLogHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEnqueueAndDispatch_withLabeledExceptions

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public void testEnqueueAndDispatch_withLabeledExceptions() {
  Object listener = new MyListener();
  ListenerCallQueue<Object> queue = new ListenerCallQueue<>();
  queue.addListener(listener, directExecutor());
  queue.enqueue(THROWING_EVENT, "custom-label");

  Logger logger = Logger.getLogger(ListenerCallQueue.class.getName());
  logger.setLevel(Level.SEVERE);
  TestLogHandler logHandler = new TestLogHandler();
  logger.addHandler(logHandler);
  try {
    queue.dispatch();
  } finally {
    logger.removeHandler(logHandler);
  }

  assertEquals(1, logHandler.getStoredLogRecords().size());
  assertEquals(
      "Exception while executing callback: MyListener custom-label",
      logHandler.getStoredLogRecords().get(0).getMessage());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:ListenerCallQueueTest.java

示例2: testPartiallyConstructedManager

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
/**
 * Catches a bug where when constructing a service manager failed, later interactions with the
 * service could cause IllegalStateExceptions inside the partially constructed ServiceManager.
 * This ISE wouldn't actually bubble up but would get logged by ExecutionQueue.  This obfuscated
 * the original error (which was not constructing ServiceManager correctly).
 */
public void testPartiallyConstructedManager() {
  Logger logger = Logger.getLogger("global");
  logger.setLevel(Level.FINEST);
  TestLogHandler logHandler = new TestLogHandler();
  logger.addHandler(logHandler);
  NoOpService service = new NoOpService();
  service.startAsync();
  try {
    new ServiceManager(Arrays.asList(service));
    fail();
  } catch (IllegalArgumentException expected) {}
  service.stopAsync();
  // Nothing was logged!
  assertEquals(0, logHandler.getStoredLogRecords().size());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:ServiceManagerTest.java

示例3: testSuccess

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@Test
public void testSuccess() throws IOException, RepoException, ValidationException {
  Files.write(credentialsFile, "https://user:[email protected]".getBytes(UTF_8));

  final TestLogHandler handler = new TestLogHandler();
  Logger.getGlobal().getParent().addHandler(handler);
  UserPassword result;
  try {
    result = credential.fill(repoGitDir, "https://somehost.com/foo/bar");
  } finally {
    Logger.getGlobal().getParent().removeHandler(handler);
  }

  assertThat(result.getUsername()).isEqualTo("user");
  assertThat(result.getPassword_BeCareful()).isEqualTo("SECRET");
  assertThat(result.toString()).doesNotContain("SECRET");
  assertThat(Iterables.transform(handler.getStoredLogRecords(), LogRecord::getMessage))
      .doesNotContain("SECRET");
}
 
开发者ID:google,项目名称:copybara,代码行数:20,代码来源:GitCredentialTest.java

示例4: testUndeclaredExtensionsLogged

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@Test
public void testUndeclaredExtensionsLogged() throws Exception {
  TestLogHandler handler = new TestLogHandler();
  Logger.getLogger(ExtensionManager.class.getCanonicalName()).addHandler(handler);
  ExtensionManager manager =
      new TestInstanceBuilder()
          .setEppRequestSource(EppRequestSource.TOOL)
          .setDeclaredUris()
          .setSuppliedExtensions(MetadataExtension.class)
          .build();
  manager.register(MetadataExtension.class);
  manager.validate();
  ImmutableList.Builder<String> logMessages = new ImmutableList.Builder<>();
  for (LogRecord record : handler.getStoredLogRecords()) {
    logMessages.add(record.getMessage());
  }
  assertThat(logMessages.build())
      .contains(
          "Client clientId is attempting to run HelloFlow without declaring "
              + "URIs [urn:google:params:xml:ns:metadata-1.0] on login");
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:ExtensionManagerTest.java

示例5: testPartiallyConstructedManager

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
/**
 * Catches a bug where when constructing a service manager failed, later interactions with the
 * service could cause IllegalStateExceptions inside the partially constructed ServiceManager.
 * This ISE wouldn't actually bubble up but would get logged by ExecutionQueue. This obfuscated
 * the original error (which was not constructing ServiceManager correctly).
 */
public void testPartiallyConstructedManager() {
  Logger logger = Logger.getLogger("global");
  logger.setLevel(Level.FINEST);
  TestLogHandler logHandler = new TestLogHandler();
  logger.addHandler(logHandler);
  NoOpService service = new NoOpService();
  service.startAsync();
  try {
    new ServiceManager(Arrays.asList(service));
    fail();
  } catch (IllegalArgumentException expected) {
  }
  service.stopAsync();
  // Nothing was logged!
  assertEquals(0, logHandler.getStoredLogRecords().size());
}
 
开发者ID:google,项目名称:guava,代码行数:23,代码来源:ServiceManagerTest.java

示例6: testSuccessfulAsList_resultCancelledRacingInputDone

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Exception {
  TestLogHandler listenerLoggerHandler = new TestLogHandler();
  Logger exceptionLogger = Logger.getLogger(AbstractFuture.class.getName());
  exceptionLogger.addHandler(listenerLoggerHandler);
  try {
    doTestSuccessfulAsList_resultCancelledRacingInputDone();

    assertWithMessage("Nothing should be logged")
        .that(listenerLoggerHandler.getStoredLogRecords()).isEmpty();
  } finally {
    exceptionLogger.removeHandler(listenerLoggerHandler);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:FuturesTest.java

示例7: testLoggingSuppressor

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public static void testLoggingSuppressor() throws IOException {
  TestLogHandler logHandler = new TestLogHandler();

  Closeables.logger.addHandler(logHandler);
  try {
    Closer closer = new Closer(new Closer.LoggingSuppressor());

    TestCloseable c1 = closer.register(TestCloseable.throwsOnClose(new IOException()));
    TestCloseable c2 = closer.register(TestCloseable.throwsOnClose(new RuntimeException()));
    try {
      throw closer.rethrow(new IOException("thrown"), IOException.class);
    } catch (IOException expected) {}

    assertTrue(logHandler.getStoredLogRecords().isEmpty());

    closer.close();

    assertEquals(2, logHandler.getStoredLogRecords().size());

    LogRecord record = logHandler.getStoredLogRecords().get(0);
    assertEquals("Suppressing exception thrown when closing " + c2, record.getMessage());

    record = logHandler.getStoredLogRecords().get(1);
    assertEquals("Suppressing exception thrown when closing " + c1, record.getMessage());
  } finally {
    Closeables.logger.removeHandler(logHandler);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:CloserTest.java

示例8: testSuccessfulAsList_resultCancelledRacingInputDone

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Exception {
  TestLogHandler listenerLoggerHandler = new TestLogHandler();
  Logger exceptionLogger = Logger.getLogger(AbstractFuture.class.getName());
  exceptionLogger.addHandler(listenerLoggerHandler);
  try {
    doTestSuccessfulAsList_resultCancelledRacingInputDone();

    assertWithMessage("Nothing should be logged")
        .that(listenerLoggerHandler.getStoredLogRecords())
        .isEmpty();
  } finally {
    exceptionLogger.removeHandler(listenerLoggerHandler);
  }
}
 
开发者ID:google,项目名称:guava,代码行数:15,代码来源:FuturesTest.java

示例9: testLoggingSuppressor

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public static void testLoggingSuppressor() throws IOException {
  TestLogHandler logHandler = new TestLogHandler();

  Closeables.logger.addHandler(logHandler);
  try {
    Closer closer = new Closer(new Closer.LoggingSuppressor());

    TestCloseable c1 = closer.register(TestCloseable.throwsOnClose(new IOException()));
    TestCloseable c2 = closer.register(TestCloseable.throwsOnClose(new RuntimeException()));
    try {
      throw closer.rethrow(new IOException("thrown"), IOException.class);
    } catch (IOException expected) {
    }

    assertTrue(logHandler.getStoredLogRecords().isEmpty());

    closer.close();

    assertEquals(2, logHandler.getStoredLogRecords().size());

    LogRecord record = logHandler.getStoredLogRecords().get(0);
    assertEquals("Suppressing exception thrown when closing " + c2, record.getMessage());

    record = logHandler.getStoredLogRecords().get(1);
    assertEquals("Suppressing exception thrown when closing " + c1, record.getMessage());
  } finally {
    Closeables.logger.removeHandler(logHandler);
  }
}
 
开发者ID:google,项目名称:guava,代码行数:30,代码来源:CloserTest.java

示例10: setUp

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@BeforeMethod
public void setUp() {
  tearDownTestCase = new TearDownTestCase(){};
  messages = new ArrayList<String>();
  handler = new TestLogHandler();
  TearDownStack.logger.addHandler(handler);
  TearDownStack.logger.setUseParentHandlers(false);
}
 
开发者ID:krishnanand,项目名称:test-libraries-for-java,代码行数:9,代码来源:TearDownTestCaseTest.java

示例11: setUp

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  test = new TearDownTestCase() {};
  messages = new ArrayList<String>();
  handler = new TestLogHandler();
  TearDownStack.logger.addHandler(handler);
  TearDownStack.logger.setUseParentHandlers(false);
}
 
开发者ID:krishnanand,项目名称:test-libraries-for-java,代码行数:9,代码来源:TearDownTestCaseTest.java

示例12: setUp

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
  super.setUp();
  logHandler = new TestLogHandler();
  LocalCache.logger.addHandler(logHandler);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:CacheLoadingTest.java

示例13: getAndResetRecords

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
private static int getAndResetRecords(TestLogHandler logHandler) {
  int records = logHandler.getStoredLogRecords().size();
  logHandler.clear();
  return records;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:6,代码来源:ByteSourceTest.java

示例14: LogsSubject

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public LogsSubject(FailureMetadata failureMetadata, TestLogHandler subject) {
  super(failureMetadata, subject);
}
 
开发者ID:google,项目名称:nomulus,代码行数:4,代码来源:LogsSubject.java

示例15: assertAboutLogs

import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public static SimpleSubjectBuilder<LogsSubject, TestLogHandler> assertAboutLogs() {
  return assertAbout(LogsSubject::new);
}
 
开发者ID:google,项目名称:nomulus,代码行数:4,代码来源:LogsSubject.java


注:本文中的com.google.common.testing.TestLogHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。