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


Java TearDown类代码示例

本文整理汇总了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();
      }
    }
  });
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:26,代码来源:InterruptionUtil.java

示例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();
    }
  });
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:UninterruptibleFutureTest.java

示例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();
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:19,代码来源:GuiceBerryJunit3.java

示例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();
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:22,代码来源:AutoTearDownGuiceBerry.java

示例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();
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:21,代码来源:TestNgGuiceBerry.java

示例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());
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:24,代码来源:GuiceBerryUniverseTest.java

示例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());
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:18,代码来源:GuiceBerryJunit3Test.java

示例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());
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:22,代码来源:GuiceBerryJunit3Test.java

示例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());
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:23,代码来源:GuiceBerryJunit3Test.java

示例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());
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:22,代码来源:GuiceBerryJunit3Test.java

示例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);
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:19,代码来源:Example3TestWrapperTest.java

示例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);
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:18,代码来源:Example3TestWrapperTest.java

示例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();
          }
        }
      });
}
 
开发者ID:google,项目名称:guava,代码行数:27,代码来源:InterruptionUtil.java

示例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();
        }
      });
}
 
开发者ID:google,项目名称:guava,代码行数:18,代码来源:UninterruptiblesTest.java

示例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();
        }
      });
}
 
开发者ID:google,项目名称:guava,代码行数:22,代码来源:UninterruptibleFutureTest.java


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