1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png.chunks;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import org.apache.commons.imaging.ImagingException;
23 import org.junit.jupiter.api.Test;
24
25 public class PngChunkScalTest {
26 private static final double delta = 0.001;
27 private static final int chunkType = 1933787468;
28
29 @Test
30 public void testConstruct_InvalidDblValue() {
31 assertThrows(ImagingException.class, () -> new PngChunkScal(10, chunkType, 0, new byte[] { 2, 65, 46, 48, 49, 0, 48, 46, 48, 50 }));
32 }
33
34 @Test
35 public void testConstruct_InvalidUnitSpecifier() {
36 assertThrows(ImagingException.class, () -> new PngChunkScal(10, chunkType, 0, new byte[] { 3, 48, 46, 48, 49, 0, 48, 46, 48, 50 }));
37 }
38
39 @Test
40 public void testConstruct_MissingSeparator() {
41 assertThrows(ImagingException.class, () -> new PngChunkScal(9, chunkType, 0, new byte[] { 1, 48, 46, 48, 49, 48, 46, 48, 50 }));
42 }
43
44 @Test
45 public void testConstruct_MissingXValue() {
46 assertThrows(ImagingException.class, () -> new PngChunkScal(2, chunkType, 0, new byte[] { 2, 0 }));
47 }
48
49 @Test
50 public void testConstruct_MissingYValue() {
51 assertThrows(ImagingException.class, () -> new PngChunkScal(6, chunkType, 0, new byte[] { 2, 48, 46, 48, 49, 0 }));
52 }
53
54 @Test
55 public void testConstructMeters() throws ImagingException {
56 final PngChunkScal pngChunkScal = new PngChunkScal(10, chunkType, 0, new byte[] { 1, 48, 46, 48, 49, 0, 48, 46, 48, 50 });
57
58 assertEquals(pngChunkScal.getUnitSpecifier(), 1);
59 assertEquals(pngChunkScal.getUnitsPerPixelXAxis(), 0.01, delta);
60 assertEquals(pngChunkScal.getUnitsPerPixelYAxis(), 0.02, delta);
61 }
62
63 @Test
64 public void testConstructRadians() throws ImagingException {
65 final PngChunkScal pngChunkScal = new PngChunkScal(10, chunkType, 0, new byte[] { 2, 48, 46, 48, 49, 0, 48, 46, 48, 50 });
66
67 assertEquals(pngChunkScal.getUnitSpecifier(), 2);
68 assertEquals(pngChunkScal.getUnitsPerPixelXAxis(), 0.01, delta);
69 assertEquals(pngChunkScal.getUnitsPerPixelYAxis(), 0.02, delta);
70 }
71 }