本文整理汇总了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());
}
示例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());
}
示例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");
}
示例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");
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例12: setUp
import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
logHandler = new TestLogHandler();
LocalCache.logger.addHandler(logHandler);
}
示例13: getAndResetRecords
import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
private static int getAndResetRecords(TestLogHandler logHandler) {
int records = logHandler.getStoredLogRecords().size();
logHandler.clear();
return records;
}
示例14: LogsSubject
import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public LogsSubject(FailureMetadata failureMetadata, TestLogHandler subject) {
super(failureMetadata, subject);
}
示例15: assertAboutLogs
import com.google.common.testing.TestLogHandler; //导入依赖的package包/类
public static SimpleSubjectBuilder<LogsSubject, TestLogHandler> assertAboutLogs() {
return assertAbout(LogsSubject::new);
}