package openfoodfacts.github.scrachx.openfood.models;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author herau
 */
public class NutrientLevelsTest {

    private NutrientLevels nutrientLevels = new NutrientLevels();

    @Before
    public void setUp(){
        nutrientLevels.setFat(NutrimentLevel.LOW);
        nutrientLevels.setSalt(NutrimentLevel.MODERATE);
        nutrientLevels.setSaturatedFat(NutrimentLevel.HIGH);
        nutrientLevels.setSugars(NutrimentLevel.MODERATE);
    }

    @Test
    public void jsonSerialization_ok() {
        JsonNode jsonNode = new ObjectMapper().valueToTree(nutrientLevels);

        assertEquals(jsonNode.get("fat").asText(), NutrimentLevel.LOW.toString());
        assertEquals(jsonNode.get("salt").asText(), NutrimentLevel.MODERATE.toString());
        assertEquals(jsonNode.get("saturated-fat").asText(), NutrimentLevel.HIGH.toString());
        assertEquals(jsonNode.get("sugars").asText(), NutrimentLevel.MODERATE.toString());
    }

    @Test
    public void jsonDeserialization_ok() throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        NutrientLevels nutrientLevelsResult = objectMapper.treeToValue(
                objectMapper.createObjectNode()
                .put("fat", "low")
                .put("salt", "moderate")
                .put("saturated-fat", "high")
                .put("sugars", "moderate"), NutrientLevels.class);

        assertEquals(nutrientLevels.getFat(), nutrientLevelsResult.getFat());
        assertEquals(nutrientLevels.getSugars(), nutrientLevelsResult.getSugars());
        assertEquals(nutrientLevels.getSaturatedFat(), nutrientLevelsResult.getSaturatedFat());
        assertEquals(nutrientLevels.getSalt(), nutrientLevelsResult.getSalt());
    }
}
@@ -349,31 +349,8 @@
 vels
- = new NutrientLevels()
 ;%0A%0A 
@@ -385,16 +385,63 @@
 etUp()%7B%0A
+        nutrientLevels = new NutrientLevels();%0A
         

Fix for NutrientLevelTest