org.junit.Rule Java Examples
The following examples show how to use
org.junit.Rule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void constructor_sortsRules() { List<IncludeExcludeFilter.Rule> rules = Arrays.asList( new IncludeExcludeFilter.Rule.Builder("rule1").setFilterType("URL_PREFIX") .setAction("INCLUDE").setFilterPattern("http://example.com/a").build(), new IncludeExcludeFilter.Rule.Builder("rule2").setFilterType("URL_PREFIX") .setAction("INCLUDE").setFilterPattern("http://example.com/b").build(), new IncludeExcludeFilter.Rule.Builder("rule3").setFilterType("URL_PREFIX") .setAction("EXCLUDE").setFilterPattern("http://private.example.com/").build(), new IncludeExcludeFilter.Rule.Builder("rule4").setFilterType("REGEX") .setAction("INCLUDE").setFilterPattern("\\.html$").setItemType("CONTENT_ITEM").build(), new IncludeExcludeFilter.Rule.Builder("rule5").setFilterType("REGEX") .setAction("INCLUDE").setFilterPattern("\\.pdf$").setItemType("CONTENT_ITEM").build(), new IncludeExcludeFilter.Rule.Builder("rule6").setFilterType("REGEX") .setAction("EXCLUDE").setFilterPattern("\\.pdf.bak$").setItemType("CONTENT_ITEM").build(), new IncludeExcludeFilter.Rule.Builder("rule6").setFilterType("REGEX") .setAction("EXCLUDE").setFilterPattern("\\.doc.bak$").setItemType("CONTENT_ITEM").build(), new IncludeExcludeFilter.Rule.Builder("rule6").setFilterType("REGEX") .setAction("EXCLUDE").setFilterPattern("\\.txt.bak$").setItemType("CONTENT_ITEM").build()); IncludeExcludeFilter filter = new IncludeExcludeFilter(rules); assertSizeEquals(filter.prefixIncludeRules, 2); assertSizeEquals(filter.prefixExcludeRules, 1); assertSizeEquals(filter.regexIncludeRules.get(ItemType.CONTENT_ITEM), 2); assertSizeEquals(filter.regexExcludeRules.get(ItemType.CONTENT_ITEM), 3); }
Example #2
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void urlPrefixExcludeRule_acceptsExpectedPatterns() { List<IncludeExcludeFilter.Rule> rules; rules = Arrays.asList( urlPrefixRule("http://www.example.com/folder", "EXCLUDE"), urlPrefixRule("http://www.example.com/folder/", "EXCLUDE")); eval(true, rules, "http://www.example.com/folder", "http://www.example.com/folder/", "http://www.example.com/folder/file.txt"); eval(false, rules, "http://www.example.com", "http://www.example.com/", "http://www.example.com/folderWithLongerName", "http://www.example.com/otherFolder"); }
Example #3
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void filePrefixExcludeRule_acceptsExpectedPatterns_windows() { assumeThat(IS_WINDOWS, is(true)); List<IncludeExcludeFilter.Rule> rules; rules = Arrays.asList( filePrefixRule("\\\\share\\folder\\path", "EXCLUDE"), filePrefixRule("\\\\share\\folder\\path\\", "EXCLUDE")); eval(true, rules, "\\\\share\\folder\\path", "\\\\share\\folder\\path\\", "\\\\share\\folder\\path\\nestedfolder", "\\\\share\\folder\\path\\nestedfolder\\", "\\\\share\\folder\\path\\file.txt"); eval(false, rules, "\\\\share\\folder", "\\\\share\\folder\\", "\\\\share\\folder\\otherpath", "\\\\share\\folder\\otherpath\\", "\\\\share\\folder\\file.txt", "\\\\share\\folder\\pathWithMoreText\\file.txt"); }
Example #4
Source File: ClassFileImporterTest.java From ArchUnit with Apache License 2.0 | 6 votes |
@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.getFileName()).contains(ClassToImportOne.class.getSimpleName() + ".java"); assertThat(source.getMd5sum()).isEqualTo(md5sumOf(bytesAt(urlOf(ClassToImportOne.class)))); clazzFromFile = new ClassFileImporter().importClass(ClassWithInnerClass.Inner.class); source = clazzFromFile.getSource().get(); assertThat(source.getUri()).isEqualTo(urlOf(ClassWithInnerClass.Inner.class).toURI()); assertThat(source.getFileName()).contains(ClassWithInnerClass.class.getSimpleName() + ".java"); assertThat(source.getMd5sum()).isEqualTo(md5sumOf(bytesAt(urlOf(ClassWithInnerClass.Inner.class)))); JavaClass clazzFromJar = new ClassFileImporter().importClass(Rule.class); source = clazzFromJar.getSource().get(); assertThat(source.getUri()).isEqualTo(urlOf(Rule.class).toURI()); assertThat(source.getFileName()).contains(Rule.class.getSimpleName() + ".java"); 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); }
Example #5
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void filePrefixExcludeRule_acceptsExpectedPatterns_unix() { assumeThat(IS_WINDOWS, is(false)); List<IncludeExcludeFilter.Rule> rules; rules = Arrays.asList( filePrefixRule("/folder", "EXCLUDE")); eval(true, rules, "/folder", "/folder/", "/folder/path", "/folder/path/", "/folder/path/file.txt", "/folder/path/nestedfolder/file.txt"); eval(false, rules, "/", "/folderWithLongerName/", "/otherFolder/path/nestedfolder/file.txt"); }
Example #6
Source File: JpaUnitRunnerTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@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, EntityManagerFactory.class, "emf"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class); jAnnotation.param("unitName", "test-unit-1"); final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule"); ruleField.annotate(Rule.class); 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()); try { // WHEN new JpaUnitRunner(cut); fail("InitializationError expected"); } catch (final InitializationError e) { // expected assertThat(e.getCauses().get(0).getMessage(), containsString("exclude each other")); } }
Example #7
Source File: JpaUnitRuleTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@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")); }
Example #8
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
@Test public void ruleBuilder_missingAction_throwsException() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Rule action"); IncludeExcludeFilter.Rule rule = new IncludeExcludeFilter.Rule.Builder("testRule") .setItemType("CONTENT_ITEM") .setFilterType("REGEX") .setFilterPattern("pattern") .build(); }
Example #9
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
private void eval(boolean expected, List<IncludeExcludeFilter.Rule> rules, String... values) { for (IncludeExcludeFilter.Rule rule : rules) { for (String s : values) { errorCollector.checkThat(rule + " = " + s, rule.eval(s), is(expected)); } } }
Example #10
Source File: JpaUnitRunner.java From jpa-unit with Apache License 2.0 | 5 votes |
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"); } }
Example #11
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
@Test public void fromConfiguration_prefixRules_rulesCreated_unix() throws IOException { assumeThat(IS_WINDOWS, is(false)); Properties config = createProperties( "includeExcludeFilter.includeText.filterType = FILE_PREFIX", "includeExcludeFilter.includeText.filterPattern = /path/to/records", "includeExcludeFilter.includeText.action = INCLUDE", "includeExcludeFilter.includeHtml.filterType = FILE_PREFIX", "includeExcludeFilter.includeHtml.filterPattern = /path/to/records/butNotThese", "includeExcludeFilter.includeHtml.action = EXCLUDE" ); setupConfig.initConfig(config); IncludeExcludeFilter filter = IncludeExcludeFilter.fromConfiguration(); List<IncludeExcludeFilter.Rule> includeRules = filter.prefixIncludeRules; assertSizeEquals(includeRules, 1); IncludeExcludeFilter.Rule rule = includeRules.get(0); assertEquals(IncludeExcludeFilter.Action.INCLUDE, rule.getAction()); assertEquals("/path/to/records", rule.getPredicate().toString()); List<IncludeExcludeFilter.Rule> excludeRules = filter.prefixExcludeRules; assertSizeEquals(excludeRules, 1); rule = excludeRules.get(0); assertEquals(IncludeExcludeFilter.Action.EXCLUDE, rule.getAction()); assertEquals("/path/to/records/butNotThese", rule.getPredicate().toString()); }
Example #12
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
@Test public void fromConfiguration_prefixRules_rulesCreated_windows() throws IOException { assumeThat(IS_WINDOWS, is(true)); Properties config = createProperties( "includeExcludeFilter.includeText.filterType = FILE_PREFIX", "includeExcludeFilter.includeText.filterPattern = \\\\\\\\share\\\\folder\\\\path", "includeExcludeFilter.includeText.action = INCLUDE", "includeExcludeFilter.includeHtml.filterType = FILE_PREFIX", "includeExcludeFilter.includeHtml.filterPattern = " + "\\\\\\\\share\\\\folder\\\\path\\\\notThese", "includeExcludeFilter.includeHtml.action = EXCLUDE" ); setupConfig.initConfig(config); IncludeExcludeFilter filter = IncludeExcludeFilter.fromConfiguration(); List<IncludeExcludeFilter.Rule> includeRules = filter.prefixIncludeRules; assertSizeEquals(includeRules, 1); IncludeExcludeFilter.Rule rule = includeRules.get(0); assertEquals(IncludeExcludeFilter.Action.INCLUDE, rule.getAction()); assertEquals("\\\\share\\folder\\path", rule.getPredicate().toString()); List<IncludeExcludeFilter.Rule> excludeRules = filter.prefixExcludeRules; assertSizeEquals(excludeRules, 1); rule = excludeRules.get(0); assertEquals(IncludeExcludeFilter.Action.EXCLUDE, rule.getAction()); assertEquals("\\\\share\\folder\\path\\notThese", rule.getPredicate().toString()); }
Example #13
Source File: GraknClientIT.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testGettingARule_TheInformationOnTheRuleIsCorrect() { try (Transaction tx = localSession.transaction(Transaction.Type.WRITE)) { tx.putAttributeType("name", grakn.core.kb.concept.api.AttributeType.ValueType.STRING); Pattern when = Graql.parsePattern("$x has name 'expectation-when';"); Pattern then = Graql.parsePattern("$x has name 'expectation-then';"); tx.putRule("expectation-rule", when, then); when = Graql.parsePattern("$x has name 'materialize-when';"); then = Graql.parsePattern("$x has name 'materialize-then';"); tx.putRule("materialize-rule", when, then); tx.commit(); } try (GraknClient.Transaction remoteTx = remoteSession.transaction().read(); Transaction localTx = localSession.transaction(Transaction.Type.READ) ) { GraqlGet query = Graql.match(var("x").type("expectation-rule")).get(); grakn.client.concept.Rule.Remote remoteConcept = remoteTx.stream(query).get().findAny().get().get("x").asRule().asRemote(remoteTx); grakn.core.kb.concept.api.ConceptId localId = grakn.core.kb.concept.api.ConceptId.of(remoteConcept.id().getValue()); grakn.core.kb.concept.api.Rule localConcept = localTx.getConcept(localId).asRule(); assertEquals(localConcept.when(), remoteConcept.when()); assertEquals(localConcept.then(), remoteConcept.then()); } }
Example #14
Source File: CheckstyleRulesDefinitionTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test() { final CheckstyleRulesDefinition definition = new CheckstyleRulesDefinition(); final RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); final RulesDefinition.Repository repository = context .repository(CheckstyleConstants.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(CheckstyleConstants.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo("java"); final List<RulesDefinition.Rule> rules = repository.rules(); assertThat(rules).hasSize(174); for (RulesDefinition.Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (RulesDefinition.Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()).overridingErrorMessage( "Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()).isNotNull(); } if (NO_SQALE.contains(rule.key())) { assertThat(rule.debtRemediationFunction()).overridingErrorMessage( "Sqale remediation function is set for rule '" + rule.key()).isNull(); } else { assertThat(rule.debtRemediationFunction()).overridingErrorMessage( "Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); } } }
Example #15
Source File: ExceptionMessageBuilderTests.java From Spork with Apache License 2.0 | 5 votes |
@Test public void annotation() { String message = new ExceptionMessageBuilder("test") .annotation(Rule.class) .build(); assertThat(message, is("test\n - annotation: org.junit.Rule")); }
Example #16
Source File: CanBeAnnotatedTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void matches_meta_annotation_by_type() { JavaClasses classes = importClassesWithContext(MetaAnnotatedClass.class, Object.class, MetaRuntimeRetentionAnnotation.class); assertThat(metaAnnotatedWith(RuntimeRetentionAnnotation.class)) .accepts(classes.get(MetaAnnotatedClass.class)) .rejects(classes.get(Object.class)); assertThat(metaAnnotatedWith(RuntimeRetentionAnnotation.class.getName())) .accepts(classes.get(MetaAnnotatedClass.class)) .rejects(classes.get(Object.class)); assertThat(metaAnnotatedWith(Rule.class)).hasDescription("meta-annotated with @Rule"); assertThat(metaAnnotatedWith(Rule.class.getName())).hasDescription("meta-annotated with @Rule"); }
Example #17
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
private IncludeExcludeFilter.Rule urlPrefixRule(String prefix, String action) { return new IncludeExcludeFilter.Rule.Builder("testRule") .setFilterType("URL_PREFIX") .setAction(action) .setFilterPattern(prefix) .build(); }
Example #18
Source File: CanBeAnnotatedTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void matches_annotation_by_type() { assertThat(annotatedWith(RuntimeRetentionAnnotation.class)) .accepts(importClassWithContext(AnnotatedClass.class)) .rejects(importClassWithContext(Object.class)); assertThat(annotatedWith(RuntimeRetentionAnnotation.class.getName())) .accepts(importClassWithContext(AnnotatedClass.class)) .rejects(importClassWithContext(Object.class)); assertThat(annotatedWith(Rule.class)).hasDescription("annotated with @Rule"); assertThat(annotatedWith(Rule.class.getName())).hasDescription("annotated with @Rule"); }
Example #19
Source File: IncludeExcludeFilterTest.java From connector-sdk with Apache License 2.0 | 5 votes |
@Test public void ruleBuilder_allValuesSet_succeeds() { IncludeExcludeFilter.Rule rule = new IncludeExcludeFilter.Rule.Builder("testRule") .setItemType("CONTENT_ITEM") .setFilterType("REGEX") .setFilterPattern("file.txt") .setAction("INCLUDE") .build(); assertEquals("testRule", rule.getName()); assertEquals(ItemType.CONTENT_ITEM, rule.getItemType().get()); assertEquals(IncludeExcludeFilter.Action.INCLUDE, rule.getAction()); }
Example #20
Source File: ClassFileImporterTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@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); }
Example #21
Source File: ClassFileImporterSlowTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void imports_jars() throws Exception { JavaClasses classes = new ClassFileImporter().importJar(jarFileOf(Rule.class)); assertThatClasses(classes).contain(Rule.class); assertThatClasses(classes).doNotContain(Object.class, ImmutableList.class); classes = new ClassFileImporter().importJars(jarFileOf(Rule.class), jarFileOf(ImmutableList.class)); assertThatClasses(classes).contain(Rule.class, ImmutableList.class); assertThatClasses(classes).doNotContain(Object.class); classes = new ClassFileImporter().importJars(ImmutableList.of( jarFileOf(Rule.class), jarFileOf(ImmutableList.class))); assertThatClasses(classes).contain(Rule.class, ImmutableList.class); assertThatClasses(classes).doNotContain(Object.class); }
Example #22
Source File: ServiceTalkTestTimeout.java From servicetalk with Apache License 2.0 | 5 votes |
@Override public Statement apply(Statement base, Description description) { // Check if multiple Timeout are present and annotated with @Rule. Class<?> clazz = description.getTestClass(); List<Class<?>> timeoutRuleClasses = new ArrayList<>(2); do { for (Field field : clazz.getDeclaredFields()) { if (field.isAnnotationPresent(Rule.class) && Timeout.class.isAssignableFrom(field.getType())) { timeoutRuleClasses.add(clazz); } } } while ((clazz = clazz.getSuperclass()) != Object.class); if (timeoutRuleClasses.size() > 1) { StringBuilder sb = new StringBuilder(256) .append("Only one @Rule for a Timeout is allowed, but ") .append(timeoutRuleClasses.size()) .append(" were detected in types: "); for (Class<?> clazz2 : timeoutRuleClasses) { sb.append(clazz2.getName()).append(", "); } sb.setLength(sb.length() - 2); throw new IllegalStateException(sb.toString()); } // If timeout is specified in @Test, let that have precedence over the global timeout. Test testAnnotation = description.getAnnotation(Test.class); if (testAnnotation != null) { long timeout = testAnnotation.timeout(); if (timeout > 0) { return new TimeoutStatement(base, timeout, TimeUnit.MILLISECONDS, onTimeout); } } return new TimeoutStatement(base, getTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, onTimeout); }
Example #23
Source File: ClassFileImporterSlowTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@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)); }
Example #24
Source File: ClassFileImporterSlowTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@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)); }
Example #25
Source File: ClassFileImporterSlowTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void respects_ImportOptions_when_using_the_default_importClasspath_method() { JavaClasses classes = new ClassFileImporter().withImportOption(DO_NOT_INCLUDE_TESTS).importClasspath(); assertThatClasses(classes).contain(ClassFileImporter.class); assertThatClasses(classes).doNotContain(getClass(), Rule.class, String.class); }
Example #26
Source File: ClassFileImporterSlowTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void imports_the_classpath() { JavaClasses classes = new ClassFileImporter().importClasspath(); assertThatClasses(classes).contain(ClassFileImporter.class, getClass()); assertThatClasses(classes).doNotContain(Rule.class); // Default does not import jars assertThatClasses(classes).doNotContain(File.class); // Default does not import JDK classes classes = new ClassFileImporter().importClasspath(new ImportOptions().with(importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath())); assertThatClasses(classes).contain(ClassFileImporter.class, getClass(), Rule.class, File.class); }
Example #27
Source File: ImportOptionsTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test @UseDataProvider("do_not_include_archives") public void detects_archives_correctly(ImportOption doNotIncludeArchives) { assertThat(doNotIncludeArchives.includes(locationOf(getClass()))) .as("includes file location") .isTrue(); assertThat(doNotIncludeArchives.includes(locationOf(Rule.class))) .as("includes Jar location") .isFalse(); assertThat(doNotIncludeArchives.includes(locationOf(Object.class))) .as("includes Jrt location") .isFalse(); }
Example #28
Source File: ImportOptionsTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test @UseDataProvider("do_not_include_jars") public void detects_Jars_correctly(ImportOption doNotIncludeJars) { assertThat(doNotIncludeJars.includes(locationOf(getClass()))) .as("includes file location") .isTrue(); assertThat(doNotIncludeJars.includes(locationOf(Rule.class))) .as("includes Jar location") .isFalse(); assertThat(doNotIncludeJars.includes(locationOf(Object.class))) .as("includes Jrt location") .isEqualTo(!comesFromJarArchive(Object.class)); }
Example #29
Source File: ClassCacheTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void get_all_classes_by_LocationProvider() { JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, new TestAnalysisRequest() .withPackagesRoots(ClassCacheTest.class) .withLocationProviders(TestLocationProviderOfClass_String.class, TestLocationProviderOfClass_Rule.class)); assertThatClasses(classes).contain(String.class, Rule.class, getClass()); classes = cache.getClassesToAnalyzeFor(TestClassWithLocationProviderUsingTestClass.class, analyzeLocation(LocationOfClass.Provider.class)); assertThatClasses(classes).contain(String.class); assertThatClasses(classes).doNotContain(getClass()); }
Example #30
Source File: ClassCacheTest.java From ArchUnit with Apache License 2.0 | 5 votes |
@Test public void non_existing_packages_are_ignored() { JavaClasses first = cache.getClassesToAnalyzeFor(TestClass.class, new TestAnalysisRequest() .withPackages("something.that.doesnt.exist") .withPackagesRoots(Rule.class)); JavaClasses second = cache.getClassesToAnalyzeFor(TestClass.class, analyzePackagesOf(Rule.class)); assertThat(first).isEqualTo(second); verifyNumberOfImports(1); }