Changeset 36194 in osm for applications/editors/josm/plugins/MicrosoftStreetside/test
- Timestamp:
- 2023-11-14T23:40:50+01:00 (14 months ago)
- Location:
- applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideAbstractImageTest.java
r36064 r36194 9 9 10 10 class StreetsideAbstractImageTest { 11 @Test12 void testIsModified() {13 StreetsideImage img = new StreetsideImage("key___________________", new LatLon(0, 0), 0);14 assertFalse(img.isModified());15 img.turn(1e-4);16 img.stopMoving();17 assertTrue(img.isModified());18 img.turn(-1e-4);19 img.stopMoving();20 assertFalse(img.isModified());21 img.move(1e-4, 1e-4);22 img.stopMoving();23 assertTrue(img.isModified());24 img.move(-1e-4, -1e-4);25 img.stopMoving();26 assertFalse(img.isModified());27 }11 @Test 12 void testIsModified() { 13 StreetsideImage img = new StreetsideImage("key___________________", new LatLon(0, 0), 0); 14 assertFalse(img.isModified()); 15 img.turn(1e-4); 16 img.stopMoving(); 17 assertTrue(img.isModified()); 18 img.turn(-1e-4); 19 img.stopMoving(); 20 assertFalse(img.isModified()); 21 img.move(1e-4, 1e-4); 22 img.stopMoving(); 23 assertTrue(img.isModified()); 24 img.move(-1e-4, -1e-4); 25 img.stopMoving(); 26 assertFalse(img.isModified()); 27 } 28 28 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideDataTest.java
r36193 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 13 12 import org.junit.jupiter.api.Disabled; 14 13 import org.junit.jupiter.api.Test; 15 import org.junit.jupiter.api.condition.DisabledIf;16 14 import org.openstreetmap.josm.data.coor.LatLon; 17 15 import org.openstreetmap.josm.testutils.annotations.Main; … … 26 24 class StreetsideDataTest { 27 25 28 private StreetsideData data;29 private StreetsideImage img1;30 private StreetsideImage img2;31 private StreetsideImage img3;32 private StreetsideImage img4;26 private StreetsideData data; 27 private StreetsideImage img1; 28 private StreetsideImage img2; 29 private StreetsideImage img3; 30 private StreetsideImage img4; 33 31 34 /**35 * Creates a sample {@link StreetsideData} objects, 4 {@link StreetsideImage}36 * objects and a {@link StreetsideSequence} object.37 */38 @BeforeEach39 public void setUp() {40 img1 = new StreetsideImage("id1__________________", new LatLon(0.1, 0.1), 90);41 img2 = new StreetsideImage("id2__________________", new LatLon(0.2, 0.2), 90);42 img3 = new StreetsideImage("id3__________________", new LatLon(0.3, 0.3), 90);43 img4 = new StreetsideImage("id4__________________", new LatLon(0.4, 0.4), 90);44 final StreetsideSequence seq = new StreetsideSequence();32 /** 33 * Creates a sample {@link StreetsideData} objects, 4 {@link StreetsideImage} 34 * objects and a {@link StreetsideSequence} object. 35 */ 36 @BeforeEach 37 public void setUp() { 38 img1 = new StreetsideImage("id1__________________", new LatLon(0.1, 0.1), 90); 39 img2 = new StreetsideImage("id2__________________", new LatLon(0.2, 0.2), 90); 40 img3 = new StreetsideImage("id3__________________", new LatLon(0.3, 0.3), 90); 41 img4 = new StreetsideImage("id4__________________", new LatLon(0.4, 0.4), 90); 42 final StreetsideSequence seq = new StreetsideSequence(); 45 43 46 seq.add(Arrays.asList(img1, img2, img3, img4));44 seq.add(Arrays.asList(img1, img2, img3, img4)); 47 45 48 data = new StreetsideData();49 data.addAll(new ConcurrentSkipListSet<>(seq.getImages()));50 }46 data = new StreetsideData(); 47 data.addAll(new ConcurrentSkipListSet<>(seq.getImages())); 48 } 51 49 52 /**53 * Tests the addition of new images. If a second image with the same key as54 * another one in the database, the one that is being added should be ignored.55 */56 @Test57 void testAdd() {58 data = new StreetsideData();59 assertEquals(0, data.getImages().size());60 data.add(img1);61 assertEquals(1, data.getImages().size());62 data.add(img1);63 assertEquals(1, data.getImages().size());64 data.addAll(new ConcurrentSkipListSet<>(Arrays.asList(img2, img3)));65 assertEquals(3, data.getImages().size());66 data.addAll(new ConcurrentSkipListSet<>(Arrays.asList(img3, img4)));67 assertEquals(4, data.getImages().size());68 }50 /** 51 * Tests the addition of new images. If a second image with the same key as 52 * another one in the database, the one that is being added should be ignored. 53 */ 54 @Test 55 void testAdd() { 56 data = new StreetsideData(); 57 assertEquals(0, data.getImages().size()); 58 data.add(img1); 59 assertEquals(1, data.getImages().size()); 60 data.add(img1); 61 assertEquals(1, data.getImages().size()); 62 data.addAll(new ConcurrentSkipListSet<>(Arrays.asList(img2, img3))); 63 assertEquals(3, data.getImages().size()); 64 data.addAll(new ConcurrentSkipListSet<>(Arrays.asList(img3, img4))); 65 assertEquals(4, data.getImages().size()); 66 } 69 67 70 /**71 * Test that the size is properly calculated.72 */73 @Test74 void testSize() {75 assertEquals(4, data.getImages().size());76 data.add(new StreetsideImage("id5__________________", new LatLon(0.1, 0.1), 90));77 assertEquals(5, data.getImages().size());78 }68 /** 69 * Test that the size is properly calculated. 70 */ 71 @Test 72 void testSize() { 73 assertEquals(4, data.getImages().size()); 74 data.add(new StreetsideImage("id5__________________", new LatLon(0.1, 0.1), 90)); 75 assertEquals(5, data.getImages().size()); 76 } 79 77 80 /**81 * Test the {@link StreetsideData#setHighlightedImage(StreetsideAbstractImage)}82 * and {@link StreetsideData#getHighlightedImage()} methods.83 */84 @Test85 void testHighlight() {86 data.setHighlightedImage(img1);87 assertEquals(img1, data.getHighlightedImage());78 /** 79 * Test the {@link StreetsideData#setHighlightedImage(StreetsideAbstractImage)} 80 * and {@link StreetsideData#getHighlightedImage()} methods. 81 */ 82 @Test 83 void testHighlight() { 84 data.setHighlightedImage(img1); 85 assertEquals(img1, data.getHighlightedImage()); 88 86 89 data.setHighlightedImage(null);90 assertNull(data.getHighlightedImage());91 }87 data.setHighlightedImage(null); 88 assertNull(data.getHighlightedImage()); 89 } 92 90 93 /**94 * Tests the selection of images.95 */96 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form")97 @Test98 void testSelect() {99 data.setSelectedImage(img1);100 assertEquals(img1, data.getSelectedImage());91 /** 92 * Tests the selection of images. 93 */ 94 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form") 95 @Test 96 void testSelect() { 97 data.setSelectedImage(img1); 98 assertEquals(img1, data.getSelectedImage()); 101 99 102 data.setSelectedImage(img4);103 assertEquals(img4, data.getSelectedImage());100 data.setSelectedImage(img4); 101 assertEquals(img4, data.getSelectedImage()); 104 102 105 data.setSelectedImage(null);106 assertNull(data.getSelectedImage());107 }103 data.setSelectedImage(null); 104 assertNull(data.getSelectedImage()); 105 } 108 106 109 /**110 * Tests the {@link StreetsideData#selectNext()} and111 * {@link StreetsideData#selectPrevious()} methods.112 */113 @Test114 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form")115 void testNextAndPrevious() {116 data.setSelectedImage(img1);107 /** 108 * Tests the {@link StreetsideData#selectNext()} and 109 * {@link StreetsideData#selectPrevious()} methods. 110 */ 111 @Test 112 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form") 113 void testNextAndPrevious() { 114 data.setSelectedImage(img1); 117 115 118 data.selectNext();119 assertEquals(img2, data.getSelectedImage());120 data.selectNext();121 assertEquals(img3, data.getSelectedImage());122 data.selectPrevious();123 assertEquals(img2, data.getSelectedImage());116 data.selectNext(); 117 assertEquals(img2, data.getSelectedImage()); 118 data.selectNext(); 119 assertEquals(img3, data.getSelectedImage()); 120 data.selectPrevious(); 121 assertEquals(img2, data.getSelectedImage()); 124 122 125 data.setSelectedImage(null);126 }123 data.setSelectedImage(null); 124 } 127 125 128 @Disabled("Someone decided to not throw an IllegalStateException. No clue why.")129 @Test130 void testNextOfNullImg() {131 data.setSelectedImage(null);132 assertThrows(IllegalStateException.class, data::selectNext);133 }126 @Disabled("Someone decided to not throw an IllegalStateException. No clue why.") 127 @Test 128 void testNextOfNullImg() { 129 data.setSelectedImage(null); 130 assertThrows(IllegalStateException.class, data::selectNext); 131 } 134 132 135 @Disabled("Someone decided to not throw an IllegalStateException. No clue why.")136 @Test137 void testPreviousOfNullImg() {138 data.setSelectedImage(null);139 assertThrows(IllegalStateException.class, data::selectPrevious);140 }133 @Disabled("Someone decided to not throw an IllegalStateException. No clue why.") 134 @Test 135 void testPreviousOfNullImg() { 136 data.setSelectedImage(null); 137 assertThrows(IllegalStateException.class, data::selectPrevious); 138 } 141 139 142 /**143 * Test the multiselection of images. When a new image is selected, the144 * multiselected List should reset.145 */146 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form")147 @Test148 void testMultiSelect() {149 assertEquals(0, data.getMultiSelectedImages().size());150 data.setSelectedImage(img1);151 assertEquals(1, data.getMultiSelectedImages().size());152 data.addMultiSelectedImage(img2);153 assertEquals(2, data.getMultiSelectedImages().size());154 data.setSelectedImage(img1);155 assertEquals(1, data.getMultiSelectedImages().size());156 }140 /** 141 * Test the multiselection of images. When a new image is selected, the 142 * multiselected List should reset. 143 */ 144 @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form") 145 @Test 146 void testMultiSelect() { 147 assertEquals(0, data.getMultiSelectedImages().size()); 148 data.setSelectedImage(img1); 149 assertEquals(1, data.getMultiSelectedImages().size()); 150 data.addMultiSelectedImage(img2); 151 assertEquals(2, data.getMultiSelectedImages().size()); 152 data.setSelectedImage(img1); 153 assertEquals(1, data.getMultiSelectedImages().size()); 154 } 157 155 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideLayerTest.java
r36193 r36194 24 24 @Projection 25 25 class StreetsideLayerTest { 26 private static Layer getDummyLayer() { 27 return ImageryLayer.create(new ImageryInfo("dummy", "https://example.org")); 28 } 29 30 @Test 31 void testGetIcon() { 32 assertNotNull(StreetsideLayer.getInstance().getIcon()); 33 } 34 35 @Test 36 void testIsMergable() { 37 assertFalse(StreetsideLayer.getInstance().isMergable(getDummyLayer())); 38 } 39 40 @Test 41 void testMergeFrom() { 42 StreetsideLayer layer = StreetsideLayer.getInstance(); 43 Layer dummyLayer = getDummyLayer(); 44 assertThrows(UnsupportedOperationException.class, () -> layer.mergeFrom(dummyLayer)); 45 } 46 47 @Test 48 void testSetVisible() { 49 StreetsideLayer.getInstance().getData().add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0)); 50 StreetsideLayer.getInstance().getData().add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0)); 51 StreetsideImage invisibleImage = new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0); 52 invisibleImage.setVisible(false); 53 StreetsideLayer.getInstance().getData().add(invisibleImage); 54 55 StreetsideLayer.getInstance().setVisible(false); 56 for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) { 57 assertFalse(img.isVisible()); 26 private static Layer getDummyLayer() { 27 return ImageryLayer.create(new ImageryInfo("dummy", "https://example.org")); 58 28 } 59 29 30 @Test 31 void testGetIcon() { 32 assertNotNull(StreetsideLayer.getInstance().getIcon()); 33 } 60 34 61 StreetsideLayer.getInstance().setVisible(true);62 for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) {63 assertTrue(img.isVisible());35 @Test 36 void testIsMergable() { 37 assertFalse(StreetsideLayer.getInstance().isMergable(getDummyLayer())); 64 38 } 65 }66 39 67 @Test68 void testGetInfoComponent() {69 Object comp = StreetsideLayer.getInstance().getInfoComponent();70 assertInstanceOf(String.class, comp);71 assertTrue(((String) comp).length() >= 9);72 }40 @Test 41 void testMergeFrom() { 42 StreetsideLayer layer = StreetsideLayer.getInstance(); 43 Layer dummyLayer = getDummyLayer(); 44 assertThrows(UnsupportedOperationException.class, () -> layer.mergeFrom(dummyLayer)); 45 } 73 46 74 @DisabledIf(value = "java.awt.GraphicsEnvironment#isHeadless", disabledReason = "Listener for destruction is only registered in non-headless environments") 75 @Test 76 void testClearInstance() { 77 StreetsideLayer.getInstance(); 78 assertTrue(StreetsideLayer.hasInstance()); 79 JOSMTestRules.cleanLayerEnvironment(); 80 assertFalse(StreetsideLayer.hasInstance()); 81 StreetsideLayer.getInstance(); 82 assertTrue(StreetsideLayer.hasInstance()); 83 } 47 @Test 48 void testSetVisible() { 49 StreetsideLayer.getInstance().getData() 50 .add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0)); 51 StreetsideLayer.getInstance().getData() 52 .add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0)); 53 StreetsideImage invisibleImage = new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0); 54 invisibleImage.setVisible(false); 55 StreetsideLayer.getInstance().getData().add(invisibleImage); 56 57 StreetsideLayer.getInstance().setVisible(false); 58 for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) { 59 assertFalse(img.isVisible()); 60 } 61 62 StreetsideLayer.getInstance().setVisible(true); 63 for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) { 64 assertTrue(img.isVisible()); 65 } 66 } 67 68 @Test 69 void testGetInfoComponent() { 70 Object comp = StreetsideLayer.getInstance().getInfoComponent(); 71 assertInstanceOf(String.class, comp); 72 assertTrue(((String) comp).length() >= 9); 73 } 74 75 @DisabledIf(value = "java.awt.GraphicsEnvironment#isHeadless", disabledReason = "Listener for destruction is only registered in non-headless environments") 76 @Test 77 void testClearInstance() { 78 StreetsideLayer.getInstance(); 79 assertTrue(StreetsideLayer.hasInstance()); 80 JOSMTestRules.cleanLayerEnvironment(); 81 assertFalse(StreetsideLayer.hasInstance()); 82 StreetsideLayer.getInstance(); 83 assertTrue(StreetsideLayer.hasInstance()); 84 } 84 85 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideSequenceTest.java
r36064 r36194 20 20 class StreetsideSequenceTest { 21 21 22 private final StreetsideImage img1 = new StreetsideImage("key1", new LatLon(0.1, 0.1), 90);23 private final StreetsideImage img2 = new StreetsideImage("key2", new LatLon(0.2, 0.2), 90);24 private final StreetsideImage img3 = new StreetsideImage("key3", new LatLon(0.3, 0.3), 90);25 private final StreetsideImage img4 = new StreetsideImage("key4", new LatLon(0.4, 0.4), 90);26 private final StreetsideImage imgWithoutSeq = new StreetsideImage("key5", new LatLon(0.5, 0.5), 90);27 private final StreetsideSequence seq = new StreetsideSequence();22 private final StreetsideImage img1 = new StreetsideImage("key1", new LatLon(0.1, 0.1), 90); 23 private final StreetsideImage img2 = new StreetsideImage("key2", new LatLon(0.2, 0.2), 90); 24 private final StreetsideImage img3 = new StreetsideImage("key3", new LatLon(0.3, 0.3), 90); 25 private final StreetsideImage img4 = new StreetsideImage("key4", new LatLon(0.4, 0.4), 90); 26 private final StreetsideImage imgWithoutSeq = new StreetsideImage("key5", new LatLon(0.5, 0.5), 90); 27 private final StreetsideSequence seq = new StreetsideSequence(); 28 28 29 /**30 * Creates 4 {@link StreetsideImage} objects and puts them in a31 * {@link StreetsideSequence} object.32 */33 @BeforeEach34 public void setUp() {35 seq.add(Arrays.asList(img1, img2, img3, img4));36 }29 /** 30 * Creates 4 {@link StreetsideImage} objects and puts them in a 31 * {@link StreetsideSequence} object. 32 */ 33 @BeforeEach 34 public void setUp() { 35 seq.add(Arrays.asList(img1, img2, img3, img4)); 36 } 37 37 38 /**39 * Tests the {@link StreetsideSequence#next(StreetsideAbstractImage)} and40 * {@link StreetsideSequence#previous(StreetsideAbstractImage)}.41 */42 @Test43 void testNextAndPrevious() {44 assertEquals(img2, img1.next());45 assertEquals(img1, img2.previous());46 assertEquals(img3, img2.next());47 assertEquals(img2, img3.previous());48 assertEquals(img4, img3.next());49 assertEquals(img3, img4.previous());38 /** 39 * Tests the {@link StreetsideSequence#next(StreetsideAbstractImage)} and 40 * {@link StreetsideSequence#previous(StreetsideAbstractImage)}. 41 */ 42 @Test 43 void testNextAndPrevious() { 44 assertEquals(img2, img1.next()); 45 assertEquals(img1, img2.previous()); 46 assertEquals(img3, img2.next()); 47 assertEquals(img2, img3.previous()); 48 assertEquals(img4, img3.next()); 49 assertEquals(img3, img4.previous()); 50 50 51 assertNull(img4.next()); 52 assertNull(img1.previous()); 51 53 52 assertNull(img4.next());53 assertNull(img1.previous());54 assertNull(imgWithoutSeq.next()); 55 assertNull(imgWithoutSeq.previous()); 54 56 55 assertNull(imgWithoutSeq.next()); 56 assertNull(imgWithoutSeq.previous()); 57 // Test IllegalArgumentException when asking for the next image of an image 58 // that is not in the sequence. 59 assertThrows(IllegalArgumentException.class, () -> seq.next(imgWithoutSeq)); 57 60 58 // Test IllegalArgumentException when asking for the next image of an image 59 // that is not in the sequence. 60 assertThrows(IllegalArgumentException.class, () -> seq.next(imgWithoutSeq)); 61 62 // Test IllegalArgumentException when asking for the previous image of an 63 // image that is not in the sequence. 64 assertThrows(IllegalArgumentException.class, () -> seq.previous(imgWithoutSeq)); 65 } 61 // Test IllegalArgumentException when asking for the previous image of an 62 // image that is not in the sequence. 63 assertThrows(IllegalArgumentException.class, () -> seq.previous(imgWithoutSeq)); 64 } 66 65 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cache/CachesTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.cache; 3 4 3 5 4 import org.junit.jupiter.api.Test; … … 8 7 class CachesTest { 9 8 10 @Test11 void testUtilityClass() {12 TestUtil.testUtilityClass(Caches.class);13 }9 @Test 10 void testUtilityClass() { 11 TestUtil.testUtilityClass(Caches.class); 12 } 14 13 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cache/StreetsideCacheTest.java
r36064 r36194 13 13 class StreetsideCacheTest { 14 14 15 @Test16 void testCache() {17 StreetsideCache cache = new StreetsideCache("00000", Type.FULL_IMAGE);18 assertNotNull(cache.getUrl());19 assertNotNull(cache.getCacheKey());15 @Test 16 void testCache() { 17 StreetsideCache cache = new StreetsideCache("00000", Type.FULL_IMAGE); 18 assertNotNull(cache.getUrl()); 19 assertNotNull(cache.getCacheKey()); 20 20 21 assertFalse(cache.isObjectLoadable());21 assertFalse(cache.isObjectLoadable()); 22 22 23 cache = new StreetsideCache("00000", Type.THUMBNAIL);24 assertNotNull(cache.getCacheKey());25 assertNotNull(cache.getUrl());23 cache = new StreetsideCache("00000", Type.THUMBNAIL); 24 assertNotNull(cache.getCacheKey()); 25 assertNotNull(cache.getUrl()); 26 26 27 cache = new StreetsideCache(null, null);28 assertNull(cache.getCacheKey());29 assertNull(cache.getUrl());30 }27 cache = new StreetsideCache(null, null); 28 assertNull(cache.getCacheKey()); 29 assertNull(cache.getUrl()); 30 } 31 31 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/CubemapUtilsTest.java
r36064 r36194 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.streetside.cubemap; 2 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 9 9 class CubemapUtilsTest { 10 10 11 @Test12 void testConvertDecimal2Quaternary() {13 final long decimal0 = 680730040L;14 final long decimal1 = 680931568L;15 String res = CubemapUtils.convertDecimal2Quaternary(decimal0);16 assertEquals("220210301312320", res);17 res = CubemapUtils.convertDecimal2Quaternary(decimal1);18 assertEquals("220211203003300", res);19 }11 @Test 12 void testConvertDecimal2Quaternary() { 13 final long decimal0 = 680730040L; 14 final long decimal1 = 680931568L; 15 String res = CubemapUtils.convertDecimal2Quaternary(decimal0); 16 assertEquals("220210301312320", res); 17 res = CubemapUtils.convertDecimal2Quaternary(decimal1); 18 assertEquals("220211203003300", res); 19 } 20 20 21 @Test22 void testConvertQuaternary2Decimal() {23 final String quadKey0 = "220210301312320";24 final String quadKey1 = "220211203003300";25 String res = CubemapUtils.convertQuaternary2Decimal(quadKey0);26 assertEquals("680730040", res);27 res = CubemapUtils.convertQuaternary2Decimal(quadKey1);28 assertEquals("680931568", res);29 }21 @Test 22 void testConvertQuaternary2Decimal() { 23 final String quadKey0 = "220210301312320"; 24 final String quadKey1 = "220211203003300"; 25 String res = CubemapUtils.convertQuaternary2Decimal(quadKey0); 26 assertEquals("680730040", res); 27 res = CubemapUtils.convertQuaternary2Decimal(quadKey1); 28 assertEquals("680931568", res); 29 } 30 30 31 @Disabled32 @Test33 void testGetFaceNumberForCount() {34 String faceNrFront = CubemapUtils.getFaceNumberForCount(0);35 String faceNrRight = CubemapUtils.getFaceNumberForCount(1);36 String faceNrBack = CubemapUtils.getFaceNumberForCount(2);37 String faceNrLeft = CubemapUtils.getFaceNumberForCount(3);38 String faceNrUp = CubemapUtils.getFaceNumberForCount(4);39 String faceNrDown = CubemapUtils.getFaceNumberForCount(5);40 assertEquals(faceNrFront, "01");41 assertEquals(faceNrRight, "02");42 assertEquals(faceNrBack, "03");43 assertEquals(faceNrLeft, "10");44 assertEquals(faceNrUp, "11");45 assertEquals(faceNrDown, "12");46 }31 @Disabled 32 @Test 33 void testGetFaceNumberForCount() { 34 String faceNrFront = CubemapUtils.getFaceNumberForCount(0); 35 String faceNrRight = CubemapUtils.getFaceNumberForCount(1); 36 String faceNrBack = CubemapUtils.getFaceNumberForCount(2); 37 String faceNrLeft = CubemapUtils.getFaceNumberForCount(3); 38 String faceNrUp = CubemapUtils.getFaceNumberForCount(4); 39 String faceNrDown = CubemapUtils.getFaceNumberForCount(5); 40 assertEquals(faceNrFront, "01"); 41 assertEquals(faceNrRight, "02"); 42 assertEquals(faceNrBack, "03"); 43 assertEquals(faceNrLeft, "10"); 44 assertEquals(faceNrUp, "11"); 45 assertEquals(faceNrDown, "12"); 46 } 47 47 48 @Disabled49 @Test50 void testGetCount4FaceNumber() {51 int count4Front = CubemapUtils.getCount4FaceNumber("01");52 int count4Right = CubemapUtils.getCount4FaceNumber("02");53 int count4Back = CubemapUtils.getCount4FaceNumber("03");54 int count4Left = CubemapUtils.getCount4FaceNumber("10");55 int count4Up = CubemapUtils.getCount4FaceNumber("11");56 int count4Down = CubemapUtils.getCount4FaceNumber("12");57 assertEquals(count4Front, 0);58 assertEquals(count4Right, 1);59 assertEquals(count4Back, 2);60 assertEquals(count4Left, 3);61 assertEquals(count4Up, 4);62 assertEquals(count4Down, 5);63 }48 @Disabled 49 @Test 50 void testGetCount4FaceNumber() { 51 int count4Front = CubemapUtils.getCount4FaceNumber("01"); 52 int count4Right = CubemapUtils.getCount4FaceNumber("02"); 53 int count4Back = CubemapUtils.getCount4FaceNumber("03"); 54 int count4Left = CubemapUtils.getCount4FaceNumber("10"); 55 int count4Up = CubemapUtils.getCount4FaceNumber("11"); 56 int count4Down = CubemapUtils.getCount4FaceNumber("12"); 57 assertEquals(count4Front, 0); 58 assertEquals(count4Right, 1); 59 assertEquals(count4Back, 2); 60 assertEquals(count4Left, 3); 61 assertEquals(count4Up, 4); 62 assertEquals(count4Down, 5); 63 } 64 64 65 @Test66 void testConvertDoubleCountNrto16TileNr() {67 String x0y0 = CubemapUtils.convertDoubleCountNrto16TileNr("00");68 String x0y1 = CubemapUtils.convertDoubleCountNrto16TileNr("01");69 String x0y2 = CubemapUtils.convertDoubleCountNrto16TileNr("02");70 String x0y3 = CubemapUtils.convertDoubleCountNrto16TileNr("03");71 String x1y0 = CubemapUtils.convertDoubleCountNrto16TileNr("10");72 String x1y1 = CubemapUtils.convertDoubleCountNrto16TileNr("11");73 String x1y2 = CubemapUtils.convertDoubleCountNrto16TileNr("12");74 String x1y3 = CubemapUtils.convertDoubleCountNrto16TileNr("13");75 String x2y0 = CubemapUtils.convertDoubleCountNrto16TileNr("20");76 String x2y1 = CubemapUtils.convertDoubleCountNrto16TileNr("21");77 String x2y2 = CubemapUtils.convertDoubleCountNrto16TileNr("22");78 String x2y3 = CubemapUtils.convertDoubleCountNrto16TileNr("23");79 String x3y0 = CubemapUtils.convertDoubleCountNrto16TileNr("30");80 String x3y1 = CubemapUtils.convertDoubleCountNrto16TileNr("31");81 String x3y2 = CubemapUtils.convertDoubleCountNrto16TileNr("32");82 String x3y3 = CubemapUtils.convertDoubleCountNrto16TileNr("33");65 @Test 66 void testConvertDoubleCountNrto16TileNr() { 67 String x0y0 = CubemapUtils.convertDoubleCountNrto16TileNr("00"); 68 String x0y1 = CubemapUtils.convertDoubleCountNrto16TileNr("01"); 69 String x0y2 = CubemapUtils.convertDoubleCountNrto16TileNr("02"); 70 String x0y3 = CubemapUtils.convertDoubleCountNrto16TileNr("03"); 71 String x1y0 = CubemapUtils.convertDoubleCountNrto16TileNr("10"); 72 String x1y1 = CubemapUtils.convertDoubleCountNrto16TileNr("11"); 73 String x1y2 = CubemapUtils.convertDoubleCountNrto16TileNr("12"); 74 String x1y3 = CubemapUtils.convertDoubleCountNrto16TileNr("13"); 75 String x2y0 = CubemapUtils.convertDoubleCountNrto16TileNr("20"); 76 String x2y1 = CubemapUtils.convertDoubleCountNrto16TileNr("21"); 77 String x2y2 = CubemapUtils.convertDoubleCountNrto16TileNr("22"); 78 String x2y3 = CubemapUtils.convertDoubleCountNrto16TileNr("23"); 79 String x3y0 = CubemapUtils.convertDoubleCountNrto16TileNr("30"); 80 String x3y1 = CubemapUtils.convertDoubleCountNrto16TileNr("31"); 81 String x3y2 = CubemapUtils.convertDoubleCountNrto16TileNr("32"); 82 String x3y3 = CubemapUtils.convertDoubleCountNrto16TileNr("33"); 83 83 84 assertEquals(x0y0, "00");85 assertEquals(x0y1, "01");86 assertEquals(x0y2, "10");87 assertEquals(x0y3, "11");88 assertEquals(x1y0, "02");89 assertEquals(x1y1, "03");90 assertEquals(x1y2, "12");91 assertEquals(x1y3, "13");92 assertEquals(x2y0, "20");93 assertEquals(x2y1, "21");94 assertEquals(x2y2, "30");95 assertEquals(x2y3, "31");96 assertEquals(x3y0, "22");97 assertEquals(x3y1, "23");98 assertEquals(x3y2, "32");99 assertEquals(x3y3, "33");100 }84 assertEquals(x0y0, "00"); 85 assertEquals(x0y1, "01"); 86 assertEquals(x0y2, "10"); 87 assertEquals(x0y3, "11"); 88 assertEquals(x1y0, "02"); 89 assertEquals(x1y1, "03"); 90 assertEquals(x1y2, "12"); 91 assertEquals(x1y3, "13"); 92 assertEquals(x2y0, "20"); 93 assertEquals(x2y1, "21"); 94 assertEquals(x2y2, "30"); 95 assertEquals(x2y3, "31"); 96 assertEquals(x3y0, "22"); 97 assertEquals(x3y1, "23"); 98 assertEquals(x3y2, "32"); 99 assertEquals(x3y3, "33"); 100 } 101 101 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/TileDownloadingTaskTest.java
r36064 r36194 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.streetside.cubemap; 2 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 17 17 class TileDownloadingTaskTest { 18 18 19 @Test20 final void testCall() throws InterruptedException {21 ExecutorService pool = Executors.newFixedThreadPool(1);22 List<Callable<List<String>>> tasks = new ArrayList<>(1);23 tasks.add(new TileDownloadingTask("2202112030033001233"));24 List<Future<List<String>>> results = pool.invokeAll(tasks);25 assertEquals(results.get(0), "2202112030033001233");26 }19 @Test 20 final void testCall() throws InterruptedException { 21 ExecutorService pool = Executors.newFixedThreadPool(1); 22 List<Callable<List<String>>> tasks = new ArrayList<>(1); 23 tasks.add(new TileDownloadingTask("2202112030033001233")); 24 List<Future<List<String>>> results = pool.invokeAll(tasks); 25 assertEquals(results.get(0), "2202112030033001233"); 26 } 27 27 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/ImageDisplayTest.java
r36064 r36194 20 20 class ImageDisplayTest { 21 21 22 private static final BufferedImage DUMMY_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);22 private static final BufferedImage DUMMY_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 23 23 24 @Test25 void testImagePersistence() {26 StreetsideImageDisplay display = new StreetsideImageDisplay();27 display.setImage(DUMMY_IMAGE, null);28 assertEquals(DUMMY_IMAGE, display.getImage());29 }24 @Test 25 void testImagePersistence() { 26 StreetsideImageDisplay display = new StreetsideImageDisplay(); 27 display.setImage(DUMMY_IMAGE, null); 28 assertEquals(DUMMY_IMAGE, display.getImage()); 29 } 30 30 31 /**32 * This test does not check if the scroll events result in the correct changes in the {@link StreetsideImageDisplay},33 * it only checks if the tested method runs through.34 */31 /** 32 * This test does not check if the scroll events result in the correct changes in the {@link StreetsideImageDisplay}, 33 * it only checks if the tested method runs through. 34 */ 35 35 36 @Test 37 void testMouseWheelMoved() { 38 if (GraphicsEnvironment.isHeadless()) { 39 return; 36 @Test 37 void testMouseWheelMoved() { 38 if (GraphicsEnvironment.isHeadless()) { 39 return; 40 } 41 StreetsideImageDisplay display = new StreetsideImageDisplay(); 42 final MouseWheelEvent dummyScroll = new MouseWheelEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 0, 43 false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 3); 44 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); 45 46 display.setImage(DUMMY_IMAGE, null); 47 48 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); 49 50 // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it. 51 JFrame frame = new JFrame(); 52 frame.setSize(42, 42); 53 frame.getContentPane().add(display); 54 frame.pack(); 55 56 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); 40 57 } 41 StreetsideImageDisplay display = new StreetsideImageDisplay();42 final MouseWheelEvent dummyScroll = new MouseWheelEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 3);43 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);44 58 45 display.setImage(DUMMY_IMAGE, null); 59 /** 60 * This test does not check if the scroll events result in the correct changes in the {@link StreetsideImageDisplay}, 61 * it only checks if the tested method runs through. 62 */ 63 @Test 64 void testMouseClicked() { 65 if (GraphicsEnvironment.isHeadless()) { 66 return; 67 } 68 for (int button = 1; button <= 3; button++) { 69 StreetsideImageDisplay display = new StreetsideImageDisplay(); 70 final MouseEvent dummyClick = new MouseEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 1, false, 71 button); 72 display.getMouseListeners()[0].mouseClicked(dummyClick); 46 73 47 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);74 display.setImage(DUMMY_IMAGE, null); 48 75 49 // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it. 50 JFrame frame = new JFrame(); 51 frame.setSize(42, 42); 52 frame.getContentPane().add(display); 53 frame.pack(); 76 display.getMouseListeners()[0].mouseClicked(dummyClick); 54 77 55 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); 56 } 78 // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it. 79 JFrame frame = new JFrame(); 80 frame.setSize(42, 42); 81 frame.getContentPane().add(display); 82 frame.pack(); 57 83 58 /** 59 * This test does not check if the scroll events result in the correct changes in the {@link StreetsideImageDisplay}, 60 * it only checks if the tested method runs through. 61 */ 62 @Test 63 void testMouseClicked() { 64 if (GraphicsEnvironment.isHeadless()) { 65 return; 84 display.getMouseListeners()[0].mouseClicked(dummyClick); 85 } 66 86 } 67 for (int button = 1; button <= 3; button++) {68 StreetsideImageDisplay display = new StreetsideImageDisplay();69 final MouseEvent dummyClick = new MouseEvent(display, 42, System.currentTimeMillis(), 0, 0, 0, 1, false, button);70 display.getMouseListeners()[0].mouseClicked(dummyClick);71 72 display.setImage(DUMMY_IMAGE, null);73 74 display.getMouseListeners()[0].mouseClicked(dummyClick);75 76 // This is necessary to make the size of the component > 0. If you know a more elegant solution, feel free to change it.77 JFrame frame = new JFrame();78 frame.setSize(42, 42);79 frame.getContentPane().add(display);80 frame.pack();81 82 display.getMouseListeners()[0].mouseClicked(dummyClick);83 }84 }85 87 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/StreetsidePreferenceSettingTest.java
r36064 r36194 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.streetside.gui; 2 3 … … 22 23 @Disabled 23 24 class StreetsidePreferenceSettingTest { 24 // TODO: repair broken unit test from Mapillary 25 @Test 26 void testAddGui() { 27 if (GraphicsEnvironment.isHeadless()) { 28 return; 25 // TODO: repair broken unit test from Mapillary 26 @Test 27 void testAddGui() { 28 if (GraphicsEnvironment.isHeadless()) { 29 return; 30 } 31 PreferenceTabbedPane tabs = new PreferenceTabbedPane(); 32 tabs.buildGui(); 33 int displayTabs = tabs.getDisplayPreference().getTabPane().getTabCount(); 34 StreetsidePreferenceSetting setting = new StreetsidePreferenceSetting(); 35 setting.addGui(tabs); 36 assertEquals(displayTabs + 1, tabs.getDisplayPreference().getTabPane().getTabCount()); 37 assertEquals(tabs.getDisplayPreference(), setting.getTabPreferenceSetting(tabs)); 29 38 } 30 PreferenceTabbedPane tabs = new PreferenceTabbedPane();31 tabs.buildGui();32 int displayTabs = tabs.getDisplayPreference().getTabPane().getTabCount();33 StreetsidePreferenceSetting setting = new StreetsidePreferenceSetting();34 setting.addGui(tabs);35 assertEquals(displayTabs + 1, tabs.getDisplayPreference().getTabPane().getTabCount());36 assertEquals(tabs.getDisplayPreference(), setting.getTabPreferenceSetting(tabs));37 }38 39 39 @Test40 void testIsExpert() {41 Assertions.assertFalse(new StreetsidePreferenceSetting().isExpert());42 }40 @Test 41 void testIsExpert() { 42 Assertions.assertFalse(new StreetsidePreferenceSetting().isExpert()); 43 } 43 44 44 @SuppressWarnings("unchecked")45 @Test46 void testOk() {47 StreetsidePreferenceSetting settings = new StreetsidePreferenceSetting();45 @SuppressWarnings("unchecked") 46 @Test 47 void testOk() { 48 StreetsidePreferenceSetting settings = new StreetsidePreferenceSetting(); 48 49 49 // Initialize the properties with some arbitrary value to make sure they are not unset50 new StringProperty("streetside.display-hour", "default").put("arbitrary");51 new StringProperty("streetside.format-24", "default").put("arbitrary");52 new StringProperty("streetside.move-to-picture", "default").put("arbitrary");53 new StringProperty("streetside.hover-enabled", "default").put("arbitrary");54 new StringProperty("streetside.download-mode", "default").put("arbitrary");55 new StringProperty("streetside.prefetch-image-count", "default").put("arbitrary");50 // Initialize the properties with some arbitrary value to make sure they are not unset 51 new StringProperty("streetside.display-hour", "default").put("arbitrary"); 52 new StringProperty("streetside.format-24", "default").put("arbitrary"); 53 new StringProperty("streetside.move-to-picture", "default").put("arbitrary"); 54 new StringProperty("streetside.hover-enabled", "default").put("arbitrary"); 55 new StringProperty("streetside.download-mode", "default").put("arbitrary"); 56 new StringProperty("streetside.prefetch-image-count", "default").put("arbitrary"); 56 57 57 // Test checkboxes 58 settings.ok(); 59 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "displayHour"), "streetside.display-hour"); 60 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "format24"), "streetside.format-24"); 61 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "moveTo"), "streetside.move-to-picture"); 62 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled"), "streetside.hover-enabled"); 63 assertEquals(String.valueOf(((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).getNumber().intValue()), new StringProperty("streetside.prefetch-image-count", "default").get()); 58 // Test checkboxes 59 settings.ok(); 60 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "displayHour"), 61 "streetside.display-hour"); 62 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "format24"), 63 "streetside.format-24"); 64 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "moveTo"), 65 "streetside.move-to-picture"); 66 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled"), 67 "streetside.hover-enabled"); 68 assertEquals( 69 String.valueOf( 70 ((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).getNumber().intValue()), 71 new StringProperty("streetside.prefetch-image-count", "default").get()); 64 72 65 // Toggle state of the checkboxes66 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "displayHour"));67 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "format24"));68 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "moveTo"));69 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled"));70 ((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).setValue(73);73 // Toggle state of the checkboxes 74 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "displayHour")); 75 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "format24")); 76 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "moveTo")); 77 toggleCheckbox((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled")); 78 ((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).setValue(73); 71 79 72 // Test the second state of the checkboxes 73 settings.ok(); 74 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "displayHour"), "streetside.display-hour"); 75 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "format24"), "streetside.format-24"); 76 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "moveTo"), "streetside.move-to-picture"); 77 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled"), "streetside.hover-enabled"); 78 assertEquals(String.valueOf(((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).getNumber().intValue()), new StringProperty("streetside.prefetch-image-count", "default").get()); 80 // Test the second state of the checkboxes 81 settings.ok(); 82 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "displayHour"), 83 "streetside.display-hour"); 84 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "format24"), 85 "streetside.format-24"); 86 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "moveTo"), 87 "streetside.move-to-picture"); 88 assertPropertyMatchesCheckboxSelection((JCheckBox) getPrivateFieldValue(settings, "hoverEnabled"), 89 "streetside.hover-enabled"); 90 assertEquals( 91 String.valueOf( 92 ((SpinnerNumberModel) getPrivateFieldValue(settings, "preFetchSize")).getNumber().intValue()), 93 new StringProperty("streetside.prefetch-image-count", "default").get()); 79 94 80 // Test combobox 81 for (int i = 0; i < ((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")).getItemCount(); i++) { 82 ((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")).setSelectedIndex(i); 83 settings.ok(); 84 assertEquals( 85 new StringProperty("streetside.download-mode", "default").get(), 86 DOWNLOAD_MODE.fromLabel( 87 ((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")).getSelectedItem().toString() 88 ).getPrefId() 89 ); 95 // Test combobox 96 for (int i = 0; i < ((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")) 97 .getItemCount(); i++) { 98 ((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")).setSelectedIndex(i); 99 settings.ok(); 100 assertEquals(new StringProperty("streetside.download-mode", "default").get(), 101 DOWNLOAD_MODE.fromLabel(((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox")) 102 .getSelectedItem().toString()).getPrefId()); 103 } 90 104 } 91 }92 105 93 /**94 * Checks, if a certain {@link BooleanProperty} (identified by the {@code propName} attribute) matches the selected-state of the given {@link JCheckBox}95 * @param cb the {@link JCheckBox}, which should be checked against the {@link BooleanProperty}96 * @param propName the name of the property against which the selected-state of the given {@link JCheckBox} should be checked97 */98 private static void assertPropertyMatchesCheckboxSelection(JCheckBox cb, String propName) {99 assertEquals(cb.isSelected(), new BooleanProperty(propName, !cb.isSelected()).get());100 }106 /** 107 * Checks, if a certain {@link BooleanProperty} (identified by the {@code propName} attribute) matches the selected-state of the given {@link JCheckBox} 108 * @param cb the {@link JCheckBox}, which should be checked against the {@link BooleanProperty} 109 * @param propName the name of the property against which the selected-state of the given {@link JCheckBox} should be checked 110 */ 111 private static void assertPropertyMatchesCheckboxSelection(JCheckBox cb, String propName) { 112 assertEquals(cb.isSelected(), new BooleanProperty(propName, !cb.isSelected()).get()); 113 } 101 114 102 private static void toggleCheckbox(JCheckBox jcb) {103 jcb.setSelected(!jcb.isSelected());104 }115 private static void toggleCheckbox(JCheckBox jcb) { 116 jcb.setSelected(!jcb.isSelected()); 117 } 105 118 106 119 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/boilerplate/SelectableLabelTest.java
r36064 r36194 7 7 import org.junit.jupiter.api.Test; 8 8 9 10 9 class SelectableLabelTest { 11 @Test12 void testSelectableLabel() {13 SelectableLabel l1 = new SelectableLabel();14 assertFalse(l1.isEditable());15 SelectableLabel l2 = new SelectableLabel("some text");16 assertTrue(l2.getText().contains("some text"));17 assertFalse(l2.isEditable());18 }10 @Test 11 void testSelectableLabel() { 12 SelectableLabel l1 = new SelectableLabel(); 13 assertFalse(l1.isEditable()); 14 SelectableLabel l2 = new SelectableLabel("some text"); 15 assertTrue(l2.getText().contains("some text")); 16 assertFalse(l2.isEditable()); 17 } 19 18 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/history/StreetsideRecordTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.history; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 35 34 class StreetsideRecordTest { 36 35 37 private StreetsideRecord record; 38 private StreetsideImage img1; 39 private StreetsideImage img2; 40 private StreetsideImage img3; 41 42 /** 43 * Creates a new {@link StreetsideRecord} object and 3 {@link StreetsideImage} 44 * objects. 45 */ 46 @BeforeEach 47 public void setUp() { 48 record = new StreetsideRecord(); 49 img1 = new StreetsideImage("key1__________________", new LatLon(0.1, 0.1), 0.1); 50 img2 = new StreetsideImage("key2__________________", new LatLon(0.2, 0.2), 0.2); 51 img3 = new StreetsideImage("key3__________________", new LatLon(0.3, 0.3), 0.3); 52 if (StreetsideLayer.hasInstance() && StreetsideLayer.getInstance().getData().getImages().size() >= 1) { 53 StreetsideLayer.getInstance().getData().getImages().clear(); 54 } 55 } 56 57 /** 58 * Test commands in general. 59 */ 60 @Test 61 void testCommand() { 62 StreetsideCommand cmd12 = new CommandMove( 63 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 64 0.1, 0.1); 65 StreetsideCommand cmd23 = new CommandMove( 66 new ConcurrentSkipListSet<>(Arrays.asList(img2, img3)), 67 0.1, 0.1); 68 StreetsideCommand cmd13 = new CommandMove( 69 new ConcurrentSkipListSet<>(Arrays.asList(img1, img3)), 70 0.1, 0.1); 71 StreetsideCommand cmd1 = new CommandMove( 72 new ConcurrentSkipListSet<>(Collections.singletonList(img1)), 0.1, 0.1); 73 StreetsideCommand cmd31 = new CommandMove( 74 new ConcurrentSkipListSet<>(Arrays.asList(img3, img1)), 75 0.2, 0.2); 76 record.addCommand(cmd12); 77 record.addCommand(cmd23); 78 79 assertEquals(1, record.position); 80 assertEquals(2, record.commandList.size()); 81 82 record.undo(); 83 84 assertEquals(0, record.position); 85 assertEquals(2, record.commandList.size()); 86 87 record.addCommand(cmd1); 88 89 assertEquals(1, record.position); 90 91 record.addCommand(cmd13); 92 93 assertEquals(2, record.position); 94 assertEquals(3, record.commandList.size()); 95 96 record.undo(); 97 record.redo(); 98 99 assertEquals(2, record.position); 100 assertEquals(3, record.commandList.size()); 101 102 record.addCommand(cmd31); 103 104 assertEquals(2, record.position); 105 assertEquals(3, record.commandList.size()); 106 107 record.addCommand(cmd1); 108 109 assertEquals(3, record.position); 110 assertEquals(4, record.commandList.size()); 111 } 112 113 /** 114 * Tests {@link CommandMove} class. 115 */ 116 @Test 117 void testCommandMove() { 118 CommandMove cmd1 = new CommandMove( 119 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 120 0.1, 0.1); 121 CommandMove cmd2 = new CommandMove( 122 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 123 0.1, 0.1); 124 125 record.addCommand(cmd1); 126 127 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 128 129 record.undo(); 130 131 assertEquals(0.0, img1.getMovingLatLon().lat(), 0.01); 132 133 record.redo(); 134 135 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 136 137 record.addCommand(cmd2); 138 record.undo(); 139 140 assertEquals(-0.1, img1.getMovingLatLon().lat(), 0.01); 141 142 record.redo(); 143 144 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 145 } 146 147 /** 148 * Tests {@link CommandTurn} class. 149 */ 150 @Test 151 void testCommandTurn() { 152 CommandTurn cmd1 = new CommandTurn( 153 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 154 0.2); 155 CommandTurn cmd2 = new CommandTurn( 156 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 157 0.1); 158 159 record.addCommand(cmd1); 160 record.undo(); 161 162 assertEquals(-0.1, img1.getMovingHe(), 0.01); 163 164 record.redo(); 165 166 assertEquals(0.1, img1.getMovingHe(), 0.01); 167 168 record.addCommand(cmd2); 169 record.undo(); 170 171 assertEquals(-0.2, img1.getMovingHe(), 0.01); 172 173 record.redo(); 174 175 assertEquals(0.1, img1.getMovingHe(), 0.01); 176 } 177 178 /** 179 * Tests {@link CommandJoin} class. 180 */ 181 @Test 182 void testCommandJoinClass() { 183 CommandJoin cmd1 = new CommandJoin(img1, img2); 184 CommandJoin cmd2 = new CommandJoin(img2, img3); 185 186 record.addCommand(cmd1); 187 assertEquals(2, img1.getSequence().getImages().size()); 188 assertEquals(img2, img1.next()); 189 record.undo(); 190 assertEquals(1, img1.getSequence().getImages().size()); 191 record.redo(); 192 record.addCommand(cmd2); 193 assertEquals(3, img1.getSequence().getImages().size()); 194 assertEquals(img3, img1.next().next()); 195 } 196 197 @Test 198 void testCommandJoinNull1() { 199 assertThrows(NullPointerException.class, () -> new CommandJoin(img1, null)); 200 } 201 202 @Test 203 void commandJoinNull2() { 204 assertThrows(NullPointerException.class, () -> new CommandJoin(null, img1)); 205 } 206 207 /** 208 * Tests {@link CommandUnjoin} class. 209 */ 210 @Test 211 void testCommandUnjoinClass() { 212 CommandJoin join1 = new CommandJoin(img1, img2); 213 CommandJoin join2 = new CommandJoin(img2, img3); 214 215 CommandUnjoin cmd1 = new CommandUnjoin( 216 Arrays.asList(new StreetsideAbstractImage[]{img1, img2})); 217 CommandUnjoin cmd2 = new CommandUnjoin( 218 Arrays.asList(new StreetsideAbstractImage[]{img2, img3})); 219 220 record.addCommand(join1); 221 record.addCommand(join2); 222 223 record.addCommand(cmd1); 224 assertEquals(1, img1.getSequence().getImages().size()); 225 record.undo(); 226 assertEquals(3, img1.getSequence().getImages().size()); 227 record.redo(); 228 record.addCommand(cmd2); 229 assertEquals(1, img1.getSequence().getImages().size()); 230 assertEquals(1, img2.getSequence().getImages().size()); 231 232 CommandUnjoin command = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[]{img1, img2, img3})); 233 assertThrows(IllegalArgumentException.class, () -> record.addCommand(command)); 234 } 36 private StreetsideRecord record; 37 private StreetsideImage img1; 38 private StreetsideImage img2; 39 private StreetsideImage img3; 40 41 /** 42 * Creates a new {@link StreetsideRecord} object and 3 {@link StreetsideImage} 43 * objects. 44 */ 45 @BeforeEach 46 public void setUp() { 47 record = new StreetsideRecord(); 48 img1 = new StreetsideImage("key1__________________", new LatLon(0.1, 0.1), 0.1); 49 img2 = new StreetsideImage("key2__________________", new LatLon(0.2, 0.2), 0.2); 50 img3 = new StreetsideImage("key3__________________", new LatLon(0.3, 0.3), 0.3); 51 if (StreetsideLayer.hasInstance() && StreetsideLayer.getInstance().getData().getImages().size() >= 1) { 52 StreetsideLayer.getInstance().getData().getImages().clear(); 53 } 54 } 55 56 /** 57 * Test commands in general. 58 */ 59 @Test 60 void testCommand() { 61 StreetsideCommand cmd12 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 62 StreetsideCommand cmd23 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img2, img3)), 0.1, 0.1); 63 StreetsideCommand cmd13 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img3)), 0.1, 0.1); 64 StreetsideCommand cmd1 = new CommandMove(new ConcurrentSkipListSet<>(Collections.singletonList(img1)), 0.1, 65 0.1); 66 StreetsideCommand cmd31 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img3, img1)), 0.2, 0.2); 67 record.addCommand(cmd12); 68 record.addCommand(cmd23); 69 70 assertEquals(1, record.position); 71 assertEquals(2, record.commandList.size()); 72 73 record.undo(); 74 75 assertEquals(0, record.position); 76 assertEquals(2, record.commandList.size()); 77 78 record.addCommand(cmd1); 79 80 assertEquals(1, record.position); 81 82 record.addCommand(cmd13); 83 84 assertEquals(2, record.position); 85 assertEquals(3, record.commandList.size()); 86 87 record.undo(); 88 record.redo(); 89 90 assertEquals(2, record.position); 91 assertEquals(3, record.commandList.size()); 92 93 record.addCommand(cmd31); 94 95 assertEquals(2, record.position); 96 assertEquals(3, record.commandList.size()); 97 98 record.addCommand(cmd1); 99 100 assertEquals(3, record.position); 101 assertEquals(4, record.commandList.size()); 102 } 103 104 /** 105 * Tests {@link CommandMove} class. 106 */ 107 @Test 108 void testCommandMove() { 109 CommandMove cmd1 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 110 CommandMove cmd2 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 111 112 record.addCommand(cmd1); 113 114 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 115 116 record.undo(); 117 118 assertEquals(0.0, img1.getMovingLatLon().lat(), 0.01); 119 120 record.redo(); 121 122 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 123 124 record.addCommand(cmd2); 125 record.undo(); 126 127 assertEquals(-0.1, img1.getMovingLatLon().lat(), 0.01); 128 129 record.redo(); 130 131 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 132 } 133 134 /** 135 * Tests {@link CommandTurn} class. 136 */ 137 @Test 138 void testCommandTurn() { 139 CommandTurn cmd1 = new CommandTurn(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.2); 140 CommandTurn cmd2 = new CommandTurn(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1); 141 142 record.addCommand(cmd1); 143 record.undo(); 144 145 assertEquals(-0.1, img1.getMovingHe(), 0.01); 146 147 record.redo(); 148 149 assertEquals(0.1, img1.getMovingHe(), 0.01); 150 151 record.addCommand(cmd2); 152 record.undo(); 153 154 assertEquals(-0.2, img1.getMovingHe(), 0.01); 155 156 record.redo(); 157 158 assertEquals(0.1, img1.getMovingHe(), 0.01); 159 } 160 161 /** 162 * Tests {@link CommandJoin} class. 163 */ 164 @Test 165 void testCommandJoinClass() { 166 CommandJoin cmd1 = new CommandJoin(img1, img2); 167 CommandJoin cmd2 = new CommandJoin(img2, img3); 168 169 record.addCommand(cmd1); 170 assertEquals(2, img1.getSequence().getImages().size()); 171 assertEquals(img2, img1.next()); 172 record.undo(); 173 assertEquals(1, img1.getSequence().getImages().size()); 174 record.redo(); 175 record.addCommand(cmd2); 176 assertEquals(3, img1.getSequence().getImages().size()); 177 assertEquals(img3, img1.next().next()); 178 } 179 180 @Test 181 void testCommandJoinNull1() { 182 assertThrows(NullPointerException.class, () -> new CommandJoin(img1, null)); 183 } 184 185 @Test 186 void commandJoinNull2() { 187 assertThrows(NullPointerException.class, () -> new CommandJoin(null, img1)); 188 } 189 190 /** 191 * Tests {@link CommandUnjoin} class. 192 */ 193 @Test 194 void testCommandUnjoinClass() { 195 CommandJoin join1 = new CommandJoin(img1, img2); 196 CommandJoin join2 = new CommandJoin(img2, img3); 197 198 CommandUnjoin cmd1 = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img1, img2 })); 199 CommandUnjoin cmd2 = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img2, img3 })); 200 201 record.addCommand(join1); 202 record.addCommand(join2); 203 204 record.addCommand(cmd1); 205 assertEquals(1, img1.getSequence().getImages().size()); 206 record.undo(); 207 assertEquals(3, img1.getSequence().getImages().size()); 208 record.redo(); 209 record.addCommand(cmd2); 210 assertEquals(1, img1.getSequence().getImages().size()); 211 assertEquals(1, img2.getSequence().getImages().size()); 212 213 CommandUnjoin command = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img1, img2, img3 })); 214 assertThrows(IllegalArgumentException.class, () -> record.addCommand(command)); 215 } 235 216 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/io/download/SequenceDownloadRunnableTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.io.download; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 21 20 class SequenceDownloadRunnableTest { 22 21 23 private static final Function<Bounds, URL> SEARCH_SEQUENCES_URL_GEN = b -> {24 return SequenceDownloadRunnableTest.class.getResource("/api/v3/responses/searchSequences.json");25 };26 private Field urlGenField;22 private static final Function<Bounds, URL> SEARCH_SEQUENCES_URL_GEN = b -> { 23 return SequenceDownloadRunnableTest.class.getResource("/api/v3/responses/searchSequences.json"); 24 }; 25 private Field urlGenField; 27 26 27 @Test 28 void testRun1() throws IllegalArgumentException, IllegalAccessException { 29 testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976)); 30 } 28 31 29 @Test30 void testRun1() throws IllegalArgumentException, IllegalAccessException {31 testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));32 }32 @Test 33 void testRun2() throws IllegalArgumentException, IllegalAccessException { 34 testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0)); 35 } 33 36 34 @Test 35 void testRun2() throws IllegalArgumentException, IllegalAccessException { 36 testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0)); 37 } 37 @Test 38 void testRun3() throws IllegalArgumentException, IllegalAccessException { 39 testNumberOfDecodedImages(0, b -> { 40 try { 41 return new URL("https://streetside/nonexistentURL"); 42 } catch (MalformedURLException e) { 43 return null; 44 } 45 }, new Bounds(0, 0, 0, 0)); 46 } 38 47 39 @Test 40 void testRun3() throws IllegalArgumentException, IllegalAccessException { 41 testNumberOfDecodedImages(0, b -> { 42 try { return new URL("https://streetside/nonexistentURL"); } catch (MalformedURLException e) { return null; } 43 }, new Bounds(0, 0, 0, 0)); 44 } 48 @Test 49 void testRun4() throws IllegalArgumentException, IllegalAccessException { 50 StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true); 51 testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976)); 52 } 45 53 46 @Test47 void testRun4() throws IllegalArgumentException, IllegalAccessException {48 StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true);49 testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));50 }54 @Test 55 void testRun5() throws IllegalArgumentException, IllegalAccessException { 56 StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true); 57 testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0)); 58 } 51 59 52 @Test 53 void testRun5() throws IllegalArgumentException, IllegalAccessException { 54 StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true); 55 testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0)); 56 } 57 58 private void testNumberOfDecodedImages(int expectedNumImgs, Function<Bounds, URL> urlGen, Bounds bounds) 59 throws IllegalArgumentException, IllegalAccessException { 60 SequenceDownloadRunnable r = new SequenceDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds); 61 urlGenField.set(null, urlGen); 62 r.run(); 63 assertEquals(expectedNumImgs, StreetsideLayer.getInstance().getData().getImages().size()); 64 } 60 private void testNumberOfDecodedImages(int expectedNumImgs, Function<Bounds, URL> urlGen, Bounds bounds) 61 throws IllegalArgumentException, IllegalAccessException { 62 SequenceDownloadRunnable r = new SequenceDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds); 63 urlGenField.set(null, urlGen); 64 r.run(); 65 assertEquals(expectedNumImgs, StreetsideLayer.getInstance().getData().getImages().size()); 66 } 65 67 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/ImageUtilTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.utils; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 11 10 import org.junit.jupiter.api.Test; 12 11 13 14 12 class ImageUtilTest { 15 13 16 @Test17 void testUtilityClass() {18 TestUtil.testUtilityClass(ImageUtil.class);19 }14 @Test 15 void testUtilityClass() { 16 TestUtil.testUtilityClass(ImageUtil.class); 17 } 20 18 21 @Test22 void testScaleImageIcon() {23 ImageIcon largeLandscape = new ImageIcon(new BufferedImage(72, 60, BufferedImage.TYPE_4BYTE_ABGR));24 ImageIcon largePortrait = new ImageIcon(new BufferedImage(56, 88, BufferedImage.TYPE_4BYTE_ABGR));25 ImageIcon smallLandscape = ImageUtil.scaleImageIcon(largeLandscape, 24);26 ImageIcon smallPortrait = ImageUtil.scaleImageIcon(largePortrait, 22);19 @Test 20 void testScaleImageIcon() { 21 ImageIcon largeLandscape = new ImageIcon(new BufferedImage(72, 60, BufferedImage.TYPE_4BYTE_ABGR)); 22 ImageIcon largePortrait = new ImageIcon(new BufferedImage(56, 88, BufferedImage.TYPE_4BYTE_ABGR)); 23 ImageIcon smallLandscape = ImageUtil.scaleImageIcon(largeLandscape, 24); 24 ImageIcon smallPortrait = ImageUtil.scaleImageIcon(largePortrait, 22); 27 25 28 assertEquals(24, smallLandscape.getIconWidth());29 assertEquals(20, smallLandscape.getIconHeight());26 assertEquals(24, smallLandscape.getIconWidth()); 27 assertEquals(20, smallLandscape.getIconHeight()); 30 28 31 assertEquals(22, smallPortrait.getIconHeight());32 assertEquals(14, smallPortrait.getIconWidth());33 }29 assertEquals(22, smallPortrait.getIconHeight()); 30 assertEquals(14, smallPortrait.getIconWidth()); 31 } 34 32 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/JsonUtil.java
r36122 r36194 9 9 10 10 public final class JsonUtil { 11 private JsonUtil() {12 // Private constructor to avoid instantiation13 }11 private JsonUtil() { 12 // Private constructor to avoid instantiation 13 } 14 14 15 public static JsonObject string2jsonObject(String s) {16 return Json.createReader(new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8))).readObject();17 }15 public static JsonObject string2jsonObject(String s) { 16 return Json.createReader(new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8))).readObject(); 17 } 18 18 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/PluginStateTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.utils; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 21 20 class PluginStateTest { 22 21 23 /**24 * Test the methods related to the download.25 */26 @Test27 void testDownload() {28 assertFalse(PluginState.isDownloading());29 PluginState.startDownload();30 assertTrue(PluginState.isDownloading());31 PluginState.startDownload();32 assertTrue(PluginState.isDownloading());33 PluginState.finishDownload();34 assertTrue(PluginState.isDownloading());35 PluginState.finishDownload();36 assertFalse(PluginState.isDownloading());37 }22 /** 23 * Test the methods related to the download. 24 */ 25 @Test 26 void testDownload() { 27 assertFalse(PluginState.isDownloading()); 28 PluginState.startDownload(); 29 assertTrue(PluginState.isDownloading()); 30 PluginState.startDownload(); 31 assertTrue(PluginState.isDownloading()); 32 PluginState.finishDownload(); 33 assertTrue(PluginState.isDownloading()); 34 PluginState.finishDownload(); 35 assertFalse(PluginState.isDownloading()); 36 } 38 37 39 /** 40 * Tests the methods related to the upload. 41 */ 42 @Test 43 void testUpload() { 44 TestUtils.assumeWorkingJMockit(); 45 JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(); 46 jopsMocker.getMockResultMap().put( 47 "You have successfully uploaded 2 images to Bing.com", 48 JOptionPane.OK_OPTION 49 ); 50 assertFalse(PluginState.isUploading()); 51 PluginState.addImagesToUpload(2); 52 assertEquals(2, PluginState.getImagesToUpload()); 53 assertEquals(0, PluginState.getImagesUploaded()); 54 assertTrue(PluginState.isUploading()); 55 PluginState.imageUploaded(); 56 assertEquals(1, PluginState.getImagesUploaded()); 57 assertTrue(PluginState.isUploading()); 58 PluginState.imageUploaded(); 59 assertFalse(PluginState.isUploading()); 60 assertEquals(2, PluginState.getImagesToUpload()); 61 assertEquals(2, PluginState.getImagesUploaded()); 62 } 38 /** 39 * Tests the methods related to the upload. 40 */ 41 @Test 42 void testUpload() { 43 TestUtils.assumeWorkingJMockit(); 44 JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(); 45 jopsMocker.getMockResultMap().put("You have successfully uploaded 2 images to Bing.com", JOptionPane.OK_OPTION); 46 assertFalse(PluginState.isUploading()); 47 PluginState.addImagesToUpload(2); 48 assertEquals(2, PluginState.getImagesToUpload()); 49 assertEquals(0, PluginState.getImagesUploaded()); 50 assertTrue(PluginState.isUploading()); 51 PluginState.imageUploaded(); 52 assertEquals(1, PluginState.getImagesUploaded()); 53 assertTrue(PluginState.isUploading()); 54 PluginState.imageUploaded(); 55 assertFalse(PluginState.isUploading()); 56 assertEquals(2, PluginState.getImagesToUpload()); 57 assertEquals(2, PluginState.getImagesUploaded()); 58 } 63 59 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideColorSchemeTest.java
r36064 r36194 10 10 class StreetsideColorSchemeTest { 11 11 12 @Test13 void testUtilityClass() {14 TestUtil.testUtilityClass(StreetsideColorScheme.class);15 }12 @Test 13 void testUtilityClass() { 14 TestUtil.testUtilityClass(StreetsideColorScheme.class); 15 } 16 16 17 @Test18 void testStyleAsDefaultPanel() {19 assertDoesNotThrow(() -> StreetsideColorScheme.styleAsDefaultPanel());20 assertDoesNotThrow(() -> StreetsideColorScheme.styleAsDefaultPanel((JComponent[]) null));21 }17 @Test 18 void testStyleAsDefaultPanel() { 19 assertDoesNotThrow(() -> StreetsideColorScheme.styleAsDefaultPanel()); 20 assertDoesNotThrow(() -> StreetsideColorScheme.styleAsDefaultPanel((JComponent[]) null)); 21 } 22 22 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsidePropertiesTest.java
r36064 r36194 5 5 6 6 public class StreetsidePropertiesTest { 7 @Test8 public void testUtilityClass() {9 TestUtil.testUtilityClass(StreetsideProperties.class);10 }7 @Test 8 public void testUtilityClass() { 9 TestUtil.testUtilityClass(StreetsideProperties.class); 10 } 11 11 12 12 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideURLTest.java
r36064 r36194 16 16 17 17 class StreetsideURLTest { 18 // TODO: replace with Streetside URL @rrh19 private static final String CLIENT_ID_QUERY_PART = "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";18 // TODO: replace with Streetside URL @rrh 19 private static final String CLIENT_ID_QUERY_PART = "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"; 20 20 21 public static class APIv3 {21 public static class APIv3 { 22 22 23 /*@Ignore 24 @Test 25 public void testSearchDetections() { 26 assertUrlEquals(StreetsideURL.APIv3.searchDetections(null), "https://a.streetside.com/v3/detections", CLIENT_ID_QUERY_PART); 23 /*@Ignore 24 @Test 25 public void testSearchDetections() { 26 assertUrlEquals(StreetsideURL.APIv3.searchDetections(null), "https://a.streetside.com/v3/detections", CLIENT_ID_QUERY_PART); 27 } 28 29 @Ignore 30 @Test 31 public void testSearchImages() { 32 assertUrlEquals(StreetsideURL.APIv3.searchImages(null), "https://a.streetside.com/v3/images", CLIENT_ID_QUERY_PART); 33 } 34 35 @Ignore 36 @Test 37 public void testSubmitChangeset() throws MalformedURLException { 38 assertEquals( 39 new URL("https://a.streetside.com/v3/changesets?" + CLIENT_ID_QUERY_PART), 40 StreetsideURL.APIv3.submitChangeset() 41 ); 42 }*/ 27 43 } 28 44 29 @Ignore30 45 @Test 31 public void testSearchImages() {32 assertUrlEquals(StreetsideURL.APIv3.searchImages(null), "https://a.streetside.com/v3/images", CLIENT_ID_QUERY_PART);33 }34 35 @Ignore36 @Test37 public void testSubmitChangeset() throws MalformedURLException {38 assertEquals(39 new URL("https://a.streetside.com/v3/changesets?" + CLIENT_ID_QUERY_PART),40 StreetsideURL.APIv3.submitChangeset()41 );42 }*/43 }44 45 46 @Test47 46 void testParseNextFromHeaderValue() throws MalformedURLException { 48 String headerVal = 49 "<https://a.streetside.com/v3/sequences?page=1&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"first\", " + 50 "<https://a.streetside.com/v3/sequences?page=2&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"prev\", " + 51 "<https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"next\""; 52 assertEquals(new URL("https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2"), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal)); 47 String headerVal = "<https://a.streetside.com/v3/sequences?page=1&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"first\", " 48 + "<https://a.streetside.com/v3/sequences?page=2&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"prev\", " 49 + "<https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"next\""; 50 assertEquals(new URL( 51 "https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2"), 52 StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal)); 53 53 } 54 54 55 55 @Test 56 56 void testParseNextFromHeaderValue2() throws MalformedURLException { 57 String headerVal = 58 "<https://urlFirst>; rel=\"first\", " + 59 "rel = \"next\" ; < ; , " + 60 "rel = \"next\" ; <https://urlNext> , " + 61 "<https://urlPrev>; rel=\"prev\""; 62 assertEquals(new URL("https://urlNext"), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal)); 57 String headerVal = "<https://urlFirst>; rel=\"first\", " + "rel = \"next\" ; < ; , " 58 + "rel = \"next\" ; <https://urlNext> , " + "<https://urlPrev>; rel=\"prev\""; 59 assertEquals(new URL("https://urlNext"), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal)); 63 60 } 64 61 65 62 @Test 66 63 void testParseNextFromHeaderValueNull() { 67 assertNull(StreetsideURL.APIv3.parseNextFromLinkHeaderValue(null));64 assertNull(StreetsideURL.APIv3.parseNextFromLinkHeaderValue(null)); 68 65 } 69 66 70 67 @Test 71 68 void testParseNextFromHeaderValueMalformed() { 72 assertNull(StreetsideURL.APIv3.parseNextFromLinkHeaderValue("<###>; rel=\"next\", blub"));69 assertNull(StreetsideURL.APIv3.parseNextFromLinkHeaderValue("<###>; rel=\"next\", blub")); 73 70 } 74 71 75 76 /*public static class Cloudfront { 72 /*public static class Cloudfront { 77 73 @Ignore 78 74 @Test 79 75 public void testThumbnail() { 80 76 assertUrlEquals(StreetsideURL.VirtualEarth.streetsideTile("arbitrary_key", true), "https://d1cuyjsrcm0gby.cloudfront.net/arbitrary_key/thumb-2048.jpg"); 81 77 assertUrlEquals(StreetsideURL.VirtualEarth.streetsideTile("arbitrary_key2", false), "https://d1cuyjsrcm0gby.cloudfront.net/arbitrary_key2/thumb-320.jpg"); 82 78 } 83 }*/79 }*/ 84 80 85 @Disabled 86 @Test 87 void testBrowseImageURL() throws MalformedURLException { 88 assertEquals(new URL("https://www.streetside.com/map/im/1234567890123456789012"), StreetsideURL.MainWebsite.browseImage("1234567890123456789012")); 89 } 81 @Disabled 82 @Test 83 void testBrowseImageURL() throws MalformedURLException { 84 assertEquals(new URL("https://www.streetside.com/map/im/1234567890123456789012"), 85 StreetsideURL.MainWebsite.browseImage("1234567890123456789012")); 86 } 90 87 91 @Test92 void testIllegalBrowseImageURL() {93 assertThrows(IllegalArgumentException.class, () -> StreetsideURL.MainWebsite.browseImage(null));94 }88 @Test 89 void testIllegalBrowseImageURL() { 90 assertThrows(IllegalArgumentException.class, () -> StreetsideURL.MainWebsite.browseImage(null)); 91 } 95 92 96 @Disabled97 @Test98 void testConnectURL() {99 /*assertUrlEquals(93 @Disabled 94 @Test 95 void testConnectURL() { 96 /*assertUrlEquals( 100 97 StreetsideURL.MainWebsite.connect("http://redirect-host/ä"), 101 98 "https://www.streetside.com/connect", … … 104 101 "response_type=token", 105 102 "redirect_uri=http%3A%2F%2Fredirect-host%2F%C3%A4" 106 );103 ); 107 104 108 assertUrlEquals(105 assertUrlEquals( 109 106 StreetsideURL.MainWebsite.connect(null), 110 107 "https://www.streetside.com/connect", … … 112 109 "scope=user%3Aread+public%3Aupload+public%3Awrite", 113 110 "response_type=token" 114 );111 ); 115 112 116 assertUrlEquals(113 assertUrlEquals( 117 114 StreetsideURL.MainWebsite.connect(""), 118 115 "https://www.streetside.com/connect", … … 120 117 "scope=user%3Aread+public%3Aupload+public%3Awrite", 121 118 "response_type=token" 122 );*/123 }119 );*/ 120 } 124 121 125 @Disabled126 @Test127 void testUploadSecretsURL() throws MalformedURLException {128 /*assertEquals(122 @Disabled 123 @Test 124 void testUploadSecretsURL() throws MalformedURLException { 125 /*assertEquals( 129 126 new URL("https://a.streetside.com/v2/me/uploads/secrets?"+CLIENT_ID_QUERY_PART), 130 127 StreetsideURL.uploadSecretsURL() 131 );*/132 }128 );*/ 129 } 133 130 134 @Disabled135 @Test136 void testUserURL() throws MalformedURLException {137 /*assertEquals(131 @Disabled 132 @Test 133 void testUserURL() throws MalformedURLException { 134 /*assertEquals( 138 135 new URL("https://a.streetside.com/v3/me?"+CLIENT_ID_QUERY_PART), 139 136 StreetsideURL.APIv3.userURL() 140 );*/141 }137 );*/ 138 } 142 139 143 @Test144 void testString2MalformedURL()145 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,NoSuchMethodException, SecurityException {146 Method method = StreetsideURL.class.getDeclaredMethod("string2URL", String[].class);147 method.setAccessible(true);148 Assertions.assertNull(method.invoke(null, new Object[]{new String[]{"malformed URL"}})); // this simply invokes string2URL("malformed URL")149 Assertions.assertNull(method.invoke(null, new Object[]{null})); // invokes string2URL(null)150 }140 @Test 141 void testString2MalformedURL() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, 142 NoSuchMethodException, SecurityException { 143 Method method = StreetsideURL.class.getDeclaredMethod("string2URL", String[].class); 144 method.setAccessible(true); 145 Assertions.assertNull(method.invoke(null, new Object[] { new String[] { "malformed URL" } })); // this simply invokes string2URL("malformed URL") 146 Assertions.assertNull(method.invoke(null, new Object[] { null })); // invokes string2URL(null) 147 } 151 148 152 @Test153 void testUtilityClass() {154 TestUtil.testUtilityClass(StreetsideURL.class);155 TestUtil.testUtilityClass(StreetsideURL.APIv3.class);156 TestUtil.testUtilityClass(StreetsideURL.VirtualEarth.class);157 TestUtil.testUtilityClass(StreetsideURL.MainWebsite.class);158 }149 @Test 150 void testUtilityClass() { 151 TestUtil.testUtilityClass(StreetsideURL.class); 152 TestUtil.testUtilityClass(StreetsideURL.APIv3.class); 153 TestUtil.testUtilityClass(StreetsideURL.VirtualEarth.class); 154 TestUtil.testUtilityClass(StreetsideURL.MainWebsite.class); 155 } 159 156 160 private static void assertUrlEquals(URL actualUrl, String expectedBaseUrl, String... expectedParams) { 161 final String actualUrlString = actualUrl.toString(); 162 assertEquals(expectedBaseUrl, actualUrlString.contains("?") ? actualUrlString.substring(0, actualUrlString.indexOf('?')) : actualUrlString); 163 String[] actualParams = actualUrl.getQuery() == null ? new String[0] : actualUrl.getQuery().split("&"); 164 assertEquals(expectedParams.length, actualParams.length); 165 for (int exIndex = 0; exIndex < expectedParams.length; exIndex++) { 166 boolean parameterIsPresent = false; 167 for (int acIndex = 0; !parameterIsPresent && acIndex < actualParams.length; acIndex++) { 168 parameterIsPresent |= actualParams[acIndex].equals(expectedParams[exIndex]); 169 } 170 Assertions.assertTrue(parameterIsPresent, expectedParams[exIndex] + " was expected in the query string of " + actualUrl.toString() + " but wasn't there."); 157 private static void assertUrlEquals(URL actualUrl, String expectedBaseUrl, String... expectedParams) { 158 final String actualUrlString = actualUrl.toString(); 159 assertEquals(expectedBaseUrl, 160 actualUrlString.contains("?") ? actualUrlString.substring(0, actualUrlString.indexOf('?')) 161 : actualUrlString); 162 String[] actualParams = actualUrl.getQuery() == null ? new String[0] : actualUrl.getQuery().split("&"); 163 assertEquals(expectedParams.length, actualParams.length); 164 for (int exIndex = 0; exIndex < expectedParams.length; exIndex++) { 165 boolean parameterIsPresent = false; 166 for (int acIndex = 0; !parameterIsPresent && acIndex < actualParams.length; acIndex++) { 167 parameterIsPresent |= actualParams[acIndex].equals(expectedParams[exIndex]); 168 } 169 Assertions.assertTrue(parameterIsPresent, expectedParams[exIndex] + " was expected in the query string of " 170 + actualUrl + " but wasn't there."); 171 } 171 172 } 172 }173 173 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideUtilsTest.java
r36064 r36194 11 11 * Tests the static methods of the class {@link StreetsideUtils} 12 12 * 13 * @author nokutu 13 14 * @see StreetsideUtils 14 * @author nokutu15 *16 15 */ 17 16 class StreetsideUtilsTest { 18 17 19 @Test20 void testUtilityClass() {21 TestUtil.testUtilityClass(StreetsideUtils.class);22 }18 @Test 19 void testUtilityClass() { 20 TestUtil.testUtilityClass(StreetsideUtils.class); 21 } 23 22 24 /**25 * Test {@link StreetsideUtils#degMinSecToDouble(RationalNumber[], String)}26 * method.27 */28 @Test29 void testDegMinSecToDouble() {30 RationalNumber[] num = new RationalNumber[3];31 num[0] = new RationalNumber(1, 1);32 num[1] = new RationalNumber(0, 1);33 num[2] = new RationalNumber(0, 1);34 String ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH;35 assertEquals(1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);36 ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH;37 assertEquals(-1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);38 num[0] = new RationalNumber(180, 1);39 assertEquals(-180, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);40 num[0] = new RationalNumber(190, 1);41 assertEquals(170, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);42 }23 /** 24 * Test {@link StreetsideUtils#degMinSecToDouble(RationalNumber[], String)} 25 * method. 26 */ 27 @Test 28 void testDegMinSecToDouble() { 29 RationalNumber[] num = new RationalNumber[3]; 30 num[0] = new RationalNumber(1, 1); 31 num[1] = new RationalNumber(0, 1); 32 num[2] = new RationalNumber(0, 1); 33 String ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH; 34 assertEquals(1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01); 35 ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH; 36 assertEquals(-1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01); 37 num[0] = new RationalNumber(180, 1); 38 assertEquals(-180, StreetsideUtils.degMinSecToDouble(num, ref), 0.01); 39 num[0] = new RationalNumber(190, 1); 40 assertEquals(170, StreetsideUtils.degMinSecToDouble(num, ref), 0.01); 41 } 43 42 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/TestUtil.java
r36193 r36194 18 18 public final class TestUtil { 19 19 20 private TestUtil() {21 // Prevent instantiation22 }20 private TestUtil() { 21 // Prevent instantiation 22 } 23 23 24 public static Field getAccessibleField(Class<?> clazz, String fieldName) { 25 try { 26 Field result = clazz.getDeclaredField(fieldName); 27 result.setAccessible(true); 28 Field modifiers = Field.class.getDeclaredField("modifiers"); 29 modifiers.setAccessible(true); 30 modifiers.setInt(result, modifiers.getInt(result) & ~Modifier.FINAL); 31 return result; 32 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { 33 throw new JosmRuntimeException(e); 24 public static Field getAccessibleField(Class<?> clazz, String fieldName) { 25 try { 26 Field result = clazz.getDeclaredField(fieldName); 27 result.setAccessible(true); 28 Field modifiers = Field.class.getDeclaredField("modifiers"); 29 modifiers.setAccessible(true); 30 modifiers.setInt(result, modifiers.getInt(result) & ~Modifier.FINAL); 31 return result; 32 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { 33 throw new JosmRuntimeException(e); 34 } 34 35 } 35 }36 36 37 /** 38 * Helper method for obtaining the value of a private field 39 * @param object the object of which you want the private field 40 * @param name the name of the private field 41 * @return the current value that field has 42 */ 43 public static Object getPrivateFieldValue(Object object, String name) { 44 try { 45 return getAccessibleField(object.getClass(), name).get(object); 46 } catch (IllegalAccessException | SecurityException e) { 47 throw new JosmRuntimeException(e); 37 /** 38 * Helper method for obtaining the value of a private field 39 * @param object the object of which you want the private field 40 * @param name the name of the private field 41 * @return the current value that field has 42 */ 43 public static Object getPrivateFieldValue(Object object, String name) { 44 try { 45 return getAccessibleField(object.getClass(), name).get(object); 46 } catch (IllegalAccessException | SecurityException e) { 47 throw new JosmRuntimeException(e); 48 } 48 49 } 49 }50 50 51 /** 52 * This method tests utility classes for common coding standards (exactly one constructor that's private, 53 * only static methods, …) and fails the current test if one of those standards is not met. 54 * This is inspired by <a href="https://stackoverflow.com/a/10872497">an answer on StackOverflow.com</a> . 55 * @param c the class under test 56 */ 57 public static void testUtilityClass(final Class<?> c) { 58 try { 59 // class must be final 60 assertTrue(Modifier.isFinal(c.getModifiers())); 61 // with exactly one constructor 62 assertEquals(1, c.getDeclaredConstructors().length); 63 final Constructor<?> constructor = c.getDeclaredConstructors()[0]; 64 // constructor has to be private 65 assertTrue(!constructor.isAccessible() && Modifier.isPrivate(constructor.getModifiers())); 66 constructor.setAccessible(true); 67 // Call private constructor for code coverage 68 constructor.newInstance(); 69 for (Method m : c.getMethods()) { 70 // Check if all methods are static 71 assertTrue(m.getDeclaringClass() != c || Modifier.isStatic(m.getModifiers())); 72 } 73 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 74 throw new JosmRuntimeException(e); 51 /** 52 * This method tests utility classes for common coding standards (exactly one constructor that's private, 53 * only static methods, …) and fails the current test if one of those standards is not met. 54 * This is inspired by <a href="https://stackoverflow.com/a/10872497">an answer on StackOverflow.com</a> . 55 * @param c the class under test 56 */ 57 public static void testUtilityClass(final Class<?> c) { 58 try { 59 // class must be final 60 assertTrue(Modifier.isFinal(c.getModifiers())); 61 // with exactly one constructor 62 assertEquals(1, c.getDeclaredConstructors().length); 63 final Constructor<?> constructor = c.getDeclaredConstructors()[0]; 64 // constructor has to be private 65 assertTrue(!constructor.isAccessible() && Modifier.isPrivate(constructor.getModifiers())); 66 constructor.setAccessible(true); 67 // Call private constructor for code coverage 68 constructor.newInstance(); 69 for (Method m : c.getMethods()) { 70 // Check if all methods are static 71 assertTrue(m.getDeclaringClass() != c || Modifier.isStatic(m.getModifiers())); 72 } 73 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException 74 | InvocationTargetException e) { 75 throw new JosmRuntimeException(e); 76 } 75 77 } 76 }77 78 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonDecoderTest.java
r36122 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.utils.api; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertArrayEquals; … … 18 17 class JsonDecoderTest { 19 18 20 @Test21 void testUtilityClass() {22 TestUtil.testUtilityClass(JsonDecoder.class);23 }19 @Test 20 void testUtilityClass() { 21 TestUtil.testUtilityClass(JsonDecoder.class); 22 } 24 23 25 @Test26 void testDecodeDoublePair() {27 assertArrayEquals(new double[0], JsonDecoder.decodeDoublePair(null));28 }24 @Test 25 void testDecodeDoublePair() { 26 assertArrayEquals(new double[0], JsonDecoder.decodeDoublePair(null)); 27 } 29 28 30 static void assertDecodesToNull(Function<JsonObject, ?> function, String...parts) {31 assertNull(function.apply(32 Json.createReader(new ByteArrayInputStream(String.join(" ", parts).getBytes(StandardCharsets.UTF_8))).readObject()33 ));34 }29 static void assertDecodesToNull(Function<JsonObject, ?> function, String... parts) { 30 assertNull(function.apply( 31 Json.createReader(new ByteArrayInputStream(String.join(" ", parts).getBytes(StandardCharsets.UTF_8))) 32 .readObject())); 33 } 35 34 36 35 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonSequencesDecoderTest.java
r36122 r36194 29 29 class JsonSequencesDecoderTest { 30 30 31 @Disabled 32 @Test 33 void testDecodeSequences() { 34 Collection<StreetsideSequence> exampleSequences = JsonDecoder.decodeFeatureCollection( 35 Json.createReader(this.getClass().getResourceAsStream("test/data/api/v3/responses/searchSequences.json")).readObject(), 36 JsonSequencesDecoder::decodeSequence 37 ); 38 assertNotNull(exampleSequences); 39 assertEquals(1, exampleSequences.size()); 40 StreetsideSequence seq = exampleSequences.iterator().next(); 41 assertEquals(4, seq.getImages().size()); 31 @Disabled 32 @Test 33 void testDecodeSequences() { 34 Collection<StreetsideSequence> exampleSequences = JsonDecoder.decodeFeatureCollection(Json 35 .createReader(this.getClass().getResourceAsStream("test/data/api/v3/responses/searchSequences.json")) 36 .readObject(), JsonSequencesDecoder::decodeSequence); 37 assertNotNull(exampleSequences); 38 assertEquals(1, exampleSequences.size()); 39 StreetsideSequence seq = exampleSequences.iterator().next(); 40 assertEquals(4, seq.getImages().size()); 42 41 43 assertEquals("LwrHXqFRN_pszCopTKHF_Q", ((StreetsideImage) seq.getImages().get(0)).getId());44 assertEquals("Aufjv2hdCKwg9LySWWVSwg", ((StreetsideImage) seq.getImages().get(1)).getId());45 assertEquals("QEVZ1tp-PmrwtqhSwdW9fQ", ((StreetsideImage) seq.getImages().get(2)).getId());46 assertEquals("G_SIwxNcioYeutZuA8Rurw", ((StreetsideImage) seq.getImages().get(3)).getId());42 assertEquals("LwrHXqFRN_pszCopTKHF_Q", seq.getImages().get(0).getId()); 43 assertEquals("Aufjv2hdCKwg9LySWWVSwg", seq.getImages().get(1).getId()); 44 assertEquals("QEVZ1tp-PmrwtqhSwdW9fQ", seq.getImages().get(2).getId()); 45 assertEquals("G_SIwxNcioYeutZuA8Rurw", seq.getImages().get(3).getId()); 47 46 48 assertEquals(323.0319999999999, seq.getImages().get(0).getHe(), 1e-10);49 assertEquals(320.8918, seq.getImages().get(1).getHe(), 1e-10);50 assertEquals(333.62239999999997, seq.getImages().get(2).getHe(), 1e-10);51 assertEquals(329.94820000000004, seq.getImages().get(3).getHe(), 1e-10);47 assertEquals(323.0319999999999, seq.getImages().get(0).getHe(), 1e-10); 48 assertEquals(320.8918, seq.getImages().get(1).getHe(), 1e-10); 49 assertEquals(333.62239999999997, seq.getImages().get(2).getHe(), 1e-10); 50 assertEquals(329.94820000000004, seq.getImages().get(3).getHe(), 1e-10); 52 51 53 assertEquals(new LatLon(7.246497, 16.432958), seq.getImages().get(0).getLatLon());54 assertEquals(new LatLon(7.246567, 16.432955), seq.getImages().get(1).getLatLon());55 assertEquals(new LatLon(7.248372, 16.432971), seq.getImages().get(2).getLatLon());56 assertEquals(new LatLon(7.249027, 16.432976), seq.getImages().get(3).getLatLon());52 assertEquals(new LatLon(7.246497, 16.432958), seq.getImages().get(0).getLatLon()); 53 assertEquals(new LatLon(7.246567, 16.432955), seq.getImages().get(1).getLatLon()); 54 assertEquals(new LatLon(7.248372, 16.432971), seq.getImages().get(2).getLatLon()); 55 assertEquals(new LatLon(7.249027, 16.432976), seq.getImages().get(3).getLatLon()); 57 56 58 assertEquals(1_457_963_093_860L, seq.getCd()); // 2016-03-14T13:44:53.860 UTC59 }57 assertEquals(1_457_963_093_860L, seq.getCd()); // 2016-03-14T13:44:53.860 UTC 58 } 60 59 61 @Test62 void testDecodeSequencesInvalid() {63 // null input64 assertEquals(0, JsonDecoder.decodeFeatureCollection(null, JsonSequencesDecoder::decodeSequence).size());65 // empty object66 assertNumberOfDecodedSequences(0, "{}");67 // object without type=FeatureCollection68 assertNumberOfDecodedSequences(0, "{\"features\": []}");69 // object with wrong value for the type attribute70 assertNumberOfDecodedSequences(0, "{\"type\": \"SomethingArbitrary\", \"features\": []}");71 // object without features-array72 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\"}");73 // object with a value for the features-key, but wrong type (in this case string instead of Array)74 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\", \"features\": \"notAnArray\"}");75 }60 @Test 61 void testDecodeSequencesInvalid() { 62 // null input 63 assertEquals(0, JsonDecoder.decodeFeatureCollection(null, JsonSequencesDecoder::decodeSequence).size()); 64 // empty object 65 assertNumberOfDecodedSequences(0, "{}"); 66 // object without type=FeatureCollection 67 assertNumberOfDecodedSequences(0, "{\"features\": []}"); 68 // object with wrong value for the type attribute 69 assertNumberOfDecodedSequences(0, "{\"type\": \"SomethingArbitrary\", \"features\": []}"); 70 // object without features-array 71 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\"}"); 72 // object with a value for the features-key, but wrong type (in this case string instead of Array) 73 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\", \"features\": \"notAnArray\"}"); 74 } 76 75 77 @Test78 void testDecodeSequencesWithArbitraryObjectAsFeature() {79 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\", \"features\": [{}]}");80 }76 @Test 77 void testDecodeSequencesWithArbitraryObjectAsFeature() { 78 assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\", \"features\": [{}]}"); 79 } 81 80 82 private static void assertNumberOfDecodedSequences(int expectedNumberOfSequences, String jsonString) { 83 assertEquals(expectedNumberOfSequences, JsonDecoder.decodeFeatureCollection( 84 Json.createReader(new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8))).readObject(), 85 JsonSequencesDecoder::decodeSequence 86 ).size()); 87 } 81 private static void assertNumberOfDecodedSequences(int expectedNumberOfSequences, String jsonString) { 82 assertEquals(expectedNumberOfSequences, JsonDecoder.decodeFeatureCollection( 83 Json.createReader(new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8))).readObject(), 84 JsonSequencesDecoder::decodeSequence).size()); 85 } 88 86 89 @Disabled 90 @Test 91 void testDecodeSequence() { 92 StreetsideSequence exampleSequence = JsonSequencesDecoder.decodeSequence( 93 Json.createReader(this.getClass().getResourceAsStream("/api/v3/responses/sequence.json")).readObject() 94 ); 95 assertEquals("cHBf9e8n0pG8O0ZVQHGFBQ", exampleSequence.getId()); 96 assertEquals(1_457_963_077_206L, exampleSequence.getCd()); // 2016-03-14T13:44:37.206 UTC 97 assertEquals(2, exampleSequence.getImages().size()); 87 @Disabled 88 @Test 89 void testDecodeSequence() { 90 StreetsideSequence exampleSequence = JsonSequencesDecoder.decodeSequence( 91 Json.createReader(this.getClass().getResourceAsStream("/api/v3/responses/sequence.json")).readObject()); 92 assertEquals("cHBf9e8n0pG8O0ZVQHGFBQ", exampleSequence.getId()); 93 assertEquals(1_457_963_077_206L, exampleSequence.getCd()); // 2016-03-14T13:44:37.206 UTC 94 assertEquals(2, exampleSequence.getImages().size()); 98 95 99 assertEquals(new StreetsideImage("76P0YUrlDD_lF6J7Od3yoA", new LatLon(16.43279, 7.246085), 96.71454), exampleSequence.getImages().get(0)); 100 assertEquals(new StreetsideImage("Ap_8E0BwoAqqewhJaEbFyQ", new LatLon(16.432799, 7.246082), 96.47705000000002), exampleSequence.getImages().get(1)); 101 } 96 assertEquals(new StreetsideImage("76P0YUrlDD_lF6J7Od3yoA", new LatLon(16.43279, 7.246085), 96.71454), 97 exampleSequence.getImages().get(0)); 98 assertEquals(new StreetsideImage("Ap_8E0BwoAqqewhJaEbFyQ", new LatLon(16.432799, 7.246082), 96.47705000000002), 99 exampleSequence.getImages().get(1)); 100 } 102 101 103 @Test 104 void testDecodeSequenceInvalid() { 105 // null input 106 Assertions.assertNull(JsonSequencesDecoder.decodeSequence(null)); 107 // `properties` key is not set 108 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, "{\"type\": \"Feature\"}"); 109 // value for the key `key` in the properties is missing 110 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, 111 "{\"type\": \"Feature\", \"properties\": {}}" 112 ); 113 // value for the key `user_key` in the properties is missing 114 assertDecodesToNull( 115 JsonSequencesDecoder::decodeSequence, 116 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\"}}" 117 ); 118 // value for the key `captured_at` in the properties is missing 119 assertDecodesToNull( 120 JsonSequencesDecoder::decodeSequence, 121 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"user_key\": \"arbitraryUserKey\"}}" 122 ); 123 // the date in `captured_at` has an unrecognized format 124 assertDecodesToNull( 125 JsonSequencesDecoder::decodeSequence, 126 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"captured_at\": \"unrecognizedDateFormat\"}}" 127 ); 128 // the `image_key` array and the `cas` array contain unexpected values (in this case `null`) 129 assertDecodesToNull( 130 JsonSequencesDecoder::decodeSequence, 131 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"user_key\": \"arbitraryUserKey\",", 132 "\"captured_at\": \"1970-01-01T00:00:00.000Z\",", 133 "\"coordinateProperties\": {\"cas\": [null, null, null, null, 1.0, 1.0, 1.0],", 134 "\"image_keys\": [null, null, \"key\", \"key\", null, null, \"key\"]}},", 135 "\"geometry\": {\"type\": \"LineString\", \"coordinates\": [null, [1,1], null, [1,1], null, [1,1], null]}}" 136 ); 137 } 102 @Test 103 void testDecodeSequenceInvalid() { 104 // null input 105 Assertions.assertNull(JsonSequencesDecoder.decodeSequence(null)); 106 // `properties` key is not set 107 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, "{\"type\": \"Feature\"}"); 108 // value for the key `key` in the properties is missing 109 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, "{\"type\": \"Feature\", \"properties\": {}}"); 110 // value for the key `user_key` in the properties is missing 111 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, 112 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\"}}"); 113 // value for the key `captured_at` in the properties is missing 114 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, 115 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"user_key\": \"arbitraryUserKey\"}}"); 116 // the date in `captured_at` has an unrecognized format 117 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, 118 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"captured_at\": \"unrecognizedDateFormat\"}}"); 119 // the `image_key` array and the `cas` array contain unexpected values (in this case `null`) 120 assertDecodesToNull(JsonSequencesDecoder::decodeSequence, 121 "{\"type\": \"Feature\", \"properties\": {\"key\": \"someKey\", \"user_key\": \"arbitraryUserKey\",", 122 "\"captured_at\": \"1970-01-01T00:00:00.000Z\",", 123 "\"coordinateProperties\": {\"cas\": [null, null, null, null, 1.0, 1.0, 1.0],", 124 "\"image_keys\": [null, null, \"key\", \"key\", null, null, \"key\"]}},", 125 "\"geometry\": {\"type\": \"LineString\", \"coordinates\": [null, [1,1], null, [1,1], null, [1,1], null]}}"); 126 } 138 127 139 /** 140 * Checks if an empty array is returned, if <code>null</code> is supplied to the method as the array. 141 */ 142 @Test 143 void testDecodeJsonArray() 144 throws NoSuchMethodException, SecurityException, IllegalAccessException, 145 IllegalArgumentException, InvocationTargetException { 146 Method method = JsonSequencesDecoder.class.getDeclaredMethod("decodeJsonArray", JsonArray.class, Function.class, Class.class); 147 method.setAccessible(true); 148 assertEquals(0, ((String[]) method.invoke(null, null, (Function<JsonValue, String>) val -> null, String.class)).length); 149 } 128 /** 129 * Checks if an empty array is returned, if <code>null</code> is supplied to the method as the array. 130 */ 131 @Test 132 void testDecodeJsonArray() throws NoSuchMethodException, SecurityException, IllegalAccessException, 133 IllegalArgumentException, InvocationTargetException { 134 Method method = JsonSequencesDecoder.class.getDeclaredMethod("decodeJsonArray", JsonArray.class, Function.class, 135 Class.class); 136 method.setAccessible(true); 137 assertEquals(0, 138 ((String[]) method.invoke(null, null, (Function<JsonValue, String>) val -> null, String.class)).length); 139 } 150 140 151 @Test 152 void testDecodeCoordinateProperty() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 153 Method decodeCoordinateProperty = JsonSequencesDecoder.class.getDeclaredMethod( 154 "decodeCoordinateProperty", 155 JsonObject.class, 156 String.class, 157 Function.class, 158 Class.class 159 ); 160 decodeCoordinateProperty.setAccessible(true); 141 @Test 142 void testDecodeCoordinateProperty() throws NoSuchMethodException, SecurityException, IllegalAccessException, 143 IllegalArgumentException, InvocationTargetException { 144 Method decodeCoordinateProperty = JsonSequencesDecoder.class.getDeclaredMethod("decodeCoordinateProperty", 145 JsonObject.class, String.class, Function.class, Class.class); 146 decodeCoordinateProperty.setAccessible(true); 161 147 162 assertEquals(0, ((String[]) decodeCoordinateProperty.invoke( 163 null, null, "key", (Function<JsonValue, String>) val -> "string", String.class 164 )).length); 148 assertEquals(0, ((String[]) decodeCoordinateProperty.invoke(null, null, "key", 149 (Function<JsonValue, String>) val -> "string", String.class)).length); 165 150 166 assertEquals(0, ((String[]) decodeCoordinateProperty.invoke( 167 null, JsonUtil.string2jsonObject("{\"coordinateProperties\":{\"key\":0}}"), "key", (Function<JsonValue, String>) val -> "string", String.class 168 )).length); 169 } 151 assertEquals(0, 152 ((String[]) decodeCoordinateProperty.invoke(null, 153 JsonUtil.string2jsonObject("{\"coordinateProperties\":{\"key\":0}}"), "key", 154 (Function<JsonValue, String>) val -> "string", String.class)).length); 155 } 170 156 171 @Test 172 void testDecodeLatLons() 173 throws NoSuchMethodException, SecurityException, IllegalAccessException, 174 IllegalArgumentException, InvocationTargetException { 175 Method decodeLatLons = JsonSequencesDecoder.class.getDeclaredMethod("decodeLatLons", JsonObject.class); 176 decodeLatLons.setAccessible(true); 157 @Test 158 void testDecodeLatLons() throws NoSuchMethodException, SecurityException, IllegalAccessException, 159 IllegalArgumentException, InvocationTargetException { 160 Method decodeLatLons = JsonSequencesDecoder.class.getDeclaredMethod("decodeLatLons", JsonObject.class); 161 decodeLatLons.setAccessible(true); 177 162 178 assertEquals(0, ((LatLon[]) decodeLatLons.invoke(null, (JsonObject) null)).length); 179 assertEquals(0, ((LatLon[]) decodeLatLons.invoke(null, JsonUtil.string2jsonObject("{\"coordinates\":0}"))).length); 180 assertEquals(0, ((LatLon[]) decodeLatLons.invoke(null, JsonUtil.string2jsonObject("{\"coordinates\":[]}"))).length); 163 assertEquals(0, ((LatLon[]) decodeLatLons.invoke(null, (JsonObject) null)).length); 164 assertEquals(0, 165 ((LatLon[]) decodeLatLons.invoke(null, JsonUtil.string2jsonObject("{\"coordinates\":0}"))).length); 166 assertEquals(0, 167 ((LatLon[]) decodeLatLons.invoke(null, JsonUtil.string2jsonObject("{\"coordinates\":[]}"))).length); 181 168 182 assertEquals(0, ((LatLon[]) decodeLatLons.invoke(null, Json.createReader(new ByteArrayInputStream( 183 "{\"type\": \"Feature\", \"coordinates\": []}".getBytes(StandardCharsets.UTF_8) 184 )).readObject())).length); 169 assertEquals(0, 170 ((LatLon[]) decodeLatLons.invoke(null, 171 Json.createReader(new ByteArrayInputStream( 172 "{\"type\": \"Feature\", \"coordinates\": []}".getBytes(StandardCharsets.UTF_8))) 173 .readObject())).length); 185 174 186 LatLon[] example = (LatLon[]) decodeLatLons.invoke(null, Json.createReader(new ByteArrayInputStream( 187 "{\"type\": \"LineString\", \"coordinates\": [ [1,2,3], [\"a\", 2], [1, \"b\"] ]}".getBytes(StandardCharsets.UTF_8) 188 )).readObject()); 189 assertEquals(3, example.length); 190 Assertions.assertNull(example[0]); 191 Assertions.assertNull(example[1]); 192 Assertions.assertNull(example[2]); 193 } 175 LatLon[] example = (LatLon[]) decodeLatLons.invoke(null, 176 Json.createReader(new ByteArrayInputStream( 177 "{\"type\": \"LineString\", \"coordinates\": [ [1,2,3], [\"a\", 2], [1, \"b\"] ]}" 178 .getBytes(StandardCharsets.UTF_8))) 179 .readObject()); 180 assertEquals(3, example.length); 181 Assertions.assertNull(example[0]); 182 Assertions.assertNull(example[1]); 183 Assertions.assertNull(example[2]); 184 } 194 185 195 @Test196 void testUtilityClass() {197 TestUtil.testUtilityClass(JsonSequencesDecoder.class);198 }186 @Test 187 void testUtilityClass() { 188 TestUtil.testUtilityClass(JsonSequencesDecoder.class); 189 } 199 190 200 191 }
Note:
See TracChangeset
for help on using the changeset viewer.