1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.beanutils2.converters;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import java.awt.Dimension;
25
26 import org.apache.commons.beanutils2.ConversionException;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34
35 public class DimensionConverterTest {
36
37 private DimensionConverter converter;
38
39 @BeforeEach
40 public void before() {
41 converter = new DimensionConverter();
42 }
43
44 @Test
45 public void testConvertingDimension() {
46 final Dimension expected = new Dimension(1920, 1080);
47 final Dimension actual = converter.convert(Dimension.class, "1920x1080");
48
49 assertEquals(expected, actual);
50 }
51
52 @Test
53 public void testConvertingSquare() {
54 final Dimension expected = new Dimension(512, 512);
55 final Dimension actual = converter.convert(Dimension.class, "512");
56
57 assertEquals(expected, actual);
58 }
59
60 @Test
61 public void testInvalidDimensions() {
62 assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "512n512"));
63 }
64
65 @Test
66 public void testInvalidNumberFormatException() {
67 assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "3000000000x100"));
68 }
69
70 @Test
71 public void testNegativeDimension() {
72 assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "-512x512"));
73 }
74 }