1
1
/*
2
- * Copyright 2012-2016 the original author or authors.
2
+ * Copyright 2012-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import com .fasterxml .jackson .databind .Module ;
20
20
import com .fasterxml .jackson .databind .ObjectMapper ;
21
+ import org .junit .After ;
21
22
import org .junit .Test ;
22
23
23
24
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
31
32
*/
32
33
public class JsonComponentModuleTests {
33
34
35
+ private AnnotationConfigApplicationContext context ;
36
+
37
+ @ After
38
+ public void closeContext () {
39
+ if (this .context != null ) {
40
+ this .context .close ();
41
+ }
42
+ }
43
+
34
44
@ Test
35
45
public void moduleShouldRegisterSerializers () throws Exception {
36
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
37
- JsonComponentModule .class , OnlySerializer .class );
38
- JsonComponentModule module = context .getBean (JsonComponentModule .class );
46
+ load (OnlySerializer .class );
47
+ JsonComponentModule module = this .context .getBean (JsonComponentModule .class );
39
48
assertSerialize (module );
40
- context .close ();
41
49
}
42
50
43
51
@ Test
44
52
public void moduleShouldRegisterDeserializers () throws Exception {
45
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
46
- JsonComponentModule .class , OnlyDeserializer .class );
47
- JsonComponentModule module = context .getBean (JsonComponentModule .class );
53
+ load (OnlyDeserializer .class );
54
+ JsonComponentModule module = this .context .getBean (JsonComponentModule .class );
48
55
assertDeserialize (module );
49
- context .close ();
50
56
}
51
57
52
58
@ Test
53
59
public void moduleShouldRegisterInnerClasses () throws Exception {
60
+ load (NameAndAgeJsonComponent .class );
61
+ JsonComponentModule module = this .context .getBean (JsonComponentModule .class );
62
+ assertSerialize (module );
63
+ assertDeserialize (module );
64
+ }
65
+
66
+ @ Test
67
+ public void moduleShouldAllowInnerAbstractClasses () throws Exception {
54
68
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
55
- JsonComponentModule .class , NameAndAgeJsonComponent .class );
69
+ JsonComponentModule .class , ComponentWithInnerAbstractClass .class );
56
70
JsonComponentModule module = context .getBean (JsonComponentModule .class );
57
71
assertSerialize (module );
58
- assertDeserialize (module );
59
72
context .close ();
60
73
}
61
74
75
+ private void load (Class <?>... configs ) {
76
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
77
+ ctx .register (configs );
78
+ ctx .register (JsonComponentModule .class );
79
+ ctx .refresh ();
80
+ this .context = ctx ;
81
+ }
82
+
62
83
private void assertSerialize (Module module ) throws Exception {
63
84
ObjectMapper mapper = new ObjectMapper ();
64
85
mapper .registerModule (module );
@@ -85,4 +106,15 @@ static class OnlyDeserializer extends NameAndAgeJsonComponent.Deserializer {
85
106
86
107
}
87
108
109
+ @ JsonComponent
110
+ static class ComponentWithInnerAbstractClass {
111
+
112
+ private static abstract class AbstractSerializer extends NameAndAgeJsonComponent .Serializer {
113
+
114
+ }
115
+
116
+ static class ConcreteSerializer extends AbstractSerializer {
117
+
118
+ }
119
+ }
88
120
}
0 commit comments