Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeb Ford-Reitz2014-04-01 10:46:42 -0400
committerZeb Ford-Reitz2014-04-01 10:48:26 -0400
commit4e565dba089a46037efbe84822238a387ab20fee (patch)
treed5c57031d2f430adb63f86fb605309e5cb21dada /org.eclipse.jubula.rc.swing.tests
parentcde493ade2b28d38870638fcf38d9fc4bb9cf3aa (diff)
downloadorg.eclipse.jubula.core-4e565dba089a46037efbe84822238a387ab20fee.tar.gz
org.eclipse.jubula.core-4e565dba089a46037efbe84822238a387ab20fee.tar.xz
org.eclipse.jubula.core-4e565dba089a46037efbe84822238a387ab20fee.zip
Adds new JUnit test fragment: o.e.j.rc.swing.tests.
This initial commit contains tests for Jubula's handling of Swing text renderers. The test can be run from Eclipse as JUnit Test. This commit does not contain any build automation (Maven, Hudson, etc) integration.
Diffstat (limited to 'org.eclipse.jubula.rc.swing.tests')
-rw-r--r--org.eclipse.jubula.rc.swing.tests/.classpath7
-rw-r--r--org.eclipse.jubula.rc.swing.tests/.gitignore2
-rw-r--r--org.eclipse.jubula.rc.swing.tests/.project28
-rw-r--r--org.eclipse.jubula.rc.swing.tests/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--org.eclipse.jubula.rc.swing.tests/META-INF/MANIFEST.MF9
-rw-r--r--org.eclipse.jubula.rc.swing.tests/build.properties11
-rw-r--r--org.eclipse.jubula.rc.swing.tests/plugin.properties7
-rw-r--r--org.eclipse.jubula.rc.swing.tests/src/org/eclipse/jubula/rc/swing/tester/TestTesterUtil.java261
8 files changed, 333 insertions, 0 deletions
diff --git a/org.eclipse.jubula.rc.swing.tests/.classpath b/org.eclipse.jubula.rc.swing.tests/.classpath
new file mode 100644
index 000000000..098194ca4
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jubula.rc.swing.tests/.gitignore b/org.eclipse.jubula.rc.swing.tests/.gitignore
new file mode 100644
index 000000000..934e0e06f
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/.gitignore
@@ -0,0 +1,2 @@
+/bin
+/target
diff --git a/org.eclipse.jubula.rc.swing.tests/.project b/org.eclipse.jubula.rc.swing.tests/.project
new file mode 100644
index 000000000..9de5d8d8c
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jubula.rc.swing.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jubula.rc.swing.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jubula.rc.swing.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..f0de5c635
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Jan 24 12:12:31 CET 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.jubula.rc.swing.tests/META-INF/MANIFEST.MF b/org.eclipse.jubula.rc.swing.tests/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..4125a1adf
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests for Jubula Swing RC
+Bundle-SymbolicName: org.eclipse.jubula.rc.swing.tests;singleton:=true
+Bundle-Version: 2.3.0.qualifier
+Bundle-Vendor: BREDEX GmbH
+Fragment-Host: org.eclipse.jubula.rc.swing;bundle-version="[2.3.0,2.4.0)"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.junit;bundle-version="[4.8.2,5.0.0)"
diff --git a/org.eclipse.jubula.rc.swing.tests/build.properties b/org.eclipse.jubula.rc.swing.tests/build.properties
new file mode 100644
index 000000000..63c299c3f
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/build.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2004, 2012 BREDEX GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.jubula.rc.swing.tests/plugin.properties b/org.eclipse.jubula.rc.swing.tests/plugin.properties
new file mode 100644
index 000000000..3707665df
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/plugin.properties
@@ -0,0 +1,7 @@
+###############################################################################
+# Copyright (c) 2014 BREDEX GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+###############################################################################
diff --git a/org.eclipse.jubula.rc.swing.tests/src/org/eclipse/jubula/rc/swing/tester/TestTesterUtil.java b/org.eclipse.jubula.rc.swing.tests/src/org/eclipse/jubula/rc/swing/tester/TestTesterUtil.java
new file mode 100644
index 000000000..6f630383c
--- /dev/null
+++ b/org.eclipse.jubula.rc.swing.tests/src/org/eclipse/jubula/rc/swing/tester/TestTesterUtil.java
@@ -0,0 +1,261 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2014 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.rc.swing.tester;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.fail;
+
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Label;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JToggleButton;
+
+import org.eclipse.jubula.rc.common.adaptable.AdapterFactoryRegistry;
+import org.eclipse.jubula.rc.common.adaptable.IAdapterFactory;
+import org.eclipse.jubula.rc.common.adaptable.ITextRendererAdapter;
+import org.eclipse.jubula.rc.common.exception.StepExecutionException;
+import org.eclipse.jubula.rc.swing.tester.util.TesterUtil;
+import org.eclipse.jubula.tools.messagehandling.MessageIDs;
+import org.junit.After;
+import org.junit.Test;
+
+@SuppressWarnings("serial")
+public class TestTesterUtil {
+
+ private static class CanvasWithPublicGetText extends Canvas {
+ public String getText() {
+ return "CanvasWithPublicGetText";
+ }
+ }
+
+ private static class CanvasWithOverriddenGetText extends CanvasWithPublicGetText {
+ public String getText() {
+ return "CanvasWithOverriddenGetText";
+ }
+ }
+
+ private static class CanvasWithInvalidGetText extends Canvas {
+ @SuppressWarnings("unused")
+ public Color getText() {
+ return Color.BLACK;
+ }
+ }
+
+ private static class CanvasWithPrivateGetText extends Canvas {
+ private String getText() {
+ return "CanvasWithPrivateGetText";
+ }
+ }
+
+ private static class CanvasWithNullGetText extends Canvas {
+ @SuppressWarnings("unused")
+ public String getText() {
+ return null;
+ }
+ }
+
+ private static class CanvasWithExceptionGetText extends Canvas {
+ @SuppressWarnings("unused")
+ public String getText() {
+ throw new RuntimeException();
+ }
+ }
+
+ private final String m_renderedText = "RenderedText";
+
+ private IAdapterFactory m_registeredAdapterFactory = null;
+
+ private void assertRenderedTextEquals(
+ String expectedText, Component renderer) {
+
+ assertEquals(
+ expectedText, TesterUtil.getRenderedText(renderer));
+ }
+
+ private void assertRendererNotSupported(Component renderer) {
+ try {
+ TesterUtil.getRenderedText(renderer);
+ fail();
+ } catch (StepExecutionException e) {
+ assertEquals(e.getErrorId(), MessageIDs.E_EVENT_SUPPORT);
+ }
+ }
+
+ @After
+ public void deregisterAdapterFactory() {
+ if (m_registeredAdapterFactory != null) {
+ AdapterFactoryRegistry.getInstance()
+ .signOffFactory(m_registeredAdapterFactory);
+ }
+ }
+
+ @Test
+ public void testRenderedNotSupported() {
+ assertRendererNotSupported(new Canvas());
+ }
+
+ @Test
+ public void testLabelRenderer() {
+ assertRenderedTextEquals(
+ m_renderedText,
+ new Label(m_renderedText));
+ }
+
+ @Test
+ public void testToggleButtonRenderer() {
+ JToggleButton toggleButton = new JToggleButton("Button text", false);
+
+ assertRenderedTextEquals(
+ Boolean.FALSE.toString(),
+ toggleButton);
+
+ toggleButton.setSelected(true);
+
+ assertRenderedTextEquals(
+ Boolean.TRUE.toString(),
+ toggleButton);
+ }
+
+ @Test
+ public void testButtonRenderer() {
+ assertRenderedTextEquals(
+ m_renderedText,
+ new JButton(m_renderedText));
+ }
+
+ @Test
+ public void testTextComponentRenderer() {
+ assertRenderedTextEquals(
+ m_renderedText,
+ new JTextField(m_renderedText));
+ }
+
+ @Test
+ public void testNullRenderer() {
+ assertRenderedTextEquals(
+ "",
+ new JLabel() {
+ @Override
+ public String getText() {
+ return null;
+ }
+ });
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testAdaptedRenderer() {
+ final String canvasText = "CanvasRenderedText";
+
+ m_registeredAdapterFactory = new IAdapterFactory() {
+
+ public Class[] getSupportedClasses() {
+ return new Class[] {Canvas.class};
+ }
+
+ public Object getAdapter(Class targetAdapterClass, Object objectToAdapt) {
+ if (objectToAdapt instanceof Canvas) {
+ return new ITextRendererAdapter() {
+ public String getText() {
+ return canvasText;
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ AdapterFactoryRegistry.getInstance()
+ .registerFactory(m_registeredAdapterFactory);
+
+ assertRenderedTextEquals(canvasText, new Canvas());
+
+ }
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void testNullAdaptedRenderer() {
+ m_registeredAdapterFactory = new IAdapterFactory() {
+
+ public Class[] getSupportedClasses() {
+ return new Class[] {Canvas.class};
+ }
+
+ public Object getAdapter(Class targetAdapterClass, Object objectToAdapt) {
+ if (objectToAdapt instanceof Canvas) {
+ return new ITextRendererAdapter() {
+ public String getText() {
+ return null;
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ AdapterFactoryRegistry.getInstance()
+ .registerFactory(m_registeredAdapterFactory);
+
+ assertRenderedTextEquals("", new Canvas());
+
+ }
+
+ @Test
+ public void testPublicGetText() {
+ CanvasWithPublicGetText c = new CanvasWithPublicGetText();
+ assertRenderedTextEquals(c.getText(), c);
+ }
+
+ @Test
+ public void testPrivateGetText() {
+ CanvasWithPrivateGetText c = new CanvasWithPrivateGetText();
+ assertRenderedTextEquals(c.getText(), c);
+ }
+
+ @Test
+ public void testOverriddenGetText() {
+ CanvasWithOverriddenGetText c = new CanvasWithOverriddenGetText();
+ assertRenderedTextEquals(c.getText(), c);
+ }
+
+ @Test
+ public void testNullGetText() {
+ CanvasWithNullGetText c = new CanvasWithNullGetText();
+ assertRenderedTextEquals("", c);
+ }
+
+ @Test
+ public void testInvalidGetText() {
+ CanvasWithInvalidGetText c = new CanvasWithInvalidGetText();
+ assertRendererNotSupported(c);
+ }
+
+ @Test
+ public void testGetTextExceptionHandling() {
+ CanvasWithExceptionGetText c = new CanvasWithExceptionGetText();
+ try {
+ TesterUtil.getRenderedText(c);
+ fail();
+ } catch (StepExecutionException e) {
+ // An error occurring while getting the text does not mean that the
+ // renderer is not supported.
+ assertFalse(MessageIDs.E_EVENT_SUPPORT.equals(e.getErrorId()));
+ }
+ }
+}

Back to the top