package com.spotify.heroic.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.spotify.heroic.HeroicMappers;
import com.spotify.heroic.grammar.QueryParser;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

public class DurationTest {
    private ObjectMapper mapper = HeroicMappers.json(Mockito.mock(QueryParser.class));

    @Test
    public void testShorthandDurationSerializer() throws IOException {
        assertEquals(Duration.of(1, TimeUnit.MILLISECONDS),
            mapper.readValue("\"1ms\"", Duration.class));
        assertEquals(Duration.of(2, TimeUnit.MILLISECONDS),
            mapper.readValue("\"2ms\"", Duration.class));
        assertEquals(Duration.of(1, TimeUnit.SECONDS), mapper.readValue("\"1s\"", Duration.class));
        assertEquals(Duration.of(1, TimeUnit.MINUTES), mapper.readValue("\"1m\"", Duration.class));
        assertEquals(Duration.of(1, TimeUnit.HOURS), mapper.readValue("\"1H\"", Duration.class));
        assertEquals(Duration.of(14, TimeUnit.DAYS), mapper.readValue("\"2w\"", Duration.class));
        assertEquals(Duration.of(3600, TimeUnit.MILLISECONDS),
            mapper.readValue("3600", Duration.class));
        assertEquals(Duration.of(3600, TimeUnit.MILLISECONDS),
            mapper.readValue("\"3600\"", Duration.class));
    }

    @Test
    public void testFallbackDurationSerializer() throws IOException {
        final Duration reference = Duration.of(1, TimeUnit.MICROSECONDS);
        final String value = mapper.writeValueAsString(reference);
        assertEquals(reference, mapper.readValue(value, Duration.class));
    }
}

@@ -165,24 +165,73 @@
 ueryParser;%0A
+import com.spotify.heroic.test.FakeModuleLoader;%0A
 import org.j
@@ -449,58 +449,48 @@
 r = 
-HeroicMappers.json(Mockito.mock(QueryParser.class)
+FakeModuleLoader.builder().build().json(
 );%0A%0A

switch DurationTest to FakeModuleLoader