[Jiemamy-notify:2627] commit [3586] 解決しなければいけない「問題」と、そのテストケース作成…。

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2009年 9月 16日 (水) 01:57:17 JST


Revision: 3586
          http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3586
Author:   daisuke_m
Date:     2009-09-16 01:57:17 +0900 (Wed, 16 Sep 2009)

Log Message:
-----------
解決しなければいけない「問題」と、そのテストケース作成…。

Added Paths:
-----------
    hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Factory.java
    hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/FactoryTest.java

Removed Paths:
-------------
    hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Daisuke.java

Deleted: hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Daisuke.java
===================================================================
--- hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Daisuke.java	2009-09-15 15:19:27 UTC (rev 3585)
+++ hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Daisuke.java	2009-09-15 16:57:17 UTC (rev 3586)
@@ -1,55 +0,0 @@
-/*
- * Copyright 2007-2009 Jiemamy Project and the Others.
- * Created on 2008/12/31
- *
- * This file is part of Jiemamy.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-package org.jiemamy.sandbox.daisuke;
-
-import java.lang.annotation.Annotation;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.jiemamy.Jiemamy;
-import org.jiemamy.model.RootModel;
-
-/**
- * 個人的な実験場。
- * 
- * @author daisuke
- */
-public class Daisuke {
-	
-	private static Logger logger = LoggerFactory.getLogger(Daisuke.class);
-	
-
-	/**
-	 * 実験。
-	 * 
-	 * @throws Exception 例外が発生した場合
-	 */
-	@Test
-	public void testname() throws Exception {
-		Jiemamy jiemamy = Jiemamy.newInstance();
-		
-		RootModel rootModel = jiemamy.getFactory().getRootModel();
-		Annotation[] annotation = rootModel.getClass().getAnnotations();
-		logger.info(rootModel.getClass().getName());
-		logger.info(ArrayUtils.toString(annotation));
-	}
-}

Added: hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Factory.java
===================================================================
--- hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Factory.java	                        (rev 0)
+++ hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Factory.java	2009-09-15 16:57:17 UTC (rev 3586)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/09/16
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.sandbox.daisuke;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 問題のファクトリ。
+ * 
+ * テストを壊さず、コンパイラ警告を解消して実装してください。
+ * 
+ * @author daisuke
+ */
+public class Factory {
+	
+	private Map<Class<?>, Comparator<?>> map = new HashMap<Class<?>, Comparator<?>>();
+	
+
+	/**
+	 * 指定した型のコンパレータを取得する。
+	 * 
+	 * <p>登録されていない場合は{@code null}を返す。</p>
+	 * 
+	 * @param <T> キーとなるクラスの型
+	 * @param clazz キーとなるクラス
+	 * @return コンパレータ
+	 */
+	public <T>Comparator<T> getComparator(Class<T> clazz) {
+		return (Comparator<T>) map.get(clazz); // コンパイラ警告
+		// Type safety: Unchecked cast from Comparator<capture#1-of ?> to Comparator<T>
+	}
+	
+	/**
+	 * 指定した型に対応するコンパレータを登録する。
+	 * 
+	 * @param <T> 比較するクラスの型
+	 * @param clazz 比較するクラス
+	 * @param comparator コンパレータ
+	 */
+	public <T>void put(Class<T> clazz, Comparator<T> comparator) {
+		map.put(clazz, comparator);
+	}
+}


Property changes on: hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/Factory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/FactoryTest.java
===================================================================
--- hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/FactoryTest.java	                        (rev 0)
+++ hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/FactoryTest.java	2009-09-15 16:57:17 UTC (rev 3586)
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/09/16
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.sandbox.daisuke;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.Comparator;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * {@link Factory}のテストクラス。
+ * 
+ * @author daisuke
+ */
+public class FactoryTest {
+	
+	static final Comparator<String> COMPARATOR = new StringComparator();
+	
+	private Factory factory;
+	
+
+	/**
+	 * テストを初期化する。
+	 * 
+	 * @throws Exception 例外が発生した場合
+	 */
+	@Before
+	public void setUp() throws Exception {
+		factory = new Factory();
+	}
+	
+	/**
+	 * テストの情報を破棄する。
+	 * 
+	 * @throws Exception 例外が発生した場合
+	 */
+	@After
+	public void tearDown() throws Exception {
+		factory = null;
+	}
+	
+	/**
+	 * 登録されていない型を指定すると{@code null}が返る。
+	 * 
+	 * @throws Exception 例外が発生した場合
+	 */
+	@Test
+	public void test1() throws Exception {
+		assertThat(factory.getComparator(String.class), is(nullValue()));
+		assertThat(factory.getComparator(Number.class), is(nullValue()));
+	}
+	
+	/**
+	 * 登録した型を指定すると、登録したコンパレータが返る。
+	 * 
+	 * @throws Exception 例外が発生した場合
+	 */
+	@Test
+	public void test2() throws Exception {
+		factory.put(String.class, COMPARATOR);
+		
+		assertThat(factory.getComparator(String.class), is(COMPARATOR));
+		assertThat(factory.getComparator(Number.class), is(nullValue()));
+	}
+	
+
+	static class StringComparator implements Comparator<String> {
+		
+		public int compare(String o1, String o2) {
+			return 0;
+		}
+		
+	}
+}


Property changes on: hercules/trunk/jiemamy-integration-test/src/test/java/org/jiemamy/sandbox/daisuke/FactoryTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain




Jiemamy-notify メーリングリストの案内
アーカイブの一覧に戻る