Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jun 15, 2017
1 parent c5c6a52 commit 31ee45b
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Test;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand All @@ -31,32 +32,35 @@
*/
public class JsonComponentModuleTests {

private AnnotationConfigApplicationContext context;

@After
public void closeContext() {
if (this.context != null) {
this.context.close();
}
}

@Test
public void moduleShouldRegisterSerializers() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
JsonComponentModule.class, OnlySerializer.class);
JsonComponentModule module = context.getBean(JsonComponentModule.class);
load(OnlySerializer.class);
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
assertSerialize(module);
context.close();
}

@Test
public void moduleShouldRegisterDeserializers() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
JsonComponentModule.class, OnlyDeserializer.class);
JsonComponentModule module = context.getBean(JsonComponentModule.class);
load(OnlyDeserializer.class);
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
assertDeserialize(module);
context.close();
}

@Test
public void moduleShouldRegisterInnerClasses() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
JsonComponentModule.class, NameAndAgeJsonComponent.class);
JsonComponentModule module = context.getBean(JsonComponentModule.class);
load(NameAndAgeJsonComponent.class);
JsonComponentModule module = this.context.getBean(JsonComponentModule.class);
assertSerialize(module);
assertDeserialize(module);
context.close();
}

@Test
Expand All @@ -68,6 +72,14 @@ public void moduleShouldAllowInnerAbstractClasses() throws Exception {
context.close();
}

private void load(Class<?>... configs) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(configs);
ctx.register(JsonComponentModule.class);
ctx.refresh();
this.context = ctx;
}

private void assertSerialize(Module module) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
Expand Down

0 comments on commit 31ee45b

Please sign in to comment.