package com.github.dnault.therapi.core.example;

import static org.junit.Assert.assertEquals;

import com.github.dnault.therapi.core.MethodRegistry;
import com.github.dnault.therapi.core.internal.JacksonHelper;
import com.github.dnault.therapi.example.CalculatorServiceImpl;
import org.junit.Test;

public class CalculatorServiceTest {
    MethodRegistry context = new MethodRegistry(JacksonHelper.newLenientObjectMapper());

    {
        context.scan(new CalculatorServiceImpl());
    }


    @Test
    public void multiplyFractions() throws Exception {
        check("calculator.multiplyFractions", "[[{numerator:2, denominator:3},{numerator:4, denominator:5}]]", "{numerator:8, denominator:15}");
    }

    protected void check(String methodName, String args, String expectedResult) throws Exception {
        assertEquals(context.getObjectMapper().readTree(expectedResult), context.invoke(methodName, context.getObjectMapper().readTree(args)));
    }
}

@@ -46,54 +46,8 @@
 e;%0A%0A
-import static org.junit.Assert.assertEquals;%0A%0A
 impo
@@ -80,16 +80,24 @@
 pi.core.
+Abstract
 MethodRe
@@ -106,70 +106,12 @@
 stry
-;%0Aimport com.github.dnault.therapi.core.internal.JacksonHelper
+Test
 ;%0Aim
@@ -172,16 +172,41 @@
 ceImpl;%0A
+import org.junit.Before;%0A
 import o
@@ -260,103 +260,80 @@
 est 
-%7B%0A    MethodRegistry context = new MethodRegistry(JacksonHelper.newLenientObjectMapper());%0A%0A   
+extends AbstractMethodRegistryTest %7B%0A    @Before%0A    public void setup()
  %7B%0A 
@@ -339,23 +339,24 @@
         
-context
+registry
 .scan(ne
@@ -390,17 +390,16 @@
 %0A    %7D%0A%0A
-%0A
     @Tes
@@ -609,257 +609,7 @@
    %7D
-%0A%0A    protected void check(String methodName, String args, String expectedResult) throws Exception %7B%0A        assertEquals(context.getObjectMapper().readTree(expectedResult), context.invoke(methodName, context.getObjectMapper().readTree(args)));%0A    %7D
 %0A%7D%0A

clean up example service test