Changeset 8876 in josm for trunk/test/unit


Ignore:
Timestamp:
2015-10-14T23:35:44+02:00 (9 years ago)
Author:
Don-vip
Message:

cleanup unit tests

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/CopyActionTest.java

    r8857 r8876  
    2626    }
    2727
     28    /**
     29     * Test of {@link CopyAction#getCopyString} method for a single way.
     30     */
    2831    @Test
    29     public void testCopyStringWay() throws Exception {
     32    public void testCopyStringWay() {
    3033        final Way way = new Way(123L);
    3134        assertEquals("way 123", CopyAction.getCopyString(Collections.singleton(way)));
    3235    }
    3336
     37    /**
     38     * Test of {@link CopyAction#getCopyString} method for a way and a relation.
     39     */
    3440    @Test
    35     public void testCopyStringWayRelation() throws Exception {
     41    public void testCopyStringWayRelation() {
    3642        final Way way = new Way(123L);
    3743        final Relation relation = new Relation(456);
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r8857 r8876  
    44import static org.junit.Assert.assertSame;
    55import static org.junit.Assert.assertTrue;
     6import static org.junit.Assert.fail;
    67
    78import java.awt.geom.Area;
     
    5051     * I don't know why, but in other tests there are no problem to add selected primitives
    5152     * but in this case there is a problem with an even listener of selection change.
     53     * @param p primitive
     54     * @param ds data set
    5255     */
    5356    public void addSelected(OsmPrimitive p, DataSet ds) {
     
    6063        } catch (Exception e) {
    6164            e.printStackTrace();
    62             assertTrue("Can't add OsmPrimitive to dataset", false);
     65            fail("Can't add OsmPrimitive to dataset: " + e.getMessage());
    6366        }
    6467    }
     
    162165        } catch (Exception e) {
    163166            e.printStackTrace();
    164             assertTrue("Impossible to mock left/right hand database", false);
     167            fail("Impossible to mock left/right hand database: " + e.getMessage());
    165168        }
    166169
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r8857 r8876  
    4242     */
    4343    @Test
    44     public void test11184() throws Exception {
     44    public void testTicket11184() {
    4545        DataSet dataSet = new DataSet();
    4646        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r8510 r8876  
    1010import java.io.InputStreamReader;
    1111import java.net.HttpURLConnection;
    12 import java.net.MalformedURLException;
    1312import java.net.URL;
    1413import java.nio.charset.StandardCharsets;
     
    112111    /**
    113112     * Tests that sending an HTTP request without command results in HTTP 400, with all available commands in error message.
    114      * @throws IOException if an I/O error occurs
    115      * @throws MalformedURLException if HTTP URL is invalid
    116113     */
    117114    @Test
    118     public void testHttpListOfCommands() throws MalformedURLException, IOException {
     115    public void testHttpListOfCommands() {
    119116        testListOfCommands(httpBase);
    120117    }
     
    122119    /**
    123120     * Tests that sending an HTTPS request without command results in HTTP 400, with all available commands in error message.
    124      * @throws IOException if an I/O error occurs
    125      * @throws MalformedURLException if HTTPS URL is invalid
    126121     */
    127122    @Test
    128     public void testHttpsListOfCommands() throws MalformedURLException, IOException {
     123    public void testHttpsListOfCommands() {
    129124        testListOfCommands(httpsBase);
    130125    }
    131126
    132     private void testListOfCommands(String url) throws MalformedURLException, IOException {
    133         HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    134         connection.connect();
    135         assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
    136         try (InputStream is = connection.getErrorStream()) {
    137             // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
    138             StringBuilder responseBody = new StringBuilder();
    139             try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    140                 String s;
    141                 while ((s = in.readLine()) != null) {
    142                     responseBody.append(s);
    143                     responseBody.append("\n");
     127    private void testListOfCommands(String url) {
     128        try {
     129            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
     130            connection.connect();
     131            assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
     132            try (InputStream is = connection.getErrorStream()) {
     133                // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
     134                StringBuilder responseBody = new StringBuilder();
     135                try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
     136                    String s;
     137                    while ((s = in.readLine()) != null) {
     138                        responseBody.append(s);
     139                        responseBody.append("\n");
     140                    }
    144141                }
     142                assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
     143            } catch (IllegalAccessException | InstantiationException e) {
     144                e.printStackTrace();
     145                fail(e.getMessage());
    145146            }
    146             assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
    147         } catch (IllegalAccessException e) {
    148             fail(e.getMessage());
    149         } catch (InstantiationException e) {
     147        } catch (IOException e) {
     148            e.printStackTrace();
    150149            fail(e.getMessage());
    151150        }
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java

    r8857 r8876  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
    4 import static org.junit.Assert.assertThat;
     4import static org.junit.Assert.assertEquals;
    55
    6 import org.hamcrest.CoreMatchers;
    76import org.junit.Test;
    87
     
    1211public class ImportHandlerTest {
    1312
     13    /**
     14     * Non-regression test for bug #7434.
     15     */
    1416    @Test
    15     public void test7434() throws Exception {
    16 
     17    public void testTicket7434() {
    1718        final ImportHandler req = new ImportHandler();
    1819        req.setUrl("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive");
    19         assertThat(req.args.get("url"), CoreMatchers.is("http://localhost:8888/relations?relations=19711&mode=recursive"));
     20        assertEquals("http://localhost:8888/relations?relations=19711&mode=recursive", req.args.get("url"));
    2021    }
    2122}
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandlerTest.java

    r8857 r8876  
    4545    }
    4646
     47    /**
     48     * Test request parameter - case 1
     49     */
    4750    @Test
    4851    public void testRequestParameter1() {
     
    5356    }
    5457
     58    /**
     59     * Test request parameter - case 2
     60     */
    5561    @Test
    56     public void testRequestParameter12() {
     62    public void testRequestParameter2() {
    5763        assertEquals(Collections.singletonMap("query", "a&b==c"),
    5864                getRequestParameter("http://example.com/?query=a%26b==c"));
    5965    }
    6066
     67    /**
     68     * Test request parameter - case 3
     69     */
    6170    @Test
    6271    public void testRequestParameter3() {
     
    6675
    6776    /**
     77     * Test request parameter - case 4
    6878     * @see <a href="http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding">
    6979     *      What every web developer must know about URL encoding</a>
     
    7787    }
    7888
     89    /**
     90     * Test request parameter - case 5
     91     */
    7992    @Test
    8093    public void testRequestParameter5() {
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionReaderTest.java

    r8857 r8876  
    114114    }
    115115
     116    /**
     117     * Tests to read a .jos file containing Bing imagery.
     118     * @throws IOException if any I/O error occurs
     119     * @throws IllegalDataException is the test file is considered as invalid
     120     */
    116121    @Test
    117122    public void testReadImage() throws IOException, IllegalDataException {
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r8837 r8876  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.session;
     3
     4import static org.junit.Assert.fail;
    35
    46import java.io.File;
     
    8587    }
    8688
    87     private void testWrite(List<Layer> layers, final boolean zip) throws IOException {
     89    private void testWrite(List<Layer> layers, final boolean zip) {
    8890        Map<Layer, SessionLayerExporter> exporters = new HashMap<>();
    8991        if (zip) {
     
    101103        try {
    102104            sw.write(file);
     105        } catch (IOException e) {
     106            e.printStackTrace();
     107            fail(e.getMessage());
    103108        } finally {
    104109            if (file.exists()) {
     
    135140    /**
    136141     * Tests to write an empty .jos file.
    137      * @throws IOException if any I/O error occurs
    138      */
    139     @Test
    140     public void testWriteEmptyJos() throws IOException {
     142     */
     143    @Test
     144    public void testWriteEmptyJos() {
    141145        testWrite(Collections.<Layer>emptyList(), false);
    142146    }
     
    144148    /**
    145149     * Tests to write an empty .joz file.
    146      * @throws IOException if any I/O error occurs
    147      */
    148     @Test
    149     public void testWriteEmptyJoz() throws IOException {
     150     */
     151    @Test
     152    public void testWriteEmptyJoz() {
    150153        testWrite(Collections.<Layer>emptyList(), true);
    151154    }
     
    153156    /**
    154157     * Tests to write a .jos file containing OSM data.
    155      * @throws IOException if any I/O error occurs
    156      */
    157     @Test
    158     public void testWriteOsmJos() throws IOException {
     158     */
     159    @Test
     160    public void testWriteOsmJos() {
    159161        testWrite(Collections.<Layer>singletonList(createOsmLayer()), false);
    160162    }
     
    162164    /**
    163165     * Tests to write a .joz file containing OSM data.
    164      * @throws IOException if any I/O error occurs
    165      */
    166     @Test
    167     public void testWriteOsmJoz() throws IOException {
     166     */
     167    @Test
     168    public void testWriteOsmJoz() {
    168169        testWrite(Collections.<Layer>singletonList(createOsmLayer()), true);
    169170    }
     
    171172    /**
    172173     * Tests to write a .jos file containing GPX data.
    173      * @throws IOException if any I/O error occurs
    174      */
    175     @Test
    176     public void testWriteGpxJos() throws IOException {
     174     */
     175    @Test
     176    public void testWriteGpxJos() {
    177177        testWrite(Collections.<Layer>singletonList(createGpxLayer()), false);
    178178    }
     
    180180    /**
    181181     * Tests to write a .joz file containing GPX data.
    182      * @throws IOException if any I/O error occurs
    183      */
    184     @Test
    185     public void testWriteGpxJoz() throws IOException {
     182     */
     183    @Test
     184    public void testWriteGpxJoz() {
    186185        testWrite(Collections.<Layer>singletonList(createGpxLayer()), true);
    187186    }
     
    189188    /**
    190189     * Tests to write a .joz file containing GPX and marker data.
    191      * @throws IOException if any I/O error occurs
    192      */
    193     @Test
    194     public void testWriteGpxAndMarkerJoz() throws IOException {
     190     */
     191    @Test
     192    public void testWriteGpxAndMarkerJoz() {
    195193        GpxLayer gpx = createGpxLayer();
    196194        testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     
    199197    /**
    200198     * Tests to write a .joz file containing an imagery layer.
    201      * @throws IOException if any I/O error occurs
    202      */
    203     @Test
    204     public void testWriteImageryLayer() throws IOException {
     199     */
     200    @Test
     201    public void testWriteImageryLayer() {
    205202        final Layer layer = createImageryLayer();
    206203        testWrite(Collections.singletonList(layer), true);
  • trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java

    r8549 r8876  
    2121    }
    2222
     23    /**
     24     * Test of {@link Geometry#getLineLineIntersection} method.
     25     */
    2326    @Test
    2427    public void testLineLineIntersection() {
  • trunk/test/unit/org/openstreetmap/josm/tools/OverpassTurboQueryWizardTest.java

    r8857 r8876  
    2222    }
    2323
     24    /**
     25     * Test key=value.
     26     */
    2427    @Test
    2528    public void testKeyValue() {
     
    4043    }
    4144
     45    /**
     46     * Test erroneous value.
     47     */
    4248    @Test(expected = OverpassTurboQueryWizard.ParseException.class)
    4349    public void testErroneous() {
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r8857 r8876  
    1010 */
    1111public class DateUtilsTest {
     12
     13    /**
     14     * Test to parse date as returned for map data.
     15     */
    1216    @Test
    13     public void testMapDate() throws Exception {
     17    public void testMapDate() {
    1418        assertEquals(1344870637000L, DateUtils.fromString("2012-08-13T15:10:37Z").getTime());
    15 
    1619    }
    1720
     21    /**
     22     * Test to parse date as returned for note data.
     23     */
    1824    @Test
    19     public void testNoteDate() throws Exception {
     25    public void testNoteDate() {
    2026        assertEquals(1417298930000L, DateUtils.fromString("2014-11-29 22:08:50 UTC").getTime());
    2127    }
Note: See TracChangeset for help on using the changeset viewer.