當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpectedException類代碼示例

本文整理匯總了Java中org.junit.rules.ExpectedException的典型用法代碼示例。如果您正苦於以下問題:Java ExpectedException類的具體用法?Java ExpectedException怎麽用?Java ExpectedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExpectedException類屬於org.junit.rules包,在下文中一共展示了ExpectedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: noValueForSize

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void noValueForSize() throws IOException {
    thrown = ExpectedException.none();
    // Basic division by zero.
    final Token token = def("a", div(con(1), con(0)));
    assertFalse(token.parse(env(stream(1))).isPresent());
    // Try to negate division by zero.
    final Token token2 = def("a", neg(div(con(1), con(0))));
    assertFalse(token2.parse(env(stream(1))).isPresent());
    // Add one to division by zero.
    final Token token3 = def("a", add(div(con(1), con(0)), con(1)));
    assertFalse(token3.parse(env(stream(1))).isPresent());
    // Add division by zero to one.
    final Token token4 = def("a", add(con(1), div(con(1), con(0))));
    assertFalse(token4.parse(env(stream(1))).isPresent());
}
 
開發者ID:parsingdata,項目名稱:metal,代碼行數:17,代碼來源:ErrorsTest.java

示例2: testExceptionThrownWhenMisConfigured

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void testExceptionThrownWhenMisConfigured() throws Exception {
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  conf.set("hbase.thrift.security.qop", "privacy");
  conf.setBoolean("hbase.thrift.ssl.enabled", false);

  ThriftServerRunner runner = null;
  ExpectedException thrown = ExpectedException.none();
  try {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Thrift HTTP Server's QoP is privacy, " +
        "but hbase.thrift.ssl.enabled is false");
    runner = new ThriftServerRunner(conf);
    fail("Thrift HTTP Server starts up even with wrong security configurations.");
  } catch (Exception e) {
  }

  assertNull(runner);
}
 
開發者ID:apache,項目名稱:hbase,代碼行數:20,代碼來源:TestThriftHttpServer.java

示例3: testAnnotationBasedParser

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void testAnnotationBasedParser() {
    expectedEx = ExpectedException.none();

    MyMapper mapper = new MyMapper();

    TestRecord record = new TestRecord("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " +
        "Chrome/48.0.2564.82 Safari/537.36");

    record = mapper.enrich(record);

    assertEquals("Desktop", record.deviceClass);
    assertEquals("Chrome 48.0.2564.82", record.agentNameVersion);
}
 
開發者ID:nielsbasjes,項目名稱:yauaa,代碼行數:15,代碼來源:TestAnnotationSystem.java

示例4: tearDown

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@After
public void tearDown() throws Exception {
    //單個測試案例執行完之後,引用置空,防止數據汙染
    tEmployee = null;
    tEmployeeExample = null;
    expectedException = ExpectedException.none();
}
 
開發者ID:xmomen,項目名稱:easy-mybatis,代碼行數:8,代碼來源:MybatisDaoTest.java

示例5: testMakeFromUrlAndPath

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void testMakeFromUrlAndPath() throws Exception {
    if (expectedResult == null) {
        expectedException.expect(IllegalArgumentException.class);
    } else {
        expectedException = ExpectedException.none();
    }

    assertThat(UrlHelper.makeFromUrlAndPath(url, path)).isEqualTo(expectedResult);
}
 
開發者ID:jakriz,項目名稱:derrick,代碼行數:11,代碼來源:UrlHelperTest.java

示例6: classTest

