From 47b66204eae7a2e20f8a8a27e129c8eca4e3fcac Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 10 Jun 2020 15:40:07 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-32149=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E3=80=91@harrison=E4=B8=A4=E4=B8=AA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=BF=9B=E8=A1=8C=E6=8B=96=E5=85=A5=EF=BC=8C=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=A2=84=E8=A7=88=E5=BE=88=E5=A5=87=E6=80=AA=20?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E5=B1=82=E5=88=A4=E6=96=AD=EF=BC=8C=20?= =?UTF-8?q?=E5=86=85=E9=83=A8=E5=8F=AF=E8=83=BD=E6=9C=89=E5=BE=88=E5=A4=9A?= =?UTF-8?q?=E4=B8=AD=E4=B8=8D=E5=90=8C=E7=9A=84=20component.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/designer/creator/XCreator.java | 12 ++-- .../beans/models/AddingModelTest.java | 62 ++++++++++++++++++- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java index a5a59acc8..f4554069e 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java @@ -429,10 +429,14 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo xCreators.add(this); int componentCount = getComponentCount(); for (int i = 0; i < componentCount; i++) { - XCreator xCreator = (XCreator) getComponent(i); - //获取真实的 creator - XCreator realCreator = xCreator.getXCreator(); - realCreator.traversalNameRelatedXCreators(xCreators); + + Component component = getComponent(i); + if (component instanceof XCreator) { + XCreator xCreator = (XCreator) component; + //获取真实的 creator + XCreator realCreator = xCreator.getXCreator(); + realCreator.traversalNameRelatedXCreators(xCreators); + } } } diff --git a/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java b/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java index a6bd82300..7f17ef3a2 100644 --- a/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java +++ b/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java @@ -1,32 +1,45 @@ package com.fr.design.designer.beans.models; +import com.fr.base.chart.BaseChartCollection; import com.fr.config.dao.DaoContext; import com.fr.config.dao.impl.LocalClassHelperDao; import com.fr.config.dao.impl.LocalEntityDao; import com.fr.config.dao.impl.LocalXmlEntityDao; import com.fr.design.designer.creator.CRPropertyDescriptor; +import com.fr.design.designer.creator.XChartEditor; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.designer.creator.cardlayout.XWCardLayout; +import com.fr.design.gui.chart.MiddleChartComponent; import com.fr.design.mainframe.FormDesigner; +import com.fr.design.module.DesignModuleFactory; import com.fr.form.main.Form; import com.fr.form.ui.ChartEditor; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WTitleLayout; +import com.fr.stable.core.PropertyChangeListener; import org.easymock.EasyMock; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import javax.swing.JComponent; import java.awt.Dimension; import java.awt.Rectangle; import java.beans.IntrospectionException; +@PrepareForTest({DesignModuleFactory.class}) +@PowerMockIgnore({"com.sun.*", "javax.*", "com.fr.jvm.assist.*"}) +@RunWith(PowerMockRunner.class) public class AddingModelTest { @Before @@ -99,7 +112,7 @@ public class AddingModelTest { FormDesigner mock = EasyMock.mock(FormDesigner.class); EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes(); EasyMock.replay(mock); - + WCardLayout wCardLayout = new WCardLayout(20, 20); XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40)); AddingModel addingModel = new AddingModel(mock, xwCardLayout); @@ -113,6 +126,53 @@ public class AddingModelTest { } + @Test + public void testInstantiateCreator_containsNotXCreator() throws Exception { + + Form form = EasyMock.mock(Form.class); + EasyMock.expect(form.isNameExist("cardlayout")).andReturn(true).once(); + EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once(); + EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes(); + EasyMock.replay(form); + + FormDesigner mock = EasyMock.mock(FormDesigner.class); + EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes(); + EasyMock.replay(mock); + + PowerMock.mockStaticPartial(DesignModuleFactory.class, "getChartComponent"); + EasyMock.expect(DesignModuleFactory.getChartComponent(EasyMock.anyObject(BaseChartCollection.class))).andReturn(new MiddleChartComponent() { + @Override + public void populate(BaseChartCollection cc) { + + } + + @Override + public BaseChartCollection update() { + return null; + } + + @Override + public void reset() { + + } + + @Override + public void addStopEditingListener(PropertyChangeListener list) { + + } + }).anyTimes(); + PowerMock.replayAll(); + + Dimension dimension = new Dimension(20, 20); + + ChartEditor chartEditor1 = new ChartEditor(); + XCreator xCreator1 = new XChartEditor(chartEditor1, dimension); + + + AddingModel chartModel = new AddingModel(mock, xCreator1); + Assert.assertEquals("chart", xCreator1.toData().getWidgetName()); + } + private static class DemoCreator extends XCreator { private String widgetName;