• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TearDown类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:UninterruptiblesTest.java


示例17: 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 manually called (thus the "manual" moniker).
 *
 * @see #setUp(TestCase, Class)
 */
public static TearDown setUp(
    TestCase testCase, 
    GuiceBerryEnvSelector guiceBerryEnvSelector) {
  final GuiceBerryWrapper setUpAndTearDown =
    GuiceBerry.INSTANCE.buildWrapper(buildTestDescription(testCase, testCase.getName()), 
        guiceBerryEnvSelector);
  setUpAndTearDown.runBeforeTest();
  return new TearDown() {
    
    public void tearDown() throws Exception {
      setUpAndTearDown.runAfterTest();
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:22,代码来源:ManualTearDownGuiceBerry.java


示例18: runBeforeTest

import com.google.common.testing.TearDown; //导入依赖的package包/类
public synchronized void runBeforeTest() {
  
  // If anything should go wrong, we "tag" this scaffolding as having failed
  // to acquire an injector, so that the tear down knows to skip the
  // appropriate steps.
  injector = BOGUS_INJECTOR;

  checkPreviousTestCalledTearDown(testDescription);
  
  final Class<? extends Module> gbeClass =
    guiceBerryEnvSelector.guiceBerryEnvToUse(testDescription);
  
  universe.currentTestDescriptionThreadLocal.set(testDescription);
  injector = getAndSetInjector(gbeClass);

  stack.addTearDown(new TearDown() {
    public void tearDown() throws Exception {
      doTearDown();
    }
  });
  
  stack.addTearDown(new TearDown() {
    public void tearDown() throws Exception {
      ToTearDown toTearDown = injector.getInstance(ToTearDown.class);
      toTearDown.runTearDown();
    }
  });
  
  TearDownAccepter accepter = wrappedGetInstance(injector, TearDownAccepter.class, gbeClass);
  buildTestWrapperInstance(injector).toRunBeforeTest();
  
  injectMembersIntoTest(gbeClass, injector); 
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:34,代码来源:GuiceBerryUniverse.java


示例19: adapt

import com.google.common.testing.TearDown; //导入依赖的package包/类
private static TestWrapper adapt(
    final com.google.inject.testing.guiceberry.TestScopeListener instance,
    final TearDownAccepter tearDownAccepter) {
  return new TestWrapper() {

    public void toRunBeforeTest() {
      tearDownAccepter.addTearDown(new TearDown() {
        public void tearDown() throws Exception {
          instance.exitingScope();
        }
      });
      instance.enteringScope();
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:16,代码来源:GuiceBerryUniverse.java


示例20: getToTearDown

import com.google.common.testing.TearDown; //导入依赖的package包/类
@Provides
@TestScoped
ToTearDown getToTearDown() {
  return new ToTearDown() {
    TearDownStack delegate = new TearDownStack();
    
    public void addTearDown(TearDown tearDown) {
      delegate.addTearDown(tearDown);
    }
  
    public void runTearDown() {
      delegate.runTearDown();
    }
  };
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:16,代码来源:GuiceBerryModule.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EntityWolf类代码示例发布时间:2022-05-22
下一篇:
Java StaticMember类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap