📄 mainunittest.java
字号:
/** ===================================================================
*
* @PROJECT.FULLNAME@ @VERSION@ License.
*
* Copyright (c) @YEAR@ L2FProd.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by L2FProd.com
* (http://www.L2FProd.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "@PROJECT.FULLNAME@", "@PROJECT.SHORTNAME@" and "L2FProd.com" must not
* be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please
* contact info@L2FProd.com.
*
* 5. Products derived from this software may not be called "@PROJECT.SHORTNAME@"
* nor may "@PROJECT.SHORTNAME@" appear in their names without prior written
* permission of L2FProd.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package com.l2fprod.common.demo;
import com.l2fprod.common.Version;
import com.l2fprod.common.swing.JButtonBar;
import com.l2fprod.common.swing.LookAndFeelTweaks;
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.File;
import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import junit.framework.TestCase;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.operators.AbstractButtonOperator;
import org.netbeans.jemmy.operators.ComponentOperator;
import org.netbeans.jemmy.util.PNGEncoder;
/**
* MainUnitTest. <br>
*
*/
public class MainUnitTest extends TestCase {
private JFrame demo;
protected void setUp() throws Exception {
super.setUp();
JemmyProperties.getProperties().setDispatchingModel(
JemmyProperties.ROBOT_MODEL_MASK);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
LookAndFeelTweaks.tweak();
demo = new JFrame("L2FProd.com Common Components "
+ Version.getVersion() + " (build " + Version.getBuildTimestamp() + ")");
demo.getContentPane().setLayout(new BorderLayout());
demo.getContentPane().add("Center", new Main());
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
demo.setSize(400, 500);
demo.setLocation(100, 100);
demo.setVisible(true);
}
public void testJButtonBar() throws Exception {
// iterate through JButtons of JButtonBar
JButtonBar buttonbar =
(
JButtonBar)ComponentOperator
.waitComponent(demo, new ComponentChooser() {
public boolean checkComponent(Component arg0) {
return arg0 instanceof JButtonBar;
}
public String getDescription() {
return null;
}
});
Component[] components = buttonbar.getComponents();
for (int i = 0, c = components.length; i < c; i++) {
if (components[i] instanceof AbstractButton) {
AbstractButton button = (AbstractButton)components[i];
new AbstractButtonOperator(button).push();
// after each click on the button, perform a screenshot
File screenshot = new File("screenshot-" + i + ".png");
System.out.println("Screenshot in " + screenshot.getAbsolutePath());
PNGEncoder.captureScreen(
demo,
screenshot.getAbsolutePath(),
PNGEncoder.COLOR_MODE);
}
}
}
protected void tearDown() throws Exception {
demo = null;
super.tearDown();
}
public MainUnitTest(String arg0) {
super(arg0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -