svnno****@sourc*****
svnno****@sourc*****
2009年 2月 9日 (月) 22:41:20 JST
Revision: 2644 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2644 Author: daisuke_m Date: 2009-02-09 22:41:19 +0900 (Mon, 09 Feb 2009) Log Message: ----------- refactor Modified Paths: -------------- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java 2009-02-09 13:27:34 UTC (rev 2643) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java 2009-02-09 13:41:19 UTC (rev 2644) @@ -18,6 +18,9 @@ */ package org.jiemamy; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import java.lang.reflect.Field; @@ -38,9 +41,6 @@ */ public class JiemamyPropertyTest { - private Class<?>[] innerClasses; - - /** * setup * @@ -48,7 +48,6 @@ */ @Before public void setUp() throws Exception { - innerClasses = JiemamyProperty.class.getClasses(); } /** @@ -58,7 +57,6 @@ */ @After public void tearDown() throws Exception { - innerClasses = null; } /** @@ -68,21 +66,27 @@ */ @Test public void test01_ModelHasGetter() throws Exception { - for (Class<?> enumClass : innerClasses) { + for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { if (Enum.class.isAssignableFrom(enumClass) == false) { continue; } + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + Class<?> targetModelClass = annot.value(); - Field[] fields = enumClass.getFields(); - for (Field field : fields) { + for (Field field : enumClass.getFields()) { String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is"); String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get"); try { targetModelClass.getMethod(getterName); } catch (NoSuchMethodException e) { + Method iserMethod; try { - targetModelClass.getMethod(iserName); + iserMethod = targetModelClass.getMethod(iserName); + if (iserMethod.getReturnType() != Boolean.class && iserMethod.getReturnType() != boolean.class) { + fail(targetModelClass.getName() + " is not have " + getterName); + } } catch (NoSuchMethodException e2) { fail(targetModelClass.getName() + " is not have " + getterName + " or " + iserName); } @@ -100,11 +104,14 @@ */ @Test public void test02_ModelHasField() throws Exception { - for (Class<?> enumClass : innerClasses) { + for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { if (Enum.class.isAssignableFrom(enumClass) == false) { continue; } + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + Class<?> interfaceClass = annot.value(); String implClassName = interfaceClass.getName() + "Impl"; @@ -137,7 +144,7 @@ */ @Test public void test03_PropertyHasFieldName() throws Exception { - for (Class<?> clazz : innerClasses) { + for (Class<?> clazz : JiemamyProperty.class.getClasses()) { if (Enum.class.isAssignableFrom(clazz) == false) { continue; } Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java 2009-02-09 13:27:34 UTC (rev 2643) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/JiemamyProperty.java 2009-02-09 13:41:19 UTC (rev 2644) @@ -320,7 +320,7 @@ */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) - public @interface TargetModel { + @interface TargetModel { /** プロパティ記述対象のインターフェイス */ Class<? extends JiemamyElement> value(); @@ -358,4 +358,5 @@ /** {@link ViewModel#getDefinition()}で取得できるプロパティ */ definition } + }