-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from manhole/junit_4_11_compatibility
[S2JUnit4] JUnit4.4と4.11の両方で動作するようにしました。
- Loading branch information
Showing
7 changed files
with
235 additions
and
10 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
s2-tiger/src/main/java/org/seasar/framework/unit/FilterCompatibility.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,54 @@ | ||
package org.seasar.framework.unit; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.runner.Runner; | ||
import org.junit.runner.manipulation.Filter; | ||
import org.junit.runner.manipulation.NoTestsRemainException; | ||
import org.seasar.framework.beans.BeanDesc; | ||
import org.seasar.framework.beans.factory.BeanDescFactory; | ||
import org.seasar.framework.util.MethodUtil; | ||
|
||
/** | ||
* org.junit.runner.manipulation.Filter クラスのシグニチャ変更に対応するクラスです。 | ||
* | ||
* JUnit 4.4: public void apply(Runner) | ||
* ↓ | ||
* JUnit 4.5: public void apply(Object) | ||
* | ||
* | ||
* @author manhole | ||
*/ | ||
public class FilterCompatibility { | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final Class[] APPLY_PARAM_TYPES = new Class[] { Object.class }; | ||
|
||
/** | ||
* Filter#apply(filterable)メソッドを実行します。 | ||
* | ||
* @param filter | ||
* フィルタ | ||
* @param filterable | ||
* フィルタ対象 | ||
* @throws NoTestsRemainException | ||
* フィルタ処理によって全てのテストが除外された場合 | ||
*/ | ||
public static void apply(final Filter filter, final Runner filterable) | ||
throws NoTestsRemainException { | ||
try { | ||
filter.apply(filterable); | ||
} catch (final NoSuchMethodError ignore) { | ||
// JUnit 4.5 or higher | ||
apply45(filter, filterable); | ||
} | ||
} | ||
|
||
private static void apply45(final Filter filter, final Object filterable) { | ||
final BeanDesc beanDesc = BeanDescFactory | ||
.getBeanDesc(filter.getClass()); | ||
final Method method = beanDesc.getMethod("apply", APPLY_PARAM_TYPES); | ||
MethodUtil.invoke(method, filter, new Object[] { filterable }); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
s2-tiger/src/main/java/org/seasar/framework/unit/RunNotifierCompatibility.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,32 @@ | ||
package org.seasar.framework.unit; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
|
||
/** | ||
* org.junit.runner.notification.RunNotifier クラスの変更に対応するクラスです。 | ||
* | ||
* @author manhole | ||
*/ | ||
public class RunNotifierCompatibility { | ||
|
||
/** | ||
* RunNotifier#testAborted メソッドと同等の処理をします。 | ||
* (このメソッドはJUnit4.5で廃止されました) | ||
* | ||
* @param notifier | ||
* ノティフィアー | ||
* @param description | ||
* テストのディスクリプション | ||
* @param e | ||
* 発生した例外 | ||
*/ | ||
public static void testAborted(final RunNotifier notifier, | ||
final Description description, final Throwable e) { | ||
notifier.fireTestStarted(description); | ||
notifier.fireTestFailure(new Failure(description, e)); | ||
notifier.fireTestFinished(description); | ||
} | ||
|
||
} |
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
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
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
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
50 changes: 50 additions & 0 deletions
50
s2-tiger/src/main/java/org/seasar/framework/unit/SorterCompatibility.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,50 @@ | ||
package org.seasar.framework.unit; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.runner.Runner; | ||
import org.junit.runner.manipulation.Sorter; | ||
import org.seasar.framework.beans.BeanDesc; | ||
import org.seasar.framework.beans.factory.BeanDescFactory; | ||
import org.seasar.framework.util.MethodUtil; | ||
|
||
/** | ||
* org.junit.runner.manipulation.Sorter クラスのシグニチャ変更に対応するクラスです。 | ||
* | ||
* JUnit 4.4: public void apply(Runner) | ||
* ↓ | ||
* JUnit 4.5: public void apply(Object) | ||
* | ||
* | ||
* @author manhole | ||
*/ | ||
public class SorterCompatibility { | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final Class[] APPLY_PARAM_TYPES = new Class[] { Object.class }; | ||
|
||
/** | ||
* Sorter#apply(sortable)メソッドを実行します。 | ||
* | ||
* @param sorter | ||
* ソーター | ||
* @param sortable | ||
* ソート対象 | ||
*/ | ||
public static void apply(final Sorter sorter, final Runner sortable) { | ||
try { | ||
sorter.apply(sortable); | ||
} catch (final NoSuchMethodError ignore) { | ||
// JUnit 4.5 or higher | ||
apply45(sorter, sortable); | ||
} | ||
} | ||
|
||
private static void apply45(final Sorter sorter, final Object sortable) { | ||
final BeanDesc beanDesc = BeanDescFactory | ||
.getBeanDesc(sorter.getClass()); | ||
final Method method = beanDesc.getMethod("apply", APPLY_PARAM_TYPES); | ||
MethodUtil.invoke(method, sorter, new Object[] { sortable }); | ||
} | ||
|
||
} |