import org.junit.rules.ExpectedException; //導入依賴的package包/類
private TypeSpec classTest(ClassName className, List<MethodSpec> methodSpecs) {
  String methodName = Introspector
      .decapitalize(className.simpleName());

  MethodSpec abstractMethodInstanceToTest = methodBuilder(methodName)
      .addModifiers(Modifier.ABSTRACT, Modifier.PROTECTED)
      .returns(className)
      .build();

  FieldSpec exception = FieldSpec.builder(ExpectedException.class, "exception")
      .addAnnotation(Rule.class)
      .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
      .initializer("$T.none()", ExpectedException.class)
      .build();

  return TypeSpec.classBuilder(className.simpleName() + "Test_")
      .addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC)
      .addMethod(abstractMethodInstanceToTest)
      .addField(exception)
      .addAnnotation(AnnotationSpec.builder(Generated.class)
          .addMember("value", "$S", MockeryProcessor.class.getCanonicalName())
          .addMember("comments", "$S", CMessages.codeGenerateWarning())
          .build())
      .addAnnotation(AnnotationSpec.builder(RunWith.class)
          .addMember("value", "$T.class", OrderedRunner.class)
          .build())
      .addMethods(methodSpecs)
      .build();
}
 
開發者ID:VictorAlbertos,項目名稱:Mockery,代碼行數:30,代碼來源:BrewJavaFile.java

示例7: testAddAfterSort

import org.junit.rules.ExpectedException; //導入依賴的package包/類
/** Tests trying to call add after calling sort. Should throw an exception. */
public static void testAddAfterSort(Sorter sorter, ExpectedException thrown) throws Exception {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage(is("Records can only be added before sort()"));
  KV<byte[], byte[]> kv = KV.of(new byte[] {4, 7}, new byte[] {1, 2});
  sorter.add(kv);
  sorter.sort();
  sorter.add(kv);
}
 
開發者ID:apache,項目名稱:beam,代碼行數:10,代碼來源:SorterTestUtils.java

示例8: testSortTwice

