本文整理汇总了Java中org.springframework.test.annotation.ExpectedException类的典型用法代码示例。如果您正苦于以下问题:Java ExpectedException类的具体用法?Java ExpectedException怎么用?Java ExpectedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpectedException类属于org.springframework.test.annotation包,在下文中一共展示了ExpectedException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getExpectedException
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
/**
* Get the {@code exception} that the supplied {@link FrameworkMethod
* test method} is expected to throw.
* <p>Supports both Spring's {@link ExpectedException @ExpectedException(...)}
* and JUnit's {@link Test#expected() @Test(expected=...)} annotations, but
* not both simultaneously.
* @return the expected exception, or {@code null} if none was specified
*/
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
Class<? extends Throwable> junitExpectedException = (testAnnotation != null
&& testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
if (springExpectedException != null && junitExpectedException != null) {
String msg = "Test method [" + frameworkMethod.getMethod()
+ "] has been configured with Spring's @ExpectedException(" + springExpectedException.getName()
+ ".class) and JUnit's @Test(expected=" + junitExpectedException.getName()
+ ".class) annotations. "
+ "Only one declaration of an 'expected exception' is permitted per test method.";
logger.error(msg);
throw new IllegalStateException(msg);
}
return springExpectedException != null ? springExpectedException : junitExpectedException;
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:29,代码来源:SpringJUnit4ClassRunner.java
示例2: testGetReferenceWhenNoRow
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(EntityNotFoundException.class)
public void testGetReferenceWhenNoRow() {
// Fails here with TopLink
Person notThere = sharedEntityManager.getReference(Person.class, 666);
// We may get here (as with Hibernate).
// Either behaviour is valid: throw exception on first access
// or on getReference itself.
notThere.getFirstName();
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:AbstractContainerEntityManagerFactoryIntegrationTests.java
示例3: runTest
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
/**
* Runs a test via the supplied {@link TestExecutionCallback}, providing
* support for the {@link ExpectedException @ExpectedException} and
* {@link Repeat @Repeat} annotations.
*
* @param tec the test execution callback to run
* @param testMethod the actual test method: used to retrieve the
* {@link ExpectedException @ExpectedException} and {@link Repeat
* @Repeat} annotations
* @throws Throwable if any exception is thrown
* @see ExpectedException
* @see Repeat
*/
private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable {
ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class);
boolean exceptionIsExpected = (expectedExceptionAnnotation != null && expectedExceptionAnnotation.value() != null);
Class<? extends Throwable> expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value()
: null);
Repeat repeat = testMethod.getAnnotation(Repeat.class);
int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1;
for (int i = 0; i < runs; i++) {
try {
if (runs > 1 && this.logger.isInfoEnabled()) {
this.logger.info("Repetition " + (i + 1) + " of test " + testMethod.getName());
}
tec.run();
if (exceptionIsExpected) {
fail("Expected exception: " + expectedException.getName());
}
}
catch (Throwable ex) {
if (!exceptionIsExpected) {
throw ex;
}
if (!expectedException.isAssignableFrom(ex.getClass())) {
// Wrap the unexpected throwable with an explicit message.
AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <"
+ expectedException.getName() + "> but was <" + ex.getClass().getName() + ">");
assertionError.initCause(ex);
throw assertionError;
}
}
}
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:47,代码来源:AbstractJUnit38SpringContextTests.java
示例4: shouldResolveSimpleDiamondAndThrowLimitException
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(MaxBackTrackLimitReachedException.class)
public void shouldResolveSimpleDiamondAndThrowLimitException() {
int i = 1;
GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder");
String[] git_revs1 = {"g11", "g12"};
u.checkinInOrder(git1, u.d(i++), git_revs1);
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(git1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p1));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p1));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(p2), u.m(p3));
CruiseConfig cruiseConfig = goConfigDao.load();
String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g11");
String p2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), p1_1);
String p3_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p3, u.d(i++), p1_1);
String p1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g12");
String p2_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), p1_2);
MaterialRevisions given = u.mrs(
u.mr(p2, true, p2_2),
u.mr(p3, false, p3_1));
MaterialRevisions expected = u.mrs(
u.mr(p2, true, p2_1),
u.mr(p3, false, p3_1));
assertThat(getRevisionsBasedOnDependencies(p4, cruiseConfig, given), is(expected));
systemEnvironment.set(SystemEnvironment.RESOLVE_FANIN_MAX_BACK_TRACK_LIMIT, 1);
getRevisionsBasedOnDependencies(p4, cruiseConfig, given);
}
开发者ID:gocd,项目名称:gocd,代码行数:35,代码来源:AutoTriggerDependencyResolutionTest.java
示例5: shouldContinueBackTrackingFromItsLastKnownPositionAndNotFromTheBeginning
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test(timeout = 10 * 1000)
@ExpectedException(NoCompatibleUpstreamRevisionsException.class)
public void shouldContinueBackTrackingFromItsLastKnownPositionAndNotFromTheBeginning() {
int i = 1;
GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
String[] git_revs1 = {"g11", "g12", "g13"};
u.checkinInOrder(git1, u.d(i++), git_revs1);
GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
String[] git_revs2 = {"g21", "g22", "g23"};
u.checkinInOrder(git2, u.d(i++), git_revs2);
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(git1), u.m(git2));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(git1), u.m(git2));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p1), u.m(p2));
CruiseConfig cruiseConfig = goConfigDao.load();
String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g11", "g21");
String p2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g12", "g21");
String p2_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g11", "g23");
MaterialRevisions given = u.mrs(
u.mr(p1, true, p1_1),
u.mr(p2, true, p2_2));
assertThat(getRevisionsBasedOnDependencies(p3, cruiseConfig, given), is(given));
}
开发者ID:gocd,项目名称:gocd,代码行数:28,代码来源:AutoTriggerDependencyResolutionTest.java
示例6: testDeleteErrorsWithImportAndOthers
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(UnableToDeleteSchemaException.class)
public void testDeleteErrorsWithImportAndOthers() throws Exception {
publishAllSchemas();
List<URI> schemasToDelete = new ArrayList<URI>();
schemasToDelete.add(this.testSchemaSimpleB.getTargetNamespace());
schemasToDelete.add(this.testSchemaSimpleD.getTargetNamespace());
schemasToDelete.add(this.testSchemaSimpleF.getTargetNamespace());
this.gme.deleteSchemas(schemasToDelete);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:12,代码来源:GMEDeletesSchemaSimpleTestCase.java
示例7: testCycleAMissingDocumentB
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(InvalidSchemaSubmissionException.class)
public void testCycleAMissingDocumentB() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaCycleA);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:8,代码来源:GMEAddSchemaCyclesTestCase.java
示例8: testDeleteErrorsWithImportAndOthers
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(UnableToDeleteSchemaFault.class)
public void testDeleteErrorsWithImportAndOthers() throws Exception {
publishAllSchemas();
List<URI> schemasToDelete = new ArrayList<URI>();
schemasToDelete.add(this.testSchemaSimpleB.getTargetNamespace());
schemasToDelete.add(this.testSchemaSimpleD.getTargetNamespace());
schemasToDelete.add(this.testSchemaSimpleF.getTargetNamespace());
this.gme.deleteSchemas(schemasToDelete);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:11,代码来源:GMEDeletesSchemaSimpleTestCase.java
示例9: testDeleteErrorsWithNestedImport
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(UnableToDeleteSchemaFault.class)
public void testDeleteErrorsWithNestedImport() throws Exception {
publishAllSchemas();
List<URI> schemasToDelete = new ArrayList<URI>();
schemasToDelete.add(this.testSchemaSimpleC.getTargetNamespace());
this.gme.deleteSchemas(schemasToDelete);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:9,代码来源:GMEDeletesSchemaSimpleTestCase.java
示例10: testDeleteErrorsWithMultipleImports
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(UnableToDeleteSchemaFault.class)
public void testDeleteErrorsWithMultipleImports() throws Exception {
publishAllSchemas();
List<URI> schemasToDelete = new ArrayList<URI>();
schemasToDelete.add(this.testSchemaSimpleE.getTargetNamespace());
this.gme.deleteSchemas(schemasToDelete);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:9,代码来源:GMEDeletesSchemaSimpleTestCase.java
示例11: testSchemaWrongNamespace
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(InvalidSchemaSubmissionException.class)
public void testSchemaWrongNamespace() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaWrongNamespace);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:9,代码来源:GMEAddSchemaErrorsTestCase.java
示例12: testSchemaNoImports
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(InvalidSchemaSubmissionException.class)
public void testSchemaNoImports() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaNoImports);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:9,代码来源:GMEAddSchemaErrorsTestCase.java
示例13: testSchemaNoNamespace
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(InvalidSchemaSubmissionException.class)
public void testSchemaNoNamespace() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaNoNamespace);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:8,代码来源:GMEAddSchemaErrorsTestCase.java
示例14: testNullSchemaImported
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(NoSuchNamespaceExistsException.class)
public void testNullSchemaImported() throws Exception {
publishAllSchemas();
this.gme.getImportingNamespaces(null);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:8,代码来源:GMEGetDependenciesSimpleTestCase.java
示例15: testDeleteErrorsWithMultipleImports
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(UnableToDeleteSchemaException.class)
public void testDeleteErrorsWithMultipleImports() throws Exception {
publishAllSchemas();
List<URI> schemasToDelete = new ArrayList<URI>();
schemasToDelete.add(this.testSchemaSimpleE.getTargetNamespace());
this.gme.deleteSchemas(schemasToDelete);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:10,代码来源:GMEDeletesSchemaSimpleTestCase.java
示例16: testCycleBMissingDocumentA
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(InvalidSchemaSubmissionException.class)
public void testCycleBMissingDocumentA() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaCycleB);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid2,代码行数:8,代码来源:GMEAddSchemaCyclesTestCase.java
示例17: testSchemaWrongNamespace
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(InvalidSchemaSubmissionFault.class)
public void testSchemaWrongNamespace() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaWrongNamespace);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:8,代码来源:GMEAddSchemaErrorsTestCase.java
示例18: testSchemaNoImports
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@ExpectedException(InvalidSchemaSubmissionFault.class)
public void testSchemaNoImports() throws Exception {
List<XMLSchema> schemas = new ArrayList<XMLSchema>();
schemas.add(this.testSchemaNoImports);
this.gme.publishSchemas(schemas);
}
开发者ID:NCIP,项目名称:cagrid-core,代码行数:8,代码来源:GMEAddSchemaErrorsTestCase.java
示例19: testDenyWritingOutsideOfEdOrgHierarchyCreate
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(value = AccessDeniedException.class)
public void testDenyWritingOutsideOfEdOrgHierarchyCreate() {
EntityBody entityBody = new EntityBody();
entityBody.put(ParameterConstants.SCHOOL_ID, UN_ASSOCIATED_ED_ORG);
when(uriInfo.getPathSegments()).thenReturn(postPath);
writeValidator.validateWriteRequest(entityBody, uriInfo, principal);
}
开发者ID:inbloom,项目名称:secure-data-service,代码行数:12,代码来源:WriteValidatorTest.java
示例20: testInvalidDelete
import org.springframework.test.annotation.ExpectedException; //导入依赖的package包/类
@Test
@ExpectedException(value = AccessDeniedException.class)
public void testInvalidDelete() {
existingSection.getBody().put(ParameterConstants.SCHOOL_ID, UN_ASSOCIATED_ED_ORG);
when(uriInfo.getPathSegments()).thenReturn(putPath);
writeValidator.validateWriteRequest(null, uriInfo, principal);
}
开发者ID:inbloom,项目名称:secure-data-service,代码行数:8,代码来源:WriteValidatorTest.java
注:本文中的org.springframework.test.annotation.ExpectedException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论