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


Java ExpectedException.expect方法代码示例

本文整理汇总了Java中org.junit.rules.ExpectedException.expect方法的典型用法代码示例。如果您正苦于以下问题:Java ExpectedException.expect方法的具体用法?Java ExpectedException.expect怎么用?Java ExpectedException.expect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.junit.rules.ExpectedException的用法示例。


在下文中一共展示了ExpectedException.expect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: assertNullPointerExceptionThrown

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
public static void assertNullPointerExceptionThrown(ExpectedException expectedException, String expectMessage) {
	expectedException.expect(NullPointerException.class);
	expectedException.expectMessage(expectMessage);
}
 
开发者ID:visGeek,项目名称:JavaVisGeekCollections,代码行数:5,代码来源:Assert2.java

示例9: testGetFailsFromCorruptFile

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
/**
 * Checks the GET operation fails when the downloaded file (from HA store)
 * is corrupt, i.e. its content's hash does not match the {@link BlobKey}'s hash.
 *
 * @param config
 * 		blob server configuration (including HA settings like {@link HighAvailabilityOptions#HA_STORAGE_PATH}
 * 		and {@link HighAvailabilityOptions#HA_CLUSTER_ID}) used to set up <tt>blobStore</tt>
 * @param blobStore
 * 		shared HA blob store to use
 * @param expectedException
 * 		expected exception rule to use
 */
public static void testGetFailsFromCorruptFile(
		Configuration config, BlobStore blobStore, ExpectedException expectedException)
		throws IOException {

	Random rnd = new Random();
	JobID jobId = new JobID();

	try (BlobServer server = new BlobServer(config, blobStore)) {

		server.start();

		byte[] data = new byte[2000000];
		rnd.nextBytes(data);

		// put content addressable (like libraries)
		BlobKey key = put(server, jobId, data, PERMANENT_BLOB);
		assertNotNull(key);

		// delete local file to make sure that the GET requests downloads from HA
		File blobFile = server.getStorageLocation(jobId, key);
		assertTrue(blobFile.delete());

		// change HA store file contents to make sure that GET requests fail
		byte[] data2 = Arrays.copyOf(data, data.length);
		data2[0] ^= 1;
		File tmpFile = Files.createTempFile("blob", ".jar").toFile();
		try {
			FileUtils.writeByteArrayToFile(tmpFile, data2);
			blobStore.put(tmpFile, jobId, key);
		} finally {
			//noinspection ResultOfMethodCallIgnored
			tmpFile.delete();
		}

		// issue a GET request that fails
		expectedException.expect(IOException.class);
		expectedException.expectMessage("data corruption");

		get(server, jobId, key);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:54,代码来源:BlobServerCorruptionTest.java

示例10: expect404NotFoundCallfireApiException

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
protected void expect404NotFoundCallfireApiException(ExpectedException ex) {
    ex.expect(CallfireApiException.class);
    ex.expect(hasProperty("apiErrorMessage", hasProperty("httpStatusCode", Matchers.is(404))));
}
 
开发者ID:CallFire,项目名称:callfire-api-client-java,代码行数:5,代码来源:AbstractIntegrationTest.java

示例11: setExpectedExceptions

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void setExpectedExceptions(ExpectedException exception, Class<?> type, String message) {
    exception.expect((Class<? extends Throwable>) type);
    exception.expectMessage(message);
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:6,代码来源:MockingHelper.java

示例12: setExpectedExceptions

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void setExpectedExceptions(Class<?> type, ExpectedException exception, String message) {
    exception.expect((Class<? extends Throwable>) type);
    exception.expectMessage(message);
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:6,代码来源:TestUtils.java

示例13: itThrows

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
/**
 * Statement that a unit should throw a specific exception for a particular case
 *
 * @param throwable the class of the expected exception type
 * @param forCase   a description of the case in which it should be thrown
 * @param testCase  an implementation of the case in which is should be thrown
 * @param <T>       the expected exception type
 * @return a Specification representing the single description
 */
default <T extends Throwable> SpecificationNode itThrows(Class<T> throwable, String forCase, Test testCase) {
    ExpectedException expectedException = ExpectedException.none();
    expectedException.expect(throwable);
    return SpecificationNode.leaf(
        String.format("throws %s %s", throwable.getSimpleName(), forCase),
        testCase).withRule(expectedException);
}
 
开发者ID:hgcummings,项目名称:jarspec,代码行数:17,代码来源:ExceptionBehaviour.java

示例14: expect

import org.junit.rules.ExpectedException; //导入方法依赖的package包/类
/**
 * Convenience method to match message without arguments
 * on our custom BusinessValidationException.
 *
 * NOTE: expectMessage with equalTo() instead of the standard hamcrest contains()
 *
 * @param thrown ExpectedException to attach to
 * @param message that is expected
 */
public static void expect(String message, ExpectedException thrown)
{
    thrown.expect(BusinessValidationException.class);
    thrown.expectMessage(equalTo(message));
}
 
开发者ID:jeffsheets,项目名称:carmaint,代码行数:15,代码来源:BusinessValidationExceptionMatchers.java


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