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


Java Rule类代码示例

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


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

示例1: getObjectRule

import org.junit.Rule; //导入依赖的package包/类
@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;
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:Jsonschema2PojoRuleTest.java

示例2: class_has_source_of_import

import org.junit.Rule; //导入依赖的package包/类
@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);
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:19,代码来源:ClassFileImporterTest.java

示例3: matches_annotation_by_type

import org.junit.Rule; //导入依赖的package包/类
@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");
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:18,代码来源:CanBeAnnotatedTest.java

示例4: validateSpringMethodRuleConfiguration

import org.junit.Rule; //导入依赖的package包/类
/**
 * 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));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SpringClassRule.java

示例5: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import org.junit.Rule; //导入依赖的package包/类
@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("ClassUnderTest"));
    assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:40,代码来源:JpaUnitRuleTest.java

示例6: initClassFields

import org.junit.Rule; //导入依赖的package包/类
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);
                }
            }
        }
    }
}
 
开发者ID:fabioCollini,项目名称:DaggerMock,代码行数:24,代码来源:OverriddenObjectsMap.java

示例7: openAndCloseDriver

import org.junit.Rule; //导入依赖的package包/类
@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
                    }
            }
        }
    };
}
 
开发者ID:ruediste,项目名称:rise,代码行数:21,代码来源:WebTestBase.java

示例8: visitEnd

import org.junit.Rule; //导入依赖的package包/类
@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();
}
 
开发者ID:dodie,项目名称:scott,代码行数:18,代码来源:StateTrackingTestClassVisitor.java

示例9: hasTimeoutRule

import org.junit.Rule; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:20,代码来源:BuckBlockJUnit4ClassRunner.java

示例10: init

import org.junit.Rule; //导入依赖的package包/类
@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("MINOR")
    .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);
}
 
开发者ID:aifraenkel,项目名称:caltec-tools,代码行数:21,代码来源:JiraIssueCreatorTest.java

示例11: shouldInitRemoteIssueWithoutName

import org.junit.Rule; //导入依赖的package包/类
@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);
}
 
开发者ID:aifraenkel,项目名称:caltec-tools,代码行数:22,代码来源:JiraIssueCreatorTest.java

示例12: hasTimeoutRule

import org.junit.Rule; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:facebook,项目名称:buck,代码行数:20,代码来源:BuckBlockJUnit4ClassRunner.java

示例13: get_all_classes_by_LocationProvider

import org.junit.Rule; //导入依赖的package包/类
@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());
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:12,代码来源:ClassCacheTest.java

示例14: imports_the_classpath

import org.junit.Rule; //导入依赖的package包/类
@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);
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:12,代码来源:ClassFileImporterSlowTest.java

示例15: imports_packages

import org.junit.Rule; //导入依赖的package包/类
@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));
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:11,代码来源:ClassFileImporterSlowTest.java


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