项目:GitHub
文件:Jsonschema2PojoRuleTest.java
@Override
public org.jsonschema2pojo.rules.Rule<JPackage,JType> getobjectRule() {
final org.jsonschema2pojo.rules.Rule<JPackage,JType> workingRule = super.getobjectRule();
return new org.jsonschema2pojo.rules.Rule<JPackage,JType>() {
@Override
public JType apply(String nodeName,JsonNode node,JPackage generatableType,Schema currentSchema) {
JType objectType = workingRule.apply(nodeName,node,generatableType,currentSchema);
if( objectType instanceof JDefinedClass ) {
JDefinedClass jclass = (JDefinedClass)objectType;
jclass.method(JMod.PUBLIC,jclass.owner().BOOLEAN,"brokenMethod").body();
}
return objectType;
}
};
}
项目:ArchUnit
文件:ClassFileImporterTest.java
@Test
public void class_has_source_of_import() throws Exception {
ArchConfiguration.get().setMd5InClassSourcesEnabled(true);
JavaClass clazzFromFile = new ClassFileImporter().importClass(ClasstoImportOne.class);
Source source = clazzFromFile.getSource().get();
assertthat(source.getUri()).isEqualTo(urlOf(ClasstoImportOne.class).toURI());
assertthat(source.getMd5sum()).isEqualTo(md5sumOf(bytesAt(urlOf(ClasstoImportOne.class))));
JavaClass clazzFromJar = new ClassFileImporter().importClass(Rule.class);
source = clazzFromJar.getSource().get();
assertthat(source.getUri()).isEqualTo(urlOf(Rule.class).toURI());
assertthat(source.getMd5sum()).isEqualTo(md5sumOf(bytesAt(urlOf(Rule.class))));
ArchConfiguration.get().setMd5InClassSourcesEnabled(false);
source = new ClassFileImporter().importClass(ClasstoImportOne.class).getSource().get();
assertthat(source.getMd5sum()).isEqualTo(MD5_SUM_disABLED);
}
项目:ArchUnit
文件:CanBeAnnotatedTest.java
@Test
public void matches_annotation_by_type() {
assertthat(annotatedWith(RuntimeRetentionAnnotation.class).apply(importClassWithContext(AnnotatedClass.class)))
.as("annotated class matches").isTrue();
assertthat(annotatedWith(RuntimeRetentionAnnotation.class.getName()).apply(importClassWithContext(AnnotatedClass.class)))
.as("annotated class matches").isTrue();
assertthat(annotatedWith(RuntimeRetentionAnnotation.class).apply(importClassWithContext(Object.class)))
.as("annotated class matches").isFalse();
assertthat(annotatedWith(RuntimeRetentionAnnotation.class.getName()).apply(importClassWithContext(Object.class)))
.as("annotated class matches").isFalse();
assertthat(annotatedWith(Rule.class).getDescription())
.isEqualTo("annotated with @Rule");
assertthat(annotatedWith(Rule.class.getName()).getDescription())
.isEqualTo("annotated with @Rule");
}
项目:spring4-understanding
文件:SpringClassRule.java
/**
* Throw an {@link IllegalStateException} if the supplied {@code testClass}
* does not declare a {@code public SpringMethodRule} field that is
* annotated with {@code @Rule}.
*/
private static void validateSpringMethodRuleConfiguration(Class<?> testClass) {
Field ruleField = null;
for (Field field : testClass.getFields()) {
int modifiers = field.getModifiers();
if (!Modifier.isstatic(modifiers) && Modifier.isPublic(modifiers) &&
SpringMethodRule.class.isAssignableFrom(field.getType())) {
ruleField = field;
break;
}
}
if (ruleField == null) {
throw new IllegalStateException(String.format(
"Failed to find 'public SpringMethodRule' field in test class [%s]. " +
"Consult the javadoc for SpringClassRule for details.",testClass.getName()));
}
if (!ruleField.isAnnotationPresent(Rule.class)) {
throw new IllegalStateException(String.format(
"SpringMethodRule field [%s] must be annotated with JUnit's @Rule annotation. " +
"Consult the javadoc for SpringClassRule for details.",ruleField));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"ClassUnderTest");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC,JpaUnitRule.class,"rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jcodemodel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar emField = jClass.field(JMod.PRIVATE,EntityManager.class,"em");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
jAnnotation.param("unitName","test-unit-1");
final JMethod jMethod = jClass.method(JMod.PUBLIC,jcodemodel.VOID,"testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(),jcodemodel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(),jClass.name());
final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertthat(descriptionCaptor.getValue().getClassName(),equalTo("ClassUnderTest"));
assertthat(descriptionCaptor.getValue().getmethodName(),equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertthat(descriptionCaptor.getValue().getClassName(),equalTo("testMethod"));
}
项目:DaggerMock
文件:OverriddenObjectsMap.java
private void initClassFields(Object target,Class<?> targetClass) {
Field[] targetFields = targetClass.getDeclaredFields();
for (Field field : targetFields) {
if (field.getAnnotation(Rule.class) == null) {
if (!Modifier.isstatic(field.getModifiers())) {
field.setAccessible(true);
try {
final Object value = field.get(target);
if (value != null) {
fields.put(new ObjectId(field),new Provider() {
@Override
public Object get() {
return value;
}
});
}
} catch (illegalaccessexception e) {
throw new RuntimeException("Error accessing field " + field,e);
}
}
}
}
}
项目:rise
文件:WebTestBase.java
@Rule
public final TestRule openAndCloseDriver() {
return (base,description) -> new Statement() {
@Override
public void evaluate() throws Throwable {
driver = createDriver();
try {
base.evaluate();
} finally {
if (closeDriver)
try {
driver.close();
} catch (Throwable t) {
// swallow
}
}
}
};
}
@Override
public void visitEnd() {
if (transformationParameters.isJUnit4RuleInjectionrequired) {
FieldVisitor fv = super.visitField(Opcodes.ACC_PUBLIC,"scottReportingRule",Type.getDescriptor(ScottReportingRule.class),null,null);
fv.visitAnnotation(Type.getDescriptor(Rule.class),true).visitEnd();
}
if (transformationParameters.isjunit5ExtensionInjectionrequired) {
AnnotationVisitor av0 = super.visitAnnotation("Lorg/junit/jupiter/api/extension/ExtendWith;",true);
AnnotationVisitor av1 = av0.visitArray("value");
av1.visit(null,Type.getType("Lhu/advancedweb/scott/runtime/Scottjunit5Extension;"));
av1.visitEnd();
av0.visitEnd();
}
super.visitEnd();
}
项目:buck-cutom
文件:BuckBlockJUnit4ClassRunner.java
/**
* @return {@code true} if the test class has any fields annotated with {@code Rule} whose type
* is {@link Timeout}.
*/
static boolean hasTimeoutRule(TestClass testClass) {
// Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11
// such as getTestRules(Object) were not public until
// https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740,// which appears to be JUnit 4.9. Because we allow users to use JUnit 4.7,we need to include a
// custom implementation that is backwards compatible to JUnit 4.7.
List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class);
for (FrameworkField field : fields) {
if (field.getField().getType().equals(Timeout.class)) {
return true;
}
}
return false;
}
项目:caltec-tools
文件:JiraIssueCreatorTest.java
@Before
public void init() throws Exception {
sonarIssue = new DefaultIssue()
.setKey("ABCD")
.setMessage("The Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.")
.setSeverity("MI@R_404_6462@")
.setRuleKey(RuleKey.of("squid","CycleBetweenPackages"));
ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(RuleKey.of("squid","CycleBetweenPackages"))).thenReturn(org.sonar.api.rules.Rule.create().setName("Avoid cycle between java packages"));
settings = new Settings(new PropertyDeFinitions(JiraIssueCreator.class,JiraPlugin.class));
settings.setProperty(CoreProperties.SERVER_BASE_URL,"http://my.sonar.com");
settings.setProperty(JiraConstants.SERVER_URL_PROPERTY,"http://my.jira.com");
settings.setProperty(JiraConstants.USERNAME_PROPERTY,"foo");
settings.setProperty(JiraConstants.PASSWORD_PROPERTY,"bar");
settings.setProperty(JiraConstants.JIRA_PROJECT_KEY_PROPERTY,"TEST");
jiraIssueCreator = new JiraIssueCreator(ruleFinder);
}
项目:caltec-tools
文件:JiraIssueCreatorTest.java
@Test
public void shouldInitRemoteIssueWithoutName() throws Exception {
// Given that
when(ruleFinder.findByKey(RuleKey.of("squid","CycleBetweenPackages"))).thenReturn(org.sonar.api.rules.Rule.create().setName(null));
RemoteIssue expectedissue = new RemoteIssue();
expectedissue.setProject("TEST");
expectedissue.setType("3");
expectedissue.setPriority("4");
expectedissue.setSummary("Sonar Issue - CycleBetweenPackages");
//expectedissue.setSummary("Sonar Issue #ABCD");
expectedissue.setDescription("Issue detail:\n{quote}\nThe Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.\n" +
"{quote}\n\n\nCheck it on Sonar: http://my.sonar.com/issue/show/ABCD");
// Verify
RemoteIssue returnedissue = jiraIssueCreator.initRemoteIssue(sonarIssue,settings,"");
assertthat(returnedissue.getSummary()).isEqualTo(expectedissue.getSummary());
assertthat(returnedissue.getDescription()).isEqualTo(expectedissue.getDescription());
assertthat(returnedissue).isEqualTo(expectedissue);
}
项目:buck
文件:BuckBlockJUnit4ClassRunner.java
/**
* @return {@code true} if the test class has any fields annotated with {@code Rule} whose type is
* {@link Timeout}.
*/
static boolean hasTimeoutRule(TestClass testClass) {
// Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11
// such as getTestRules(Object) were not public until
// https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740,we need to include a
// custom implementation that is backwards compatible to JUnit 4.7.
List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class);
for (FrameworkField field : fields) {
if (field.getField().getType().equals(Timeout.class)) {
return true;
}
}
return false;
}
项目:ArchUnit
文件:ClassCacheTest.java
@Test
public void get_all_classes_by_LocationProvider() {
JavaClasses classes = cache.getClassesToAnalyzefor(TestClassWithLocationProviders.class);
assertthatClasses(classes).contain(String.class,Rule.class,getClass());
classes = cache.getClassesToAnalyzefor(TestClassWithLocationProviderUsingTestClass.class);
assertthatClasses(classes).contain(String.class);
assertthatClasses(classes).dontContain(getClass());
}
项目:ArchUnit
文件:ClassFileImporterSlowTest.java
@Test
public void imports_the_classpath() {
JavaClasses classes = new ClassFileImporter().importClasspath();
assertthatClasses(classes).contain(ClassFileImporter.class,getClass());
assertthatClasses(classes).dontContain(Rule.class); // Default doesn't import jars
classes = new ClassFileImporter().importClasspath(new ImportOptions());
assertthatClasses(classes).contain(ClassFileImporter.class,getClass(),Rule.class);
}
项目:ArchUnit
文件:ClassFileImporterSlowTest.java
@Test
public void imports_packages() {
JavaClasses classes = new ClassFileImporter().importPackages(
getClass().getPackage().getName(),Rule.class.getPackage().getName());
assertthatClasses(classes).contain(ImmutableSet.of(getClass(),Rule.class));
classes = new ClassFileImporter().importPackages(
ImmutableSet.of(getClass().getPackage().getName(),Rule.class.getPackage().getName()));
assertthatClasses(classes).contain(ImmutableSet.of(getClass(),Rule.class));
}
项目:ArchUnit
文件:ClassFileImporterSlowTest.java
@Test
public void imports_packages_of_classes() {
JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass(),Rule.class);
assertthatClasses(classes).contain(ImmutableSet.of(getClass(),Rule.class));
classes = new ClassFileImporter().importPackagesOf(ImmutableSet.of(getClass(),Rule.class));
assertthatClasses(classes).contain(ImmutableSet.of(getClass(),Rule.class));
}
项目:ArchUnit
文件:ClassFileImporterSlowTest.java
@Test
public void imports_jars() throws Exception {
JavaClasses classes = new ClassFileImporter().importJar(jarFileOf(Rule.class));
assertthatClasses(classes).contain(Rule.class);
assertthatClasses(classes).dontContain(Object.class,ImmutableList.class);
classes = new ClassFileImporter().importJars(jarFileOf(Rule.class),jarFileOf(ImmutableList.class));
assertthatClasses(classes).contain(Rule.class,ImmutableList.class);
assertthatClasses(classes).dontContain(Object.class);
classes = new ClassFileImporter().importJars(ImmutableList.of(
jarFileOf(Rule.class),jarFileOf(ImmutableList.class)));
assertthatClasses(classes).contain(Rule.class,ImmutableList.class);
assertthatClasses(classes).dontContain(Object.class);
}
项目:ArchUnit
文件:ClassFileImporterTest.java
@Test
public void ImportOptions_are_respected() throws Exception {
ClassFileImporter importer = new ClassFileImporter().withImportOption(importOnly(getClass(),Rule.class));
assertthatClasses(importer.importPath(Paths.get(urlOf(getClass()).toURI()))).matchExactly(getClass());
assertthatClasses(importer.importUrl(urlOf(getClass()))).matchExactly(getClass());
assertthatClasses(importer.importJar(jarFileOf(Rule.class))).matchExactly(Rule.class);
}
项目:Spork
文件:ExceptionMessageBuilderTests.java
@Test
public void annotation() {
String message = new ExceptionMessageBuilder("test")
.annotation(Rule.class)
.build();
assertthat(message,is("test\n - annotation: org.junit.Rule"));
}
项目:jpa-unit
文件:JpaUnitRunner.java
public JpaUnitRunner(final Class<?> clazz) throws InitializationError {
super(clazz);
executor = new DecoratorExecutor();
final List<FrameworkField> ruleFields = getTestClass().getAnnotatedFields(Rule.class);
if (ruleFields.stream().anyMatch(f -> f.getType().equals(JpaUnitRule.class))) {
throw new InitializationError("JpaUnitRunner and JpaUnitRule exclude each other");
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithoutPersistenceContextField() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jcodemodel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JMethod jMethod = jClass.method(JMod.PUBLIC,jClass.name());
try {
// WHEN
new JpaUnitRule(cut);
fail("IllegalArgumentException expected");
} catch (final IllegalArgumentException e) {
// THEN
assertthat(e.getMessage(),containsstring("EntityManagerFactory or EntityManager field annotated"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithMultiplePersistenceContextFields() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jcodemodel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar em1Field = jClass.field(JMod.PRIVATE,"em1");
em1Field.annotate(PersistenceContext.class);
final JFieldVar em2Field = jClass.field(JMod.PRIVATE,"em2");
em2Field.annotate(PersistenceContext.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,containsstring("Only single field is allowed"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithMultiplePersistenceUnitFields() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jcodemodel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar emf1Field = jClass.field(JMod.PRIVATE,EntityManagerFactory.class,"emf1");
emf1Field.annotate(PersistenceUnit.class);
final JFieldVar emf2Field = jClass.field(JMod.PRIVATE,"emf2");
emf2Field.annotate(PersistenceUnit.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,containsstring("Only single field is allowed"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceContextAndPersistenceUnitFields() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"em");
emf1Field.annotate(PersistenceContext.class);
final JFieldVar emf2Field = jClass.field(JMod.PRIVATE,"emf");
emf2Field.annotate(PersistenceUnit.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,containsstring("either @PersistenceUnit or @PersistenceContext"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceContextFieldOfWrongType() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"em");
emField.annotate(PersistenceContext.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,containsstring("annotated with @PersistenceContext is not of type EntityManager"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceUnitFieldOfWrongType() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"emf");
emField.annotate(PersistenceUnit.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,containsstring("annotated with @PersistenceUnit is not of type EntityManagerFactory"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceContextWithoutUnitNameSpecified() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,jClass.name());
try {
// WHEN
new JpaUnitRule(cut);
fail("JpaUnitException expected");
} catch (final JpaUnitException e) {
// THEN
assertthat(e.getMessage(),containsstring("No Persistence"));
}
}
项目:jpa-unit
文件:JpaUnitRuleTest.java
项目:jpa-unit
文件:JpaUnitRuleTest.java
@Test
public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"emf");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class);
jAnnotation.param("unitName",equalTo("testMethod"));
}
项目:jpa-unit
文件:JpaUnitRunnerTest.java
@Test
public void testJpaUnitRunnerAndJpaUnitRuleFieldExcludeEachOther() throws Exception {
// GIVEN
final Jcodemodel jcodemodel = new Jcodemodel();
final JPackage jp = jcodemodel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC,"ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value",JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE,"test-unit-1");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC,"rule");
ruleField.annotate(Rule.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC,jClass.name());
try {
// WHEN
new JpaUnitRunner(cut);
fail("InitializationError expected");
} catch (final InitializationError e) {
// expected
assertthat(e.getCauses().get(0).getMessage(),containsstring("exclude each other"));
}
}
项目:Mockery
文件:BrewJavaFile.java
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",cmessages.codeGenerateWarning())
.build())
.addAnnotation(AnnotationSpec.builder(RunWith.class)
.addMember("value","$T.class",OrderedRunner.class)
.build())
.addMethods(methodSpecs)
.build();
}
项目:kc-rice
文件:LoadTimeWeavableTestRunner.java
/**
* @param target the test case instance
* @return a list of TestRules that should be applied when executing this
* test
*/
protected List<TestRule> getTestRules(Object target) {
List<TestRule> result = getTestClass().getAnnotatedMethodValues(target,TestRule.class);
result.addAll(getTestClass().getAnnotatedFieldValues(target,TestRule.class));
return result;
}
项目:powermock
文件:PowerMockJUnit47RunnerDelegateImpl.java
@Override
public void executeTest(final Method method,final Object testInstance,final Runnable test) {
// We change the context classloader to the current CL in order for the Mockito
// framework to load it's plugins (such as MockMaker) correctly.
final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
final Set<Field> rules;
try {
rules = WhiteBox.getFieldsAnnotatedWith( testInstance,Rule.class );
} finally {
Thread.currentThread().setContextClassLoader(originalCL);
}
hasRules = !rules.isEmpty();
if (!hasRules) {
executeTestInSuper(method,testInstance,test);
} else {
int processedFields = 0;
for (Field field : rules) {
processedFields++;
try {
LastRuleTestExecutorStatement lastStatement = new LastRuleTestExecutorStatement(processedFields,rules.size(),test,method);
Statement statement = applyRuletoLastStatement(method,field,lastStatement);
statement.evaluate();
} catch (Throwable e) {
/*
* No rule Could handle the exception thus we need to
* add it as a failure.
*/
super.handleException(testMethod,potentialTestFailure == null ? e : potentialTestFailure);
}
}
}
}
项目:junit-clptr
文件:ClassLoaderPerTestRunner.java
/**
* Load classes (TestCase,@Before and @After with custom class loader.
*
* @throws ClassNotFoundException the class not found exception
*/
private void loadClassesWithCustomClassLoader( FrameworkMethod method )
throws ClassNotFoundException
{
// We need the classpath so that our custom loader can search for the requested classes.
String testPath = getClasspath();
TestClassLoader classLoader =
testPath == null
? new TestClassLoader()
: new TestClassLoader( testPath );
ClptrExclude clptrExclude = getTestClass().getAnnotation( ClptrExclude.class );
if ( clptrExclude != null )
{
classLoader.addExcludes( clptrExclude.value() );
}
clptrExclude = method.getAnnotation( ClptrExclude.class );
if ( clptrExclude != null )
{
classLoader.addExcludes(clptrExclude.value() );
}
Thread.currentThread().setContextClassLoader(classLoader);
testClassFromClassLoader = new TestClass(classLoader.loadClass(getTestClass().getJavaClass().getName()));
// See withAfters and withBefores for the reason.
beforeFromClassLoader = classLoader.loadClass(Before.class.getName());
afterFromClassLoader = classLoader.loadClass(After.class.getName());
ruleFromClassLoader = classLoader.loadClass(Rule.class.getName());
}
@Test
public void shouldUpdateFormFieldVisibilityRules() throws Exception {
VisibilityRules visibilityRule = new VisibilityRules();
visibilityRule.setRuleType(RuleType.SHOW);
List<VisibilityRules.Rule> rules = Collections.singletonList(rule("FirstName","isNotEmpty","Der address"));
visibilityRule.setRules(rules);
marketoFormClient.updateFormFieldVisibilityRules(TEST_FORM_ID,TEST_FORM_FIELD,visibilityRule);
// Can not verify - no way to fetch not approved content
}
项目:currencycloud-java
文件:BetamaxTestSupport.java
@Rule
public Recorder createRecorder() {
Recorder recorder = new Recorder();
String tc = this.getClass().getSimpleName();
recorder.setTapeRoot(new File(recorder.getTapeRoot(),(tc).substring(0,tc.length() - "Test".length())));
return recorder;
}
/**
* Creates a test rule.
*
* @return a test rule.
*/
@Rule
public TestRule rule() {
return RuleChain
.outerRule(new LogbackAccessEventQueuingAppenderRule())
.around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter
文件:AbstractForwardHeadersUsingTest.java
/**
* Creates a test rule.
*
* @return a test rule.
*/
@Rule
public TestRule rule() {
return RuleChain
.outerRule(new LogbackAccessEventQueuingAppenderRule())
.around(new LogbackAccessEventQueuingListenerRule());
}
/**
* Creates a test rule.
*
* @return a test rule.
*/
@Rule
public TestRule rule() {
return RuleChain
.outerRule(new LogbackAccessEventQueuingAppenderRule())
.around(new LogbackAccessEventQueuingListenerRule());
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。