Changeset 11776 in josm


Ignore:
Timestamp:
2017-03-25T22:01:59+01:00 (8 years ago)
Author:
michael2402
Message:

Reduce startup time of StyleCacheTest, use test rules, do not leak memory. See #14495

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/gui/mappaint/StyleCacheTest.java

    r11276 r11776  
    1111import java.util.IdentityHashMap;
    1212
     13import org.junit.AfterClass;
    1314import org.junit.Assert;
     15import org.junit.Before;
    1416import org.junit.BeforeClass;
     17import org.junit.Rule;
    1518import org.junit.Test;
    1619import org.openstreetmap.josm.JOSMFixture;
     
    2124import org.openstreetmap.josm.data.osm.visitor.paint.Rendering;
    2225import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
     26import org.openstreetmap.josm.gui.MapView;
    2327import org.openstreetmap.josm.gui.NavigatableComponent;
    2428import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2529import org.openstreetmap.josm.io.Compression;
    2630import org.openstreetmap.josm.io.OsmReader;
     31import org.openstreetmap.josm.testutils.JOSMTestRules;
    2732import org.openstreetmap.josm.tools.Pair;
     33
     34import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2835
    2936/**
     
    4148    private static DataSet dsCity2;
    4249
     50    /**
     51     * The test rules used for this test.
     52     */
     53    @Rule
     54    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     55    public JOSMTestRules test = new JOSMTestRules().preferences().platform().projection();
     56
     57    /**
     58     * Load the test data that is required.
     59     * @throws Exception
     60     */
    4361    @BeforeClass
    4462    public static void load() throws Exception {
    45         JOSMFixture.createPerformanceTestFixture().init(true);
    4663        img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    47         g = (Graphics2D) img.getGraphics();
    48         g.setClip(0, 0, IMG_WIDTH, IMG_WIDTH);
    49         g.setColor(Color.BLACK);
    50         g.fillRect(0, 0, IMG_WIDTH, IMG_WIDTH);
    51         nc = Main.map.mapView;
    52         nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
    5364
    54         MapPaintStyles.readFromPreferences();
    5565        try (
    5666            InputStream fisC = Compression.getUncompressedFileInputStream(new File("data_nodist/neubrandenburg.osm.bz2"));
     
    5868            dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
    5969        }
    60         try (
    61             InputStream fisC = Compression.getUncompressedFileInputStream(new File("data_nodist/neubrandenburg.osm.bz2"));
    62         ) {
    63             dsCity2 = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
    64         }
     70        dsCity2 = new DataSet(dsCity);
     71    }
     72
     73    /**
     74     * Free the memory allocated for this test.
     75     * <p>
     76     * Since we are running junit in non-forked mode, we don't know when this test will not be referenced any more.
     77     */
     78    @AfterClass
     79    public static void unload() {
     80        g = null;
     81        img = null;
     82        nc = null;
     83        dsCity = null;
     84        dsCity2 = null;
     85    }
     86
     87    /**
     88     * Create the temporary graphics
     89     */
     90    @Before
     91    public void loadGraphicComponents() {
     92        g = (Graphics2D) img.getGraphics();
     93        g.setClip(0, 0, IMG_WIDTH, IMG_WIDTH);
     94        g.setColor(Color.BLACK);
     95        g.fillRect(0, 0, IMG_WIDTH, IMG_WIDTH);
     96        nc = new MapView(Main.getLayerManager(), null);
     97        nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
     98        MapPaintStyles.readFromPreferences();
    6599    }
    66100
     
    79113    @Test
    80114    public void testStyleCacheInternPool() {
     115        // This can be removed if there was no dependency on Main.map in some MapCSS conditions. See #14572
     116        JOSMFixture.createFunctionalTestFixture().init(true);
     117
    81118        Bounds bounds = new Bounds(53.56, 13.25, 53.57, 13.26);
    82119        Rendering visitor = new StyledMapRenderer(g, nc, false);
     
    105142    @Test
    106143    public void testStyleCacheInternPool2() {
     144        // This can be removed if there was no dependency on Main.map in some MapCSS conditions. See #14572
     145        JOSMFixture.createFunctionalTestFixture().init(true);
     146
    107147        Bounds bounds = new Bounds(53.56, 13.25, 53.57, 13.26);
    108148        Rendering visitor = new StyledMapRenderer(g, nc, false);
Note: See TracChangeset for help on using the changeset viewer.