-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for JIgnore annotation
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
jackdaw-sample/src/main/java/com/github/vbauer/jackdaw/bean/IgnoredBeanModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.vbauer.jackdaw.bean; | ||
|
||
import com.github.vbauer.jackdaw.annotation.JAdapter; | ||
import com.github.vbauer.jackdaw.annotation.JBean; | ||
import com.github.vbauer.jackdaw.annotation.JBuilder; | ||
import com.github.vbauer.jackdaw.annotation.JClassDescriptor; | ||
import com.github.vbauer.jackdaw.annotation.JComparator; | ||
import com.github.vbauer.jackdaw.annotation.JFactoryMethod; | ||
import com.github.vbauer.jackdaw.annotation.JFunction; | ||
import com.github.vbauer.jackdaw.annotation.JIgnore; | ||
import com.github.vbauer.jackdaw.annotation.JPredicate; | ||
import com.github.vbauer.jackdaw.annotation.JService; | ||
import com.github.vbauer.jackdaw.annotation.JSupplier; | ||
|
||
/** | ||
* @author Vladislav Bauer | ||
*/ | ||
@JIgnore | ||
@JAdapter | ||
@JBean | ||
@JBuilder | ||
@JClassDescriptor | ||
@JComparator | ||
@JFactoryMethod | ||
@JFunction | ||
@JPredicate | ||
@JService(Object.class) | ||
@JSupplier | ||
public abstract class IgnoredBeanModel { | ||
} |
57 changes: 57 additions & 0 deletions
57
jackdaw-sample/src/test/kotlin/com/github/vbauer/jackdaw/JIgnoreTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.vbauer.jackdaw | ||
|
||
import com.github.vbauer.jackdaw.bean.IgnoredBeanModel | ||
import org.hamcrest.BaseMatcher | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matchers.emptyIterable | ||
import org.hamcrest.Matchers.not | ||
import org.junit.Assert.assertThat | ||
import org.junit.Test | ||
import java.util.* | ||
|
||
/** | ||
* @author Vladislav Bauer | ||
*/ | ||
|
||
class JIgnoreTest { | ||
|
||
@Test | ||
fun testIgnoredBean() { | ||
assertThat(generatedClass("Adapter"), notExist()) | ||
assertThat(beanClass(), notExist()) | ||
assertThat(generatedClass("Builder"), notExist()) | ||
assertThat(generatedClass("ClassDescriptor"), notExist()) | ||
assertThat(generatedClass("Comparators"), notExist()) | ||
assertThat(generatedClass("Factory"), notExist()) | ||
assertThat(generatedClass("Functions"), notExist()) | ||
assertThat(generatedClass("Predicates"), notExist()) | ||
assertThat(generatedClass("Suppliers"), notExist()) | ||
|
||
val loader = ServiceLoader.load(IgnoredBeanModel::class.java) | ||
assertThat(loader, emptyIterable()) | ||
} | ||
|
||
|
||
val pkg = "com.github.vbauer.jackdaw.bean" | ||
|
||
private fun notExist() = not(HasClassMatcher()) | ||
private fun generatedClass(name: String) = pkg + ".IgnoredBeanModel" + name | ||
private fun beanClass() = pkg + ".IgnoredBean" | ||
|
||
|
||
class HasClassMatcher : BaseMatcher<String>() { | ||
override fun matches(item: Any?): Boolean { | ||
try { | ||
Class.forName(item.toString()) | ||
return true | ||
} catch (ex: Exception) { | ||
return false | ||
} | ||
} | ||
|
||
override fun describeTo(description: Description) { | ||
description.appendText("existed class") | ||
} | ||
} | ||
} | ||
|