Changeset 10937 in josm for trunk


Ignore:
Timestamp:
2016-09-03T12:24:18+02:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S3658 - Unit tests should throw exceptions

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r10908 r10937  
    1717        <classpathentry kind="lib" path="test/lib/equalsverifier-2.1.5.jar"/>
    1818        <classpathentry kind="lib" path="test/lib/reflections/reflections-0.9.10.jar"/>
     19        <classpathentry kind="lib" path="test/lib/reflections/guava-19.0.jar"/>
     20        <classpathentry kind="lib" path="test/lib/reflections/javassist-3.20.0-GA.jar"/>
    1921        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_102"/>
    2022        <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r10758 r10937  
    66import static org.junit.Assert.assertNotNull;
    77import static org.junit.Assert.assertTrue;
    8 import static org.junit.Assert.fail;
    98
    109import java.io.File;
     
    4039import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    4140
     41/**
     42 * Unit tests of {@link MultiFetchServerObjectReader}.
     43 */
    4244public class MultiFetchServerObjectReaderTest {
    4345    private static Logger logger = Logger.getLogger(MultiFetchServerObjectReader.class.getName());
     
    138140    }
    139141
     142    /**
     143     * Setup test.
     144     * @throws Exception if an error occurs
     145     */
    140146    @BeforeClass
    141     public static void init() throws OsmTransferException {
     147    public static void init() throws Exception {
    142148        logger.info("initializing ...");
    143149        JOSMFixture.createFunctionalTestFixture().init();
     
    177183                w.footer();
    178184            }
    179         } catch (IOException e) {
    180             fail(MessageFormat.format("failed to open file ''{0}'' for writing", dataSetCacheOutputFile.toString()));
    181185        }
    182186    }
     
    200204    }
    201205
     206    /**
     207     * Test to multi-get 10 nodes.
     208     * @throws OsmTransferException if an error occurs
     209     */
    202210    @Test
    203211    public void testMultiGet10Nodes() throws OsmTransferException {
     
    217225    }
    218226
     227    /**
     228     * Test to multi-get 10 ways.
     229     * @throws OsmTransferException if an error occurs
     230     */
    219231    @Test
    220232    public void testMultiGet10Ways() throws OsmTransferException {
     
    235247    }
    236248
     249    /**
     250     * Test to multi-get 10 relations.
     251     * @throws OsmTransferException if an error occurs
     252     */
    237253    @Test
    238254    public void testMultiGet10Relations() throws OsmTransferException {
     
    253269    }
    254270
     271    /**
     272     * Test to multi-get 800 nodes.
     273     * @throws OsmTransferException if an error occurs
     274     */
    255275    @Test
    256276    public void testMultiGet800Nodes() throws OsmTransferException {
     
    270290    }
    271291
     292    /**
     293     * Test to multi-get non-existing node.
     294     * @throws OsmTransferException if an error occurs
     295     */
    272296    @Test
    273297    public void testMultiGetWithNonExistingNode() throws OsmTransferException {
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r10758 r10937  
    151151     * @throws OsmTransferException if something goes wrong
    152152     * @throws CyclicUploadDependencyException if a cyclic dependency is detected
     153     * @throws IOException if an I/O error occurs
    153154     */
    154155    @BeforeClass
    155     public static void setUpBeforeClass() throws OsmTransferException, CyclicUploadDependencyException {
     156    public static void setUpBeforeClass() throws OsmTransferException, CyclicUploadDependencyException, IOException {
    156157        logger.info("initializing ...");
    157158
     
    196197                w.footer();
    197198            }
    198         } catch (IOException e) {
    199             fail(MessageFormat.format("failed to open file ''{0}'' for writing", dataSetCacheOutputFile.toString()));
    200199        }
    201200    }
     
    219218    }
    220219
     220    /**
     221     * Test reading references for a node.
     222     * @throws OsmTransferException if an error occurs
     223     */
    221224    @Test
    222225    public void testBackreferenceForNode() throws OsmTransferException {
     
    272275    }
    273276
     277    /**
     278     * Test reading full references for a node.
     279     * @throws OsmTransferException if an error occurs
     280     */
    274281    @Test
    275282    public void testBackreferenceForNodeFull() throws OsmTransferException {
     
    316323    }
    317324
     325    /**
     326     * Test reading references for a way.
     327     * @throws OsmTransferException if an error occurs
     328     */
    318329    @Test
    319330    public void testBackreferenceForWay() throws OsmTransferException {
     
    356367    }
    357368
     369    /**
     370     * Test reading full references for a way.
     371     * @throws OsmTransferException if an error occurs
     372     */
    358373    @Test
    359374    public void testBackreferenceForWayFull() throws OsmTransferException {
     
    390405    }
    391406
     407    /**
     408     * Test reading references for a relation.
     409     * @throws OsmTransferException if an error occurs
     410     */
    392411    @Test
    393412    public void testBackreferenceForRelation() throws OsmTransferException {
     
    505524    }
    506525
     526    /**
     527     * Test reading full references for a relation.
     528     * @throws OsmTransferException if an error occurs
     529     */
    507530    @Test
    508531    public void testBackreferenceForRelationFull() throws OsmTransferException {
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r10758 r10937  
    44import static org.junit.Assert.assertSame;
    55import static org.junit.Assert.assertTrue;
    6 import static org.junit.Assert.fail;
    76
    87import java.awt.geom.Area;
     
    5453     * @param p primitive
    5554     * @param ds data set
     55     * @throws ReflectiveOperationException if an error occurs
    5656     */
    57     public void addSelected(OsmPrimitive p, DataSet ds) {
    58         try {
    59             Method method = ds.getClass()
    60                 .getDeclaredMethod("addSelected",
    61                                    new Class<?>[] {Collection.class, boolean.class});
    62             Utils.setObjectsAccessible(method);
    63             method.invoke(ds, Collections.singleton(p), false);
    64         } catch (ReflectiveOperationException e) {
    65             e.printStackTrace();
    66             fail("Can't add OsmPrimitive to dataset: " + e.getMessage());
    67         }
     57    public void addSelected(OsmPrimitive p, DataSet ds) throws ReflectiveOperationException {
     58        Method method = ds.getClass().getDeclaredMethod("addSelected",
     59                                                        new Class<?>[] {Collection.class, boolean.class});
     60        Utils.setObjectsAccessible(method);
     61        method.invoke(ds, Collections.singleton(p), false);
    6862    }
    6963
     
    7266     * circle direction must equals way direction.
    7367     * see #7421
     68     * @throws ReflectiveOperationException if an error occurs
    7469     */
    7570    @Test
    76     public void testTicket7421case0() {
     71    public void testTicket7421case0() throws ReflectiveOperationException {
    7772        DataSet dataSet = new DataSet();
    7873        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
     
    137132     * circle direction depend on traffic hand. Simulate a left hand traffic.
    138133     * see #7421
     134     * @throws ReflectiveOperationException if an error occurs
    139135     */
    140136    @Test
    141     public void testTicket7421case1() {
     137    public void testTicket7421case1() throws ReflectiveOperationException {
    142138        DataSet dataSet = new DataSet();
    143139        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
     
    155151
    156152        // Mock left/right hand traffic database
    157         try {
    158             Field leftHandTrafficPolygons = RightAndLefthandTraffic.class
    159                 .getDeclaredField("leftHandTrafficPolygons");
    160             Field rlCache = RightAndLefthandTraffic.class.getDeclaredField("rlCache");
    161             Utils.setObjectsAccessible(leftHandTrafficPolygons, rlCache);
    162             leftHandTrafficPolygons.set(null, new ArrayList<Area>());
    163             rlCache.set(null, new GeoPropertyIndex<>(new ConstantTrafficHand(true), 24));
    164         } catch (ReflectiveOperationException e) {
    165             e.printStackTrace();
    166             fail("Impossible to mock left/right hand database: " + e.getMessage());
    167         }
     153        Field leftHandTrafficPolygons = RightAndLefthandTraffic.class
     154            .getDeclaredField("leftHandTrafficPolygons");
     155        Field rlCache = RightAndLefthandTraffic.class.getDeclaredField("rlCache");
     156        Utils.setObjectsAccessible(leftHandTrafficPolygons, rlCache);
     157        leftHandTrafficPolygons.set(null, new ArrayList<Area>());
     158        rlCache.set(null, new GeoPropertyIndex<>(new ConstantTrafficHand(true), 24));
    168159
    169160        CreateCircleAction action = new CreateCircleAction();
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r10876 r10937  
    55import static org.junit.Assert.assertSame;
    66import static org.junit.Assert.assertTrue;
    7 import static org.junit.Assert.fail;
    87
    98import java.awt.event.InputEvent;
     
    3534
    3635    class SelectActionMock extends SelectAction {
    37         SelectActionMock(MapFrame mapFrame, DataSet dataSet, OsmDataLayer layer) {
     36        SelectActionMock(MapFrame mapFrame, DataSet dataSet, OsmDataLayer layer) throws ReflectiveOperationException {
    3837            super(mapFrame);
    39             try {
    40                 Field mv = SelectAction.class.getDeclaredField("mv");
    41                 Utils.setObjectsAccessible(mv);
    42                 mv.set(this, new MapViewMock());
    43             } catch (ReflectiveOperationException e) {
    44                 e.printStackTrace();
    45                 fail("Can't setup testing environnement");
    46             }
     38            Field mv = SelectAction.class.getDeclaredField("mv");
     39            Utils.setObjectsAccessible(mv);
     40            mv.set(this, new MapViewMock());
    4741        }
    4842
     
    6862     * Resulting way should be attach to the third node.
    6963     * see #10748
     64     * @throws ReflectiveOperationException if an error occurs
    7065     */
    7166    @Test
    7267    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    73     public void testTicket10748() {
     68    public void testTicket10748() throws ReflectiveOperationException {
    7469        DataSet dataSet = new DataSet();
    7570        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java

    r10758 r10937  
    2828
    2929    @Test
    30     public void testOneNewRelationOnly() {
     30    public void testOneNewRelationOnly() throws CyclicUploadDependencyException {
    3131        Relation r = new Relation();
    3232        r.put("name", "r1");
     
    3636        APIDataSet apiDataSet = new APIDataSet();
    3737        apiDataSet.init(ds);
    38         try {
    39             apiDataSet.adjustRelationUploadOrder();
    40         } catch (CyclicUploadDependencyException e) {
    41             fail("unexpected exception:" + e);
    42         }
     38        apiDataSet.adjustRelationUploadOrder();
    4339        List<OsmPrimitive> toAdd = apiDataSet.getPrimitivesToAdd();
    4440
     
    4844
    4945    @Test
    50     public void testNewParentChildPair() {
    51         DataSet ds = new DataSet();
    52         Relation r1 = new Relation();
    53         ds.addPrimitive(r1);
    54         r1.put("name", "r1");
    55 
    56         Relation r2 = new Relation();
    57         ds.addPrimitive(r2);
    58         r2.put("name", "r2");
    59 
    60         r1.addMember(new RelationMember("", r2));
    61 
    62         APIDataSet apiDataSet = new APIDataSet();
    63         apiDataSet.init(ds);
    64         try {
    65             apiDataSet.adjustRelationUploadOrder();
    66         } catch (CyclicUploadDependencyException e) {
    67             fail("unexpected exception:" + e);
    68         }
     46    public void testNewParentChildPair() throws CyclicUploadDependencyException {
     47        DataSet ds = new DataSet();
     48        Relation r1 = new Relation();
     49        ds.addPrimitive(r1);
     50        r1.put("name", "r1");
     51
     52        Relation r2 = new Relation();
     53        ds.addPrimitive(r2);
     54        r2.put("name", "r2");
     55
     56        r1.addMember(new RelationMember("", r2));
     57
     58        APIDataSet apiDataSet = new APIDataSet();
     59        apiDataSet.init(ds);
     60        apiDataSet.adjustRelationUploadOrder();
    6961        List<OsmPrimitive> toAdd = apiDataSet.getPrimitivesToAdd();
    7062
     
    7567
    7668    @Test
    77     public void testOneExistingAndThreNewInAChain() {
     69    public void testOneExistingAndThreNewInAChain() throws CyclicUploadDependencyException {
    7870        DataSet ds = new DataSet();
    7971
     
    10092        APIDataSet apiDataSet = new APIDataSet();
    10193        apiDataSet.init(ds);
    102         try {
    103             apiDataSet.adjustRelationUploadOrder();
    104         } catch (CyclicUploadDependencyException e) {
    105             fail("unexpected exception:" + e);
    106         }
     94        apiDataSet.adjustRelationUploadOrder();
    10795        List<OsmPrimitive> toAdd = apiDataSet.getPrimitivesToAdd();
    10896
     
    118106
    119107    @Test
    120     public void testOneParentTwoNewChildren() {
     108    public void testOneParentTwoNewChildren() throws CyclicUploadDependencyException {
    121109        DataSet ds = new DataSet();
    122110        Relation r1 = new Relation();
     
    138126        APIDataSet apiDataSet = new APIDataSet();
    139127        apiDataSet.init(ds);
    140         try {
    141             apiDataSet.adjustRelationUploadOrder();
    142         } catch (CyclicUploadDependencyException e) {
    143             fail("unexpected exception:" + e);
    144         }
     128        apiDataSet.adjustRelationUploadOrder();
    145129        List<OsmPrimitive> toAdd = apiDataSet.getPrimitivesToAdd();
    146130
     
    151135
    152136    @Test // for ticket #9624
    153     public void testDeleteOneParentTwoNewChildren() {
     137    public void testDeleteOneParentTwoNewChildren() throws CyclicUploadDependencyException {
    154138        DataSet ds = new DataSet();
    155139        Relation r1 = new Relation(1);
     
    185169        apiDataSet.getPrimitivesToDelete().add(r3);
    186170        apiDataSet.getPrimitivesToDelete().add(r4);
    187         try {
    188             apiDataSet.adjustRelationUploadOrder();
    189         } catch (CyclicUploadDependencyException e) {
    190             fail("unexpected exception:" + e);
    191         }
     171        apiDataSet.adjustRelationUploadOrder();
    192172        List<OsmPrimitive> toDelete = apiDataSet.getPrimitivesToDelete();
    193173
     
    198178
    199179    @Test // for ticket #9656
    200     public void testDeleteWay() {
     180    public void testDeleteWay() throws CyclicUploadDependencyException {
    201181        DataSet ds = new DataSet();
    202182        final Way way = new Way(1, 2);
     
    225205        APIDataSet apiDataSet = new APIDataSet();
    226206        apiDataSet.init(ds);
    227         try {
    228             apiDataSet.adjustRelationUploadOrder();
    229         } catch (CyclicUploadDependencyException e) {
    230             fail("unexpected exception:" + e);
    231         }
     207        apiDataSet.adjustRelationUploadOrder();
    232208        List<OsmPrimitive> toDelete = apiDataSet.getPrimitivesToDelete();
    233209
  • trunk/test/unit/org/openstreetmap/josm/gui/TableCellRendererTest.java

    r10758 r10937  
    22package org.openstreetmap.josm.gui;
    33
     4import static org.junit.Assert.assertNotNull;
     5
    46import java.lang.reflect.Constructor;
    5 import java.lang.reflect.InvocationTargetException;
    67import java.lang.reflect.Modifier;
    78import java.util.Arrays;
     
    5354    /**
    5455     * Unit test of all table cell renderers against null values.
     56     * @throws NoSuchMethodException no default constructor - to fix this, add a default constructor to the class
     57     *                               or add the class to the SKIP_TEST list above
     58     * @throws ReflectiveOperationException if an error occurs
    5559     */
    5660    @Test
    57     public void testTableCellRenderer() {
     61    public void testTableCellRenderer() throws ReflectiveOperationException {
    5862        Reflections reflections = new Reflections("org.openstreetmap.josm");
    5963        Set<Class<? extends TableCellRenderer>> renderers = reflections.getSubTypesOf(TableCellRenderer.class);
     
    6771                continue;
    6872            }
    69             TableCellRenderer tcr = createInstance(klass);
    70             try {
    71                 tcr.getTableCellRendererComponent(tbl, null, false, false, 0, 0);
    72             } catch (NullPointerException npe) {
    73                 npe.printStackTrace();
    74                 Assert.fail("NPE in getTableCellRendererComponent");
    75             }
     73            assertNotNull(createInstance(klass).getTableCellRendererComponent(tbl, null, false, false, 0, 0));
    7674        }
    7775    }
     
    8280     * @param klass the class
    8381     * @return an instance of the class
     82     * @throws NoSuchMethodException no default constructor - to fix this, add a default constructor to the class
     83     *                               or add the class to the SKIP_TEST list above
     84     * @throws ReflectiveOperationException if an error occurs
    8485     */
    85     private static <T> T createInstance(Class<? extends T> klass) {
     86    private static <T> T createInstance(Class<? extends T> klass) throws ReflectiveOperationException {
    8687        boolean needOuterClass = klass.isMemberClass() && !Modifier.isStatic(klass.getModifiers());
    8788        Constructor<? extends T> c;
    88         try {
    89             if (needOuterClass) {
    90                 c = klass.getDeclaredConstructor(klass.getDeclaringClass());
    91             } else {
    92                 c = klass.getDeclaredConstructor();
    93             }
    94         } catch (NoSuchMethodException ex) {
    95             // no default constructor - to fix this, add a default constructor
    96             // to the class or add the class to the SKIP_TEST list above
    97             Assert.fail("No default constructor - cannot test TableCellRenderer: " + ex);
    98             return null;
    99         } catch (SecurityException ex) {
    100             throw new RuntimeException(ex);
     89        if (needOuterClass) {
     90            c = klass.getDeclaredConstructor(klass.getDeclaringClass());
     91        } else {
     92            c = klass.getDeclaredConstructor();
    10193        }
    10294        Utils.setObjectsAccessible(c);
    103         T o;
    104         try {
    105             if (needOuterClass) {
    106                 Object outerInstance = createInstance(klass.getDeclaringClass());
    107                 o = c.newInstance(outerInstance);
    108             } else {
    109                 o = c.newInstance();
    110             }
    111         } catch (InstantiationException | IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {
    112             throw new RuntimeException(ex);
     95        if (needOuterClass) {
     96            return c.newInstance(createInstance(klass.getDeclaringClass()));
     97        } else {
     98            return c.newInstance();
    11399        }
    114         return o;
    115100    }
    116 
    117101}
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModelTest.java

    r10846 r10937  
    6161                break;
    6262            }
    63             try {
    64                 int[] rows = (int[]) idx[i];
    65                 if (rows.length != 2) {
    66                     fail("illegal selection range. Either null or not length 2: " + Arrays.toString(rows));
    67                 }
    68                 if (rows[0] > rows[1]) {
    69                     fail("illegal selection range. lower bound > upper bound ");
    70                 }
    71                 for (int j = rows[0]; j <= rows[1]; j++) {
    72                     assertTrue("expected row " + j + " to be selected", model.isSelectedIndex(j));
    73                 }
    74             } catch (ClassCastException e) {
    75                 fail("illegal selection range:" + idx[i]);
     63            int[] rows = (int[]) idx[i];
     64            if (rows.length != 2) {
     65                fail("illegal selection range. Either null or not length 2: " + Arrays.toString(rows));
     66            }
     67            if (rows[0] > rows[1]) {
     68                fail("illegal selection range. lower bound > upper bound ");
     69            }
     70            for (int j = rows[0]; j <= rows[1]; j++) {
     71                assertTrue("expected row " + j + " to be selected", model.isSelectedIndex(j));
    7672            }
    7773        }
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r10339 r10937  
    33
    44import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.fail;
    65
    76import java.io.BufferedReader;
     
    4140    /**
    4241     * Starts Remote control before testing requests.
     42     * @throws GeneralSecurityException if a security error occurs
    4343     */
    4444    @Before
    45     public void setUp() {
     45    public void setUp() throws GeneralSecurityException {
    4646        JOSMFixture.createUnitTestFixture().init();
    4747        RemoteControl.PROP_REMOTECONTROL_HTTPS_ENABLED.put(true);
     
    7070     * <a href="http://stackoverflow.com/a/2893932/2257172">here</a> and
    7171     * <a href="http://stackoverflow.com/a/19542614/2257172">here</a>
     72     * @throws GeneralSecurityException if a security error occurs
    7273     */
    73     public void disableCertificateValidation() {
     74    public void disableCertificateValidation() throws GeneralSecurityException {
    7475        // Create a trust manager that does not validate certificate chains
    7576        TrustManager[] trustAllCerts = new TrustManager[] {
     
    9192
    9293        // Install the all-trusting trust manager
    93         try {
    94             SSLContext sc = SSLContext.getInstance("TLS");
    95             sc.init(null, trustAllCerts, new SecureRandom());
    96             HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    97         } catch (GeneralSecurityException e) {
    98             fail(e.getMessage());
    99         }
     94        SSLContext sc = SSLContext.getInstance("TLS");
     95        sc.init(null, trustAllCerts, new SecureRandom());
     96        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    10097
    10198        // Create all-trusting host name verifier
     
    121118    /**
    122119     * Tests that sending an HTTP request without command results in HTTP 400, with all available commands in error message.
     120     * @throws Exception if an error occurs
    123121     */
    124122    @Test
    125     public void testHttpListOfCommands() {
     123    public void testHttpListOfCommands() throws Exception {
    126124        testListOfCommands(httpBase);
    127125    }
     
    129127    /**
    130128     * Tests that sending an HTTPS request without command results in HTTP 400, with all available commands in error message.
     129     * @throws Exception if an error occurs
    131130     */
    132131    @Test
    133     public void testHttpsListOfCommands() {
     132    public void testHttpsListOfCommands() throws Exception {
    134133        testListOfCommands(httpsBase);
    135134    }
    136135
    137     private void testListOfCommands(String url) {
    138         try {
    139             HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    140             connection.connect();
    141             assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
    142             try (InputStream is = connection.getErrorStream()) {
    143                 // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
    144                 StringBuilder responseBody = new StringBuilder();
    145                 try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    146                     String s;
    147                     while ((s = in.readLine()) != null) {
    148                         responseBody.append(s);
    149                         responseBody.append("\n");
    150                     }
     136    private void testListOfCommands(String url) throws IOException, ReflectiveOperationException {
     137        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
     138        connection.connect();
     139        assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
     140        try (InputStream is = connection.getErrorStream()) {
     141            // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
     142            StringBuilder responseBody = new StringBuilder();
     143            try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
     144                String s;
     145                while ((s = in.readLine()) != null) {
     146                    responseBody.append(s);
     147                    responseBody.append("\n");
    151148                }
    152                 assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
    153             } catch (ReflectiveOperationException e) {
    154                 e.printStackTrace();
    155                 fail(e.getMessage());
    156149            }
    157         } catch (IOException e) {
    158             e.printStackTrace();
    159             fail(e.getMessage());
     150            assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
    160151        }
    161152    }
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r10571 r10937  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.session;
    3 
    4 import static org.junit.Assert.fail;
    53
    64import java.io.File;
     
    9189    }
    9290
    93     private void testWrite(List<Layer> layers, final boolean zip) {
     91    private void testWrite(List<Layer> layers, final boolean zip) throws IOException {
    9492        Map<Layer, SessionLayerExporter> exporters = new HashMap<>();
    9593        if (zip) {
     
    107105        try {
    108106            sw.write(file);
    109         } catch (IOException e) {
    110             e.printStackTrace();
    111             fail(e.getMessage());
    112107        } finally {
    113108            if (file.exists()) {
     
    148143    /**
    149144     * Tests to write an empty .jos file.
    150      */
    151     @Test
    152     public void testWriteEmptyJos() {
     145     * @throws IOException if an I/O error occurs
     146     */
     147    @Test
     148    public void testWriteEmptyJos() throws IOException {
    153149        testWrite(Collections.<Layer>emptyList(), false);
    154150    }
     
    156152    /**
    157153     * Tests to write an empty .joz file.
    158      */
    159     @Test
    160     public void testWriteEmptyJoz() {
     154     * @throws IOException if an I/O error occurs
     155     */
     156    @Test
     157    public void testWriteEmptyJoz() throws IOException {
    161158        testWrite(Collections.<Layer>emptyList(), true);
    162159    }
     
    164161    /**
    165162     * Tests to write a .jos file containing OSM data.
    166      */
    167     @Test
    168     public void testWriteOsmJos() {
     163     * @throws IOException if an I/O error occurs
     164     */
     165    @Test
     166    public void testWriteOsmJos() throws IOException {
    169167        testWrite(Collections.<Layer>singletonList(createOsmLayer()), false);
    170168    }
     
    172170    /**
    173171     * Tests to write a .joz file containing OSM data.
    174      */
    175     @Test
    176     public void testWriteOsmJoz() {
     172     * @throws IOException if an I/O error occurs
     173     */
     174    @Test
     175    public void testWriteOsmJoz() throws IOException {
    177176        testWrite(Collections.<Layer>singletonList(createOsmLayer()), true);
    178177    }
     
    180179    /**
    181180     * Tests to write a .jos file containing GPX data.
    182      */
    183     @Test
    184     public void testWriteGpxJos() {
     181     * @throws IOException if an I/O error occurs
     182     */
     183    @Test
     184    public void testWriteGpxJos() throws IOException {
    185185        testWrite(Collections.<Layer>singletonList(createGpxLayer()), false);
    186186    }
     
    188188    /**
    189189     * Tests to write a .joz file containing GPX data.
    190      */
    191     @Test
    192     public void testWriteGpxJoz() {
     190     * @throws IOException if an I/O error occurs
     191     */
     192    @Test
     193    public void testWriteGpxJoz() throws IOException {
    193194        testWrite(Collections.<Layer>singletonList(createGpxLayer()), true);
    194195    }
     
    196197    /**
    197198     * Tests to write a .joz file containing GPX and marker data.
    198      */
    199     @Test
    200     public void testWriteGpxAndMarkerJoz() {
     199     * @throws IOException if an I/O error occurs
     200     */
     201    @Test
     202    public void testWriteGpxAndMarkerJoz() throws IOException {
    201203        GpxLayer gpx = createGpxLayer();
    202204        testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
     
    205207    /**
    206208     * Tests to write a .joz file containing an imagery layer.
    207      */
    208     @Test
    209     public void testWriteImageryLayer() {
     209     * @throws IOException if an I/O error occurs
     210     */
     211    @Test
     212    public void testWriteImageryLayer() throws IOException {
    210213        final Layer layer = createImageryLayer();
    211214        testWrite(Collections.singletonList(layer), true);
     
    214217    /**
    215218     * Tests to write a .joz file containing a note layer.
    216      */
    217     @Test
    218     public void testWriteNoteLayer() {
     219     * @throws IOException if an I/O error occurs
     220     */
     221    @Test
     222    public void testWriteNoteLayer() throws IOException {
    219223        final Layer layer = createNoteLayer();
    220224        testWrite(Collections.singletonList(layer), true);
Note: See TracChangeset for help on using the changeset viewer.