import org.junit.rules.ExpectedException; //導入依賴的package包/類
/** Tests trying to calling sort twice. Should throw an exception. */
public static void testSortTwice(Sorter sorter, ExpectedException thrown) throws Exception {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage(is("sort() can only be called once."));
  KV<byte[], byte[]> kv = KV.of(new byte[] {4, 7}, new byte[] {1, 2});
  sorter.add(kv);
  sorter.sort();
  sorter.sort();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:10,代碼來源:SorterTestUtils.java

示例9: nsdManagementOnboardTest

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void nsdManagementOnboardTest()
    throws NotFoundException, BadFormatException, NetworkServiceIntegrityException,
        CyclicDependenciesException, EntityInUseException, BadRequestException, IOException,
        AlreadyExistingException, PluginException, IncompatibleVNFPackage, VimException,
        InterruptedException, EntityUnreachableException {

  NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor();

  when(vnfmManagerEndpointRepository.findAll())
      .thenReturn(
          new ArrayList<VnfmManagerEndpoint>() {
            {
              VnfmManagerEndpoint vnfmManagerEndpoint = new VnfmManagerEndpoint();
              vnfmManagerEndpoint.setEndpoint("test");
              vnfmManagerEndpoint.setType("test");
              vnfmManagerEndpoint.setActive(true);
              vnfmManagerEndpoint.setEnabled(true);
              add(vnfmManagerEndpoint);
            }
          });

  when(nsdRepository.save(nsd_exp)).thenReturn(nsd_exp);
  exception = ExpectedException.none();
  nsdManagement.onboard(nsd_exp, projectId);
  assertEqualsNSD(nsd_exp);
}
 
開發者ID:openbaton,項目名稱:NFVO,代碼行數:28,代碼來源:NetworkServiceDescriptorManagementClassSuiteTest.java

示例10: testHTTPError

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void testHTTPError() {
	ExpectedException exception = ExpectedException.none();
	try {
		exception.expect(CandybeanException.class);
		response = WS.request(WS.OP.POST, uri + "/get", headers, "", ContentType.DEFAULT_TEXT);
		Assert.fail();
	} catch (CandybeanException e) {
		Assert.assertEquals("HTTP request received HTTP code: 405",
				e.getMessage().split("\n")[0]);
	}
}
 
開發者ID:sugarcrm,項目名稱:candybean,代碼行數:13,代碼來源:WSSystemTest.java

示例11: testResponseError

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
@Ignore("This test should pass, but takes a full minute to do so because it" +
		"waits for the response to time out.")
public void testResponseError() {
	ExpectedException exception = ExpectedException.none();
	try {
		exception.expect(CandybeanException.class);
		// Send to an IP address that does not exist
		response = WS.request(WS.OP.POST, "http://240.0.0.0", headers, "", ContentType.DEFAULT_TEXT);
		Assert.fail();
	} catch (CandybeanException e) {
		Assert.assertEquals("Connect to 240.0.0.0:80 [/240.0.0.0] failed: Operation timed out", e.getMessage());
	}
}
 
開發者ID:sugarcrm,項目名稱:candybean,代碼行數:15,代碼來源:WSSystemTest.java

示例12: outputIsIdentical

import org.junit.rules.ExpectedException; //導入依賴的package包/類
@Test
public void outputIsIdentical() throws IOException, InterruptedException, ExecutionException {
  if (!ToolHelper.artSupported()) {
    return;
  }

  String original = getOriginalDexFile().toString();

  File generated;
  // Collect the generated dex files.
  File[] outputFiles =
      temp.getRoot().listFiles((File file) -> file.getName().endsWith(".dex"));
  if (outputFiles.length == 1) {
    // Just run Art on classes.dex.
    generated = outputFiles[0];
  } else {
    // Run Art on JAR file with multiple dex files.
    generated = temp.getRoot().toPath().resolve(pkg + ".jar").toFile();
    JarBuilder.buildJar(outputFiles, generated);
  }

  ToolHelper.ProcessResult javaResult =
      ToolHelper.runJava(ImmutableList.of(getOriginalJarFile().toString()), mainClass);
  if (javaResult.exitCode != 0) {
    fail("JVM failed for: " + mainClass);
  }

  // TODO(ager): Once we have a bot running using dalvik (version 4.4.4) we should remove
  // this explicit loop to get rid of repeated testing on the buildbots.
  for (DexVm version : artVersions) {
    TestCondition condition = failingRun.get(mainClass);
    if (condition != null && condition.test(tool, compiler, version, mode)) {
      thrown.expect(Throwable.class);
    } else {
      thrown = ExpectedException.none();
    }

    // Check output against Art output on original dex file.
    String output =
        ToolHelper.checkArtOutputIdentical(original, generated.toString(), mainClass, version);

    // Check output against JVM output.
    if (shouldMatchJVMOutput(version)) {
      String javaOutput = javaResult.stdout;
      assertEquals(
          "JVM and Art output differ:\n" + "JVM:\n" + javaOutput + "\nArt:\n" + output,
          output,
          javaOutput);
    }
  }
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:52,代碼來源:R8RunExamplesTest.java

示例13: thrown

import org.junit.rules.ExpectedException; //導入依賴的package包/類
public ExpectedException thrown() {
    return thrown;
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:4,代碼來源:ObjectifyTest.java

示例14: expectInvalidSyntaxUsageForClassInsteadOfInterface

import org.junit.rules.ExpectedException; //導入依賴的package包/類
public static void expectInvalidSyntaxUsageForClassInsteadOfInterface(ExpectedException thrown, Class<?> nonInterface) {
    thrown.expect(InvalidSyntaxUsageException.class);
    thrown.expectMessage(nonInterface.getName());
    thrown.expectMessage("interface");
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:6,代碼來源:JavaClassTest.java

示例15: expectInvalidSyntaxUsageForRetentionSource

import org.junit.rules.ExpectedException; //導入依賴的package包/類
public static void expectInvalidSyntaxUsageForRetentionSource(ExpectedException thrown) {
    thrown.expect(InvalidSyntaxUsageException.class);
    thrown.expectMessage(Retention.class.getSimpleName());
    thrown.expectMessage(RetentionPolicy.SOURCE.name());
    thrown.expectMessage("useless");
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:7,代碼來源:CanBeAnnotatedTest.java


注:本文中的org.junit.rules.ExpectedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。