本文整理汇总了Java中com.google.common.testing.TearDown类的典型用法代码示例。如果您正苦于以下问题:Java TearDown类的具体用法?Java TearDown怎么用?Java TearDown使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TearDown类属于com.google.common.testing包,在下文中一共展示了TearDown类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: repeatedlyInterruptTestThread
import com.google.common.testing.TearDown; //导入依赖的package包/类
static void repeatedlyInterruptTestThread(
long interruptPeriodMillis, TearDownAccepter tearDownAccepter) {
final Interruptenator interruptingTask =
new Interruptenator(Thread.currentThread(), interruptPeriodMillis);
final Thread interruptingThread = new Thread(interruptingTask);
interruptingThread.start();
tearDownAccepter.addTearDown(new TearDown() {
@Override public void tearDown() throws Exception {
interruptingTask.stopInterrupting();
interruptingThread.interrupt();
joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
Thread.interrupted();
if (interruptingThread.isAlive()) {
// This will be hidden by test-output redirection:
logger.severe(
"InterruptenatorTask did not exit; future tests may be affected");
/*
* This won't do any good under JUnit 3, but I'll leave it around in
* case we ever switch to JUnit 4:
*/
fail();
}
}
});
}
示例2: setUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Override protected void setUp() {
final ExecutorService executor = Executors.newSingleThreadExecutor();
tearDownStack.addTearDown(new TearDown() {
@Override
public void tearDown() {
executor.shutdownNow();
}
});
sleeper = new SleepingRunnable(1000);
delayedFuture = executor.submit(sleeper, true);
tearDownStack.addTearDown(new TearDown() {
@Override
public void tearDown() {
Thread.interrupted();
}
});
}
示例3: doSetUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
public synchronized void doSetUp(final TestCase testCase) {
TestDescription testDescription = buildDescription(testCase);
final GuiceBerryWrapper wrapper = guiceBerry.buildWrapper(testDescription,
new VersionTwoBackwardsCompatibleGuiceBerryEnvSelector());
//add a tear down before setting up so that if an exception is thrown there,
//we still do the tear down.
maybeAddGuiceBerryTearDown(testDescription, new TearDown() {
public void tearDown() throws Exception {
wrapper.runAfterTest();
}
});
wrapper.runBeforeTest();
}
示例4: setUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
/**
* Same as {@link #setUp(TearDownAccepter, Class)}, but with the given
* {@code guiceBerryEnvSelector}.
*
* @see #setUp(TestCase, Class)
*/
public static <T extends TestCase & TearDownAccepter> void setUp(
/* TeaDownTestCase */ T testCase,
GuiceBerryEnvSelector guiceBerryEnvSelector) {
final GuiceBerryWrapper toTearDown =
GuiceBerry.INSTANCE.buildWrapper(
ManualTearDownGuiceBerry.buildTestDescription(testCase, testCase.getName()),
guiceBerryEnvSelector);
testCase.addTearDown(new TearDown() {
public void tearDown() throws Exception {
toTearDown.runAfterTest();
}
}) ;
toTearDown.runBeforeTest();
}
示例5: setUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
/**
* Sets up the {@code testCase} with the given {@code guiceBerryEnvSelector}
* and returns a {@link TearDown} whose {@link TearDown#tearDown()} method
* must be called.
*/
public static TearDown setUp(
Object testCase,
Method method,
GuiceBerryEnvSelector guiceBerryEnvSelector) {
final GuiceBerryWrapper setUpAndTearDown =
GuiceBerry.INSTANCE.buildWrapper(buildTestDescription(testCase, method.getName()),
guiceBerryEnvSelector);
setUpAndTearDown.runBeforeTest();
return new TearDown() {
public void tearDown() throws Exception {
setUpAndTearDown.runAfterTest();
}
};
}
示例6: testThrowingTearDown
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Test public void testThrowingTearDown() {
GuiceBerryEnvSelector guiceBerryEnvSelector = DefaultEnvSelector.of(MyGuiceBerryEnv.class);
TestDescription testDescription = bogusTestDescription();
GuiceBerryUniverse.TestCaseScaffolding testCaseScaffolding =
new GuiceBerryUniverse.TestCaseScaffolding(testDescription, guiceBerryEnvSelector, universe);
testCaseScaffolding.runBeforeTest();
Assert.assertTrue(universe.currentTestDescriptionThreadLocal.get() != null);
((MyTest)testDescription.getTestCase()).accepter.addTearDown(new TearDown() {
public void tearDown() throws Exception {
throw new RuntimeException();
}
});
try {
testCaseScaffolding.runAfterTest();
Assert.fail();
} catch (RuntimeException good) {}
Assert.assertEquals(null, universe.currentTestDescriptionThreadLocal.get());
}
示例7: testRemapper
import com.google.common.testing.TearDown; //导入依赖的package包/类
public void testRemapper() {
TestWithGbeOne test = TestWithGbeOne.createInstance();
TearDown tearDown = new TearDown() {
public void tearDown() throws Exception {
System.clearProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME);
}
};
addTearDown(tearDown);
System.setProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME,
MyGuiceBerryEnvRemapper.class.getName());
instance().doSetUp(test);
assertEquals(BarServiceTwo.class, test.barService.getClass());
assertEquals(FooServiceTwo.class, test.fooService.getClass());
}
示例8: testRemapperSystemPropertyNeedsClassThatExists
import com.google.common.testing.TearDown; //导入依赖的package包/类
public void testRemapperSystemPropertyNeedsClassThatExists() {
TestWithGbeOne test = TestWithGbeOne.createInstance();
TearDown tearDown = new TearDown() {
public void tearDown() throws Exception {
System.clearProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME);
}
};
addTearDown(tearDown);
System.setProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME,
"foo");
try {
instance().doSetUp(test);
fail();
} catch (IllegalArgumentException expected) {
assertEquals("Class 'foo', which is being declared as a GuiceBerryEnvRemapper, does not exist.",
expected.getMessage());
}
}
示例9: testRemapperSystemPropertyNeedsClassThatImplementsCorrectInterface
import com.google.common.testing.TearDown; //导入依赖的package包/类
public void testRemapperSystemPropertyNeedsClassThatImplementsCorrectInterface() {
TestWithGbeOne test = TestWithGbeOne.createInstance();
TearDown tearDown = new TearDown() {
public void tearDown() throws Exception {
System.clearProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME);
}
};
addTearDown(tearDown);
System.setProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME,
MyNonGuiceBerryEnvRemapper.class.getName());
try {
instance().doSetUp(test);
fail();
} catch (IllegalArgumentException expected) {
assertEquals("Class '" + SELF_CANONICAL_NAME + "$MyNonGuiceBerryEnvRemapper' " +
"is being declared as a GuiceBerryEnvRemapper, but does not implement that interface",
expected.getMessage());
}
}
示例10: testRemapperSystemPropertyNeedsClassWithZeroArgConstructor
import com.google.common.testing.TearDown; //导入依赖的package包/类
public void testRemapperSystemPropertyNeedsClassWithZeroArgConstructor() {
TestWithGbeOne test = TestWithGbeOne.createInstance();
TearDown tearDown = new TearDown() {
public void tearDown() throws Exception {
System.clearProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME);
}
};
addTearDown(tearDown);
System.setProperty(GuiceBerryEnvRemapper.GUICE_BERRY_ENV_REMAPPER_PROPERTY_NAME,
MyGuiceBerryEnvRemapperWithInvalidConstructor.class.getName());
try {
instance().doSetUp(test);
fail();
} catch (IllegalArgumentException expected) {
assertEquals("GuiceBerryEnvRemapper '" + SELF_CANONICAL_NAME + "$MyGuiceBerryEnvRemapperWithInvalidConstructor' " +
"must have public zero-arguments constructor", expected.getMessage());
}
}
示例11: getTestWrapper
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Provides
@Singleton
TestWrapper getTestWrapper(final TestId testId,
final TearDownAccepter tearDownAccepter) {
return new TestWrapper() {
public void toRunBeforeTest() {
tearDownAccepter.addTearDown(new TearDown() {
public void tearDown() throws Exception {
System.out.println("Ending: " + testId);
}
});
System.out.println("Beginning: " + testId);
}
};
}
示例12: getTestWrapper
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Provides
TestWrapper getTestWrapper(final TestId testId,
final TearDownAccepter tearDownAccepter) {
return new TestWrapper() {
public void toRunBeforeTest() {
tearDownAccepter.addTearDown(new TearDown() {
public void tearDown() throws Exception {
System.out.println("Ending: " + testId);
}
});
System.out.println("Beginning: " + testId);
}
};
}
示例13: repeatedlyInterruptTestThread
import com.google.common.testing.TearDown; //导入依赖的package包/类
static void repeatedlyInterruptTestThread(
long interruptPeriodMillis, TearDownAccepter tearDownAccepter) {
final Interruptenator interruptingTask =
new Interruptenator(Thread.currentThread(), interruptPeriodMillis);
final Thread interruptingThread = new Thread(interruptingTask);
interruptingThread.start();
tearDownAccepter.addTearDown(
new TearDown() {
@Override
public void tearDown() throws Exception {
interruptingTask.stopInterrupting();
interruptingThread.interrupt();
joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
Thread.interrupted();
if (interruptingThread.isAlive()) {
// This will be hidden by test-output redirection:
logger.severe("InterruptenatorTask did not exit; future tests may be affected");
/*
* This won't do any good under JUnit 3, but I'll leave it around in
* case we ever switch to JUnit 4:
*/
fail();
}
}
});
}
示例14: setUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Override
protected void setUp() {
// Clear any previous interrupt before running the test.
if (Thread.currentThread().isInterrupted()) {
throw new AssertionError(
"Thread interrupted on test entry. "
+ "Some test probably didn't clear the interrupt state");
}
tearDownStack.addTearDown(
new TearDown() {
@Override
public void tearDown() {
Thread.interrupted();
}
});
}
示例15: setUp
import com.google.common.testing.TearDown; //导入依赖的package包/类
@Override
protected void setUp() {
final ExecutorService executor = Executors.newSingleThreadExecutor();
tearDownStack.addTearDown(
new TearDown() {
@Override
public void tearDown() {
executor.shutdownNow();
}
});
sleeper = new SleepingRunnable(1000);
delayedFuture = executor.submit(sleeper, true);
tearDownStack.addTearDown(
new TearDown() {
@Override
public void tearDown() {
Thread.interrupted();
}
});
}