Lanlan
5 years ago
2 changed files with 120 additions and 23 deletions
@ -0,0 +1,57 @@
|
||||
package com.fr.design.designer.beans.models; |
||||
|
||||
import com.fr.design.designer.creator.CRPropertyDescriptor; |
||||
import com.fr.design.designer.creator.XCreator; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.form.ui.ChartEditor; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import javax.swing.JComponent; |
||||
import java.awt.Dimension; |
||||
import java.beans.IntrospectionException; |
||||
|
||||
public class AddingModelTest { |
||||
|
||||
@Test |
||||
public void testInstantiateCreator() throws Exception { |
||||
|
||||
ChartEditor chartEditor = new ChartEditor(); |
||||
chartEditor.setWidgetName("test01"); |
||||
XCreator xCreator = new XCreator(chartEditor, new Dimension(20, 20)) { |
||||
@Override |
||||
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||
return new CRPropertyDescriptor[0]; |
||||
} |
||||
|
||||
@Override |
||||
protected JComponent initEditor() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
protected void initXCreatorProperties() { |
||||
} |
||||
|
||||
@Override |
||||
public String createDefaultName() { |
||||
return "test"; |
||||
} |
||||
}; |
||||
AddingModel addingModel = new AddingModel(xCreator, 20, 20); |
||||
|
||||
Form form = EasyMock.mock(Form.class); |
||||
EasyMock.expect(form.isNameExist("test0")).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); |
||||
|
||||
addingModel.instantiateCreator(mock); |
||||
Assert.assertEquals("test1", xCreator.toData().getWidgetName()); |
||||
} |
||||
} |
Loading…
Reference in new issue