com.google.common.testing.TestLogHandler Java Examples
The following examples show how to use
com.google.common.testing.TestLogHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitCredentialTest.java From copybara with Apache License 2.0 | 6 votes |
@Test public void testSuccess() throws Exception { Files.write(credentialsFile, "https://user:[email protected]".getBytes(UTF_8)); 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"); }
Example #2
Source File: ProfilerTest.java From copybara with Apache License 2.0 | 6 votes |
@Test public void testListenerLogging() { // Keep a strong reference to the Logger we use to capture log records for the duration of the // test to avoid any potential race conditions with the weak referencing used by the JDK // // TODO: This could be migrated to use the package level logger name, which would be less // fragile against code being moved around. Logger loggerUnderTest = Logger.getLogger(LogProfilerListener.class.getCanonicalName()); TestLogHandler assertingHandler = new TestLogHandler(); assertingHandler.setLevel(Level.FINE); loggerUnderTest.addHandler(assertingHandler); profiler = new Profiler(ticker); profiler.init(ImmutableList.of(new LogProfilerListener())); try (ProfilerTask ignore = profiler.start("testListenerLogging")) { // do something } LogRecord record = assertingHandler.getStoredLogRecords().get(0); assertThat(record.getMessage()).contains("testListenerLogging"); assertThat(record.getSourceClassName()).contains(this.getClass().getName()); loggerUnderTest.removeHandler(assertingHandler); }
Example #3
Source File: ExtensionManagerTest.java From nomulus with Apache License 2.0 | 6 votes |
@Test public void testUndeclaredExtensionsLogged() throws Exception { TestLogHandler handler = new TestLogHandler(); LoggerConfig.getConfig(ExtensionManager.class).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"); }
Example #4
Source File: LogsSubject.java From nomulus with Apache License 2.0 | 4 votes |
public LogsSubject(FailureMetadata failureMetadata, TestLogHandler subject) { super(failureMetadata, subject); this.actual = subject; }
Example #5
Source File: LogsSubject.java From nomulus with Apache License 2.0 | 4 votes |
public static SimpleSubjectBuilder<LogsSubject, TestLogHandler> assertAboutLogs() { return assertAbout(LogsSubject::new); }
Example #6
Source File: TestLogHandlerUtils.java From nomulus with Apache License 2.0 | 4 votes |
/** * Find the first log message stored in the handler that has the provided prefix, and return that * message with the prefix stripped off. */ public static String findFirstLogMessageByPrefix(TestLogHandler handler, String prefix) { return findFirstLogRecordWithMessagePrefix(handler, prefix) .getMessage() .replaceFirst("^" + prefix, ""); }
Example #7
Source File: TestLogHandlerUtils.java From nomulus with Apache License 2.0 | 4 votes |
/** Returns the first log record stored in handler whose message has the provided prefix. */ public static LogRecord findFirstLogRecordWithMessagePrefix( TestLogHandler handler, final String prefix) { return Iterables.find( handler.getStoredLogRecords(), logRecord -> logRecord.getMessage().startsWith(prefix)); }
Example #8
Source File: CacheLoadingTest.java From caffeine with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); logHandler = new TestLogHandler(); logger.addHandler(logHandler); }