Skip to content

Commit

Permalink
Add unit test for JIgnore annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauer committed Apr 22, 2016
1 parent f926253 commit d295a2b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
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 {
}
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")
}
}
}

0 comments on commit d295a2b

Please sign in to comment.