1
1
package org .junit .tests .experimental .categories ;
2
2
3
-
4
3
import static org .hamcrest .CoreMatchers .is ;
5
4
import static org .junit .Assert .assertThat ;
6
5
7
- import java .lang .reflect .Method ;
8
6
import java .util .List ;
9
7
10
8
import org .junit .After ;
14
12
import org .junit .Test ;
15
13
import org .junit .experimental .categories .Category ;
16
14
import org .junit .experimental .categories .CategoryValidator ;
15
+ import org .junit .runners .model .FrameworkMethod ;
16
+ import org .junit .runners .model .TestClass ;
17
17
18
18
public class CategoryValidatorTest {
19
19
@@ -47,30 +47,30 @@ public static void methodWithCategory() {
47
47
}
48
48
49
49
@ Test
50
- public void errorIsAddedWhenCategoryIsUsedWithBeforeClass () throws NoSuchMethodException {
51
- Method method = CategoryTest .class . getMethod ( "methodWithCategoryAndBeforeClass" );
52
- testAndAssertErrrorMessage (method , "@BeforeClass can not be combined with @Category" );
50
+ public void errorIsAddedWhenCategoryIsUsedWithBeforeClass () {
51
+ FrameworkMethod method = new TestClass ( CategoryTest .class ). getAnnotatedMethods ( BeforeClass . class ). get ( 0 );
52
+ testAndAssertErrorMessage (method , "@BeforeClass can not be combined with @Category" );
53
53
}
54
54
55
55
@ Test
56
- public void errorIsAddedWhenCategoryIsUsedWithAfterClass () throws NoSuchMethodException {
57
- Method method = CategoryTest .class . getMethod ( "methodWithCategoryAndAfterClass" );
58
- testAndAssertErrrorMessage (method , "@AfterClass can not be combined with @Category" );
56
+ public void errorIsAddedWhenCategoryIsUsedWithAfterClass () {
57
+ FrameworkMethod method = new TestClass ( CategoryTest .class ). getAnnotatedMethods ( AfterClass . class ). get ( 0 );
58
+ testAndAssertErrorMessage (method , "@AfterClass can not be combined with @Category" );
59
59
}
60
60
61
61
@ Test
62
- public void errorIsAddedWhenCategoryIsUsedWithBefore () throws NoSuchMethodException {
63
- Method method = CategoryTest .class . getMethod ( "methodWithCategoryAndBefore" );
64
- testAndAssertErrrorMessage (method , "@Before can not be combined with @Category" );
62
+ public void errorIsAddedWhenCategoryIsUsedWithBefore () {
63
+ FrameworkMethod method = new TestClass ( CategoryTest .class ). getAnnotatedMethods ( Before . class ). get ( 0 );
64
+ testAndAssertErrorMessage (method , "@Before can not be combined with @Category" );
65
65
}
66
66
67
67
@ Test
68
- public void errorIsAddedWhenCategoryIsUsedWithAfter () throws NoSuchMethodException {
69
- Method method = CategoryTest .class . getMethod ( "methodWithCategoryAndAfter" );
70
- testAndAssertErrrorMessage (method , "@After can not be combined with @Category" );
68
+ public void errorIsAddedWhenCategoryIsUsedWithAfter () {
69
+ FrameworkMethod method = new TestClass ( CategoryTest .class ). getAnnotatedMethods ( After . class ). get ( 0 );
70
+ testAndAssertErrorMessage (method , "@After can not be combined with @Category" );
71
71
}
72
72
73
- private void testAndAssertErrrorMessage ( Method method , String expectedErrorMessage ) throws NoSuchMethodException {
73
+ private void testAndAssertErrorMessage ( FrameworkMethod method , String expectedErrorMessage ) {
74
74
List <Exception > errors = new CategoryValidator ().validateAnnotatedMethod (method );
75
75
76
76
assertThat (errors .size (), is (1 ));
@@ -80,8 +80,8 @@ private void testAndAssertErrrorMessage(Method method, String expectedErrorMessa
80
80
81
81
@ Test
82
82
public void errorIsNotAddedWhenCategoryIsNotCombinedWithIllegalCombination () throws NoSuchMethodException {
83
- Method beforeClass = CategoryTest .class .getMethod ("methodWithCategory" );
84
- List <Exception > errors = new CategoryValidator ().validateAnnotatedMethod (beforeClass );
83
+ FrameworkMethod method = new FrameworkMethod ( CategoryTest .class .getMethod ("methodWithCategory" ) );
84
+ List <Exception > errors = new CategoryValidator ().validateAnnotatedMethod (method );
85
85
86
86
assertThat (errors .size (), is (0 ));
87
87
}
0 commit comments