1 /////////////////////////////////////////////////////////////////////////////////////////////// 2 // checkstyle: Checks Java source code and other text files for adherence to a set of rules. 3 // Copyright (C) 2001-2025 the original author or authors. 4 // 5 // This library is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU Lesser General Public 7 // License as published by the Free Software Foundation; either 8 // version 2.1 of the License, or (at your option) any later version. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with this library; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 /////////////////////////////////////////////////////////////////////////////////////////////// 19 20 package com.puppycrawl.tools.checkstyle.gui; 21 22 import static com.google.common.truth.Truth.assertWithMessage; 23 24 import java.awt.Window; 25 import java.util.Arrays; 26 27 import javax.swing.SwingUtilities; 28 29 import org.junit.jupiter.params.ParameterizedTest; 30 import org.junit.jupiter.params.provider.ValueSource; 31 32 import com.puppycrawl.tools.checkstyle.AbstractGuiTestSupport; 33 34 public class MainTest extends AbstractGuiTestSupport { 35 36 @Override 37 protected String getPackageLocation() { 38 return "com/puppycrawl/tools/checkstyle/gui/main"; 39 } 40 41 /** 42 * Parametrized test to invoke Checkstyle GUI with different command line arguments. 43 * 44 * @param argList the command line arguments delimited by a semicolon (";") 45 * @throws Exception if an exception occurs while executing the test. 46 */ 47 @ParameterizedTest 48 @ValueSource(strings = {";", "InputMain.java"}) 49 public void testMain(String argList) throws Exception { 50 final String[] args = argList.split(";"); 51 for (int i = 0; i < args.length; i++) { 52 args[i] = getPath(args[i]); 53 } 54 55 // Create the main window 56 Main.main(args); 57 58 SwingUtilities.invokeAndWait(() -> { 59 // Close the main window 60 final long mainFrameCount = Arrays.stream(Window.getWindows()) 61 .filter(wnd -> wnd instanceof MainFrame && wnd.isVisible()) 62 .peek(Window::dispose) 63 .count(); 64 assertWithMessage("Only one window is expected") 65 .that(mainFrameCount) 66 .isEqualTo(1); 67 }); 68 } 69 70 }