Changeset 10983 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-09-10T01:45:13+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13609 - --version and --help are too verbose

File:
1 edited

Legend:

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

    r10123 r10983  
    66import static org.junit.Assert.assertNull;
    77
     8import java.io.ByteArrayOutputStream;
     9import java.io.IOException;
     10import java.io.PrintStream;
    811import java.util.Arrays;
    912import java.util.Collection;
     
    1518import org.junit.Test;
    1619import org.openstreetmap.josm.JOSMFixture;
     20import org.openstreetmap.josm.data.Version;
    1721import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
    1822import org.openstreetmap.josm.plugins.PluginHandler;
     
    3337    public static void setUp() {
    3438        JOSMFixture.createUnitTestFixture().init(true);
     39    }
     40
     41    private void testShow(final String arg, String expected) throws InterruptedException, IOException {
     42        PrintStream old = System.out;
     43        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
     44            System.setOut(new PrintStream(baos));
     45            Thread t = new Thread() {
     46                @Override
     47                public void run() {
     48                    MainApplication.main(new String[] {arg});
     49                }
     50            };
     51            t.run();
     52            t.join();
     53            System.out.flush();
     54            assertEquals(expected, baos.toString().trim());
     55        } finally {
     56            System.setOut(old);
     57        }
     58    }
     59
     60    /**
     61     * Test of {@link MainApplication#main} with argument {@code --version}.
     62     * @throws Exception in case of error
     63     */
     64    @Test
     65    public void testShowVersion() throws Exception {
     66        testShow("--version", Version.getInstance().getAgentString());
     67    }
     68
     69    /**
     70     * Test of {@link MainApplication#main} with argument {@code --help}.
     71     * @throws Exception in case of error
     72     */
     73    @Test
     74    public void testShowHelp() throws Exception {
     75        testShow("--help", MainApplication.getHelp().trim());
    3576    }
    3677
     
    72113
    73114    private static PluginInformation newPluginInformation(String plugin) throws PluginListParseException {
    74         //return new PluginInformation(new File(TestUtils.getTestDataRoot()+File.separator+"plugin"+File.separator+plugin+".jar"));
    75115        return PluginListParser.createInfo(plugin+".jar", "https://svn.openstreetmap.org/applications/editors/josm/dist/"+plugin+".jar",
    76116                "");
Note: See TracChangeset for help on using the changeset viewer.