Ignore:
Timestamp:
2016-06-16T13:43:21+02:00 (8 years ago)
Author:
Don-vip
Message:

gsoc-core - fix LayerManagerTest with new custom JUnit rule/matcher to check for exception root causes

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java

    r10378 r10397  
    22package org.openstreetmap.josm.gui.layer;
    33
     4import static org.hamcrest.CoreMatchers.any;
    45import static org.junit.Assert.assertEquals;
    56import static org.junit.Assert.assertFalse;
     
    1112
    1213import java.awt.Graphics2D;
     14import java.lang.reflect.InvocationTargetException;
    1315import java.util.ArrayList;
    1416import java.util.Arrays;
     
    1820
    1921import org.junit.Before;
     22import org.junit.Rule;
    2023import org.junit.Test;
    2124import org.openstreetmap.josm.data.Bounds;
     
    2730import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    2831import org.openstreetmap.josm.gui.util.GuiHelper;
     32import org.openstreetmap.josm.testutils.ExpectedRootException;
    2933import org.openstreetmap.josm.tools.Predicates;
     34import org.openstreetmap.josm.tools.bugreport.ReportedException;
    3035
    3136/**
     
    119124            layerOrderChanged = e;
    120125        }
    121 
    122126    }
    123127
    124128    protected LayerManager layerManager;
     129
     130    /**
     131     * Rule used to expect exceptions.
     132     */
     133    @Rule
     134    public ExpectedRootException thrown = ExpectedRootException.none();
    125135
    126136    /**
     
    182192     * {@link LayerManager#addLayer(Layer)}: duplicate layers
    183193     */
    184     @Test(expected = IllegalArgumentException.class)
     194    @Test
    185195    public void testAddLayerFails() {
     196        thrown.expect(ReportedException.class);
     197        thrown.expectCause(any(InvocationTargetException.class));
     198        thrown.expectRootCause(any(IllegalArgumentException.class));
     199
    186200        AbstractTestLayer layer1 = new AbstractTestLayer();
    187201        layerManager.addLayer(layer1);
     
    192206     * {@link LayerManager#addLayer(Layer)}: illegal default layer position
    193207     */
    194     @Test(expected = IndexOutOfBoundsException.class)
     208    @Test
    195209    public void testAddLayerIllegalPosition() {
     210        thrown.expect(ReportedException.class);
     211        thrown.expectCause(any(InvocationTargetException.class));
     212        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
     213
    196214        AbstractTestLayer layer1 = new AbstractTestLayer() {
    197215            @Override
     
    260278     * {@link LayerManager#moveLayer(Layer, int)} fails for wrong index
    261279     */
    262     @Test(expected = IndexOutOfBoundsException.class)
     280    @Test
    263281    public void testMoveLayerFailsRange() {
     282        thrown.expect(ReportedException.class);
     283        thrown.expectCause(any(InvocationTargetException.class));
     284        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
     285
    264286        AbstractTestLayer layer1 = new AbstractTestLayer();
    265287        AbstractTestLayer layer2 = new AbstractTestLayer();
     
    272294     * {@link LayerManager#moveLayer(Layer, int)} fails for wrong layer
    273295     */
    274     @Test(expected = IllegalArgumentException.class)
     296    @Test
    275297    public void testMoveLayerFailsNotInList() {
     298        thrown.expect(ReportedException.class);
     299        thrown.expectCause(any(InvocationTargetException.class));
     300        thrown.expectRootCause(any(IllegalArgumentException.class));
     301
    276302        AbstractTestLayer layer1 = new AbstractTestLayer();
    277303        AbstractTestLayer layer2 = new AbstractTestLayer();
Note: See TracChangeset for help on using the changeset viewer.