package org.sagebionetworks.bridge.models.studies;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;

import org.sagebionetworks.bridge.json.BridgeObjectMapper;

public class MimeTypeTest {

    @Test
    public void canDeserializeAutogeneratedMimeTypes() throws Exception {
        MimeType deser = BridgeObjectMapper.get().readValue("\"pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"application/pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"HTML\"", MimeType.class);
        assertEquals(MimeType.HTML, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"TEXT/PLAIN\"", MimeType.class);
        assertEquals(MimeType.TEXT, deser);
    }
    
    @Test
    public void nullDoesNotBreakDeserialization() throws Exception {
        assertNull(BridgeObjectMapper.get().readValue("\"\"", MimeType.class));
    }
}

package org.sagebionetworks.bridge.models.studies;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;

import org.sagebionetworks.bridge.json.BridgeObjectMapper;

import com.fasterxml.jackson.databind.ObjectMapper;

public class MimeTypeTest {

    @Test
    public void canDeserializeAutogeneratedMimeTypes() throws Exception {
        ObjectMapper mapper = BridgeObjectMapper.get();
        
        MimeType deser = mapper.readValue("\"pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = mapper.readValue("\"application/pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = mapper.readValue("\"HTML\"", MimeType.class);
        assertEquals(MimeType.HTML, deser);
        
        deser = mapper.readValue("\"TEXT/PLAIN\"", MimeType.class);
        assertEquals(MimeType.TEXT, deser);
    }
    
    /**
     * Test that serialization works with a normal ObjectMapper, not just BridgeObjectMapper.
     */
    @Test
    public void canSerializeWithNormalObjectMaper() throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        
        String json = mapper.writeValueAsString(MimeType.HTML);
        
        MimeType type = mapper.readValue(json, MimeType.class);
        
        assertEquals(MimeType.HTML, type);
    }
    
    @Test
    public void nullDoesNotBreakDeserialization() throws Exception {
        assertNull(BridgeObjectMapper.get().readValue("\"\"", MimeType.class));
    }
}

Test with ObjectMapper.