|
| 1 | +/** |
| 2 | + * Copyright 2000-2025 Vaadin Ltd. |
| 3 | + * |
| 4 | + * This program is available under Vaadin Commercial License and Service Terms. |
| 5 | + * |
| 6 | + * See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full |
| 7 | + * license. |
| 8 | + */ |
| 9 | +package com.vaadin.flow.component.charts; |
| 10 | + |
| 11 | +import org.junit.Assert; |
| 12 | +import org.junit.Before; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 16 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 17 | +import com.vaadin.flow.component.charts.model.Labels; |
| 18 | +import com.vaadin.flow.component.charts.util.ChartSerialization; |
| 19 | + |
| 20 | +public class LabelsSerializationTest { |
| 21 | + |
| 22 | + private ObjectMapper objectMapper; |
| 23 | + |
| 24 | + @Before |
| 25 | + public void setUp() { |
| 26 | + objectMapper = ChartSerialization.createObjectMapper(); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testRotation_isParsableAsNumber_serializedAsNumber() |
| 31 | + throws JsonProcessingException { |
| 32 | + Labels labels = new Labels(); |
| 33 | + labels.setRotation("90"); |
| 34 | + String json = objectMapper.writeValueAsString(labels); |
| 35 | + Assert.assertTrue("Rotation should be serialized as a number", |
| 36 | + json.contains("\"rotation\":90.0")); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testRotation_isNotParsableAsNumber_serializedAsString() |
| 41 | + throws JsonProcessingException { |
| 42 | + Labels labels = new Labels(); |
| 43 | + labels.setRotation("auto"); |
| 44 | + String json = objectMapper.writeValueAsString(labels); |
| 45 | + Assert.assertTrue("Rotation should be serialized as a string", |
| 46 | + json.contains("\"rotation\":\"auto\"")); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testRotation_isNull_notSerialized() |
| 51 | + throws JsonProcessingException { |
| 52 | + Labels labels = new Labels(); |
| 53 | + labels.setRotation((String) null); |
| 54 | + String json = objectMapper.writeValueAsString(labels); |
| 55 | + Assert.assertFalse("Rotation should not be serialized", |
| 56 | + json.contains("\"rotation\"")); |
| 57 | + } |
| 58 | +} |
0 commit comments