@ -56,6 +56,9 @@ public class AddingModelTest {
DaoContext . setEntityDao ( null ) ;
DaoContext . setEntityDao ( null ) ;
}
}
/ * *
* 默认名字 + i
* /
@Test
@Test
public void testInstantiateCreator ( ) throws Exception {
public void testInstantiateCreator ( ) throws Exception {
@ -82,7 +85,7 @@ public class AddingModelTest {
AddingModel addingModel = new AddingModel ( xCreator1 , 20 , 20 ) ;
AddingModel addingModel = new AddingModel ( xCreator1 , 20 , 20 ) ;
Form form = EasyMock . mock ( Form . class ) ;
Form form = EasyMock . mock ( Form . class ) ;
EasyMock . expect ( form . isNameExist ( "test" ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( "test0 " ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( "test03" ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( "test03" ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( EasyMock . anyString ( ) ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . expect ( form . isNameExist ( EasyMock . anyString ( ) ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . replay ( form ) ;
EasyMock . replay ( form ) ;
@ -93,9 +96,9 @@ public class AddingModelTest {
addingModel . instantiateCreator ( mock ) ;
addingModel . instantiateCreator ( mock ) ;
//没有默认参数, 但已经存在 test
//没有默认参数, 但已经存在 test
Assert . assertEquals ( "test0 " , xCreator1 . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "test1 " , xCreator1 . toData ( ) . getWidgetName ( ) ) ;
//直接返回
//直接返回
Assert . assertEquals ( "test02" , xCreator2 . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "test020 " , xCreator2 . toData ( ) . getWidgetName ( ) ) ;
//已经存在,后接0
//已经存在,后接0
Assert . assertEquals ( "test030" , xCreator3 . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "test030" , xCreator3 . toData ( ) . getWidgetName ( ) ) ;
}
}
@ -104,8 +107,8 @@ public class AddingModelTest {
public void testInstantiateCreator_cardLayout ( ) throws Exception {
public void testInstantiateCreator_cardLayout ( ) throws Exception {
Form form = EasyMock . mock ( Form . class ) ;
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 ( "cardlayout0" ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( "cardlayout1" ) ) . andReturn ( true ) . once ( ) ;
EasyMock . expect ( form . isNameExist ( EasyMock . anyString ( ) ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . expect ( form . isNameExist ( EasyMock . anyString ( ) ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . replay ( form ) ;
EasyMock . replay ( form ) ;
@ -116,13 +119,16 @@ public class AddingModelTest {
WCardLayout wCardLayout = new WCardLayout ( 20 , 20 ) ;
WCardLayout wCardLayout = new WCardLayout ( 20 , 20 ) ;
XWCardLayout xwCardLayout = new XWCardLayout ( wCardLayout , new Dimension ( 40 , 40 ) ) ;
XWCardLayout xwCardLayout = new XWCardLayout ( wCardLayout , new Dimension ( 40 , 40 ) ) ;
AddingModel addingModel = new AddingModel ( mock , xwCardLayout ) ;
AddingModel addingModel = new AddingModel ( mock , xwCardLayout ) ;
Assert . assertEquals ( "cardlayout1 " , xwCardLayout . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "cardlayout2 " , xwCardLayout . toData ( ) . getWidgetName ( ) ) ;
//依赖于 cardlayout 创建 container
//依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout . initCreatorWrapper ( 80 ) ;
XLayoutContainer parentLayOut = xwCardLayout . initCreatorWrapper ( 80 ) ;
//组件默认名 tablelayout2
AddingModel parentModel = new AddingModel ( mock , parentLayOut ) ;
AddingModel parentModel = new AddingModel ( mock , parentLayOut ) ;
Assert . assertEquals ( "tablayout1" , parentLayOut . toData ( ) . getWidgetName ( ) ) ;
//经过处理 tablayout20
Assert . assertEquals ( "tabpane1" , ( ( XCreator ) ( parentLayOut . getComponent ( 0 ) ) ) . getXCreator ( ) . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "tablayout20" , parentLayOut . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "tabpane20" , ( ( XCreator ) ( parentLayOut . getComponent ( 0 ) ) ) . getXCreator ( ) . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "cardlayout20" , xwCardLayout . toData ( ) . getWidgetName ( ) ) ;
}
}
@ -130,8 +136,6 @@ public class AddingModelTest {
public void testInstantiateCreator_containsNotXCreator ( ) throws Exception {
public void testInstantiateCreator_containsNotXCreator ( ) throws Exception {
Form form = EasyMock . mock ( Form . class ) ;
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 . expect ( form . isNameExist ( EasyMock . anyString ( ) ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . replay ( form ) ;
EasyMock . replay ( form ) ;
@ -170,16 +174,16 @@ public class AddingModelTest {
AddingModel chartModel = new AddingModel ( mock , xCreator1 ) ;
AddingModel chartModel = new AddingModel ( mock , xCreator1 ) ;
Assert . assertEquals ( "chart" , xCreator1 . toData ( ) . getWidgetName ( ) ) ;
Assert . assertEquals ( "chart0 " , xCreator1 . toData ( ) . getWidgetName ( ) ) ;
}
}
private static class DemoCreator extends XCreator {
private static class DemoCreator extends XCreator {
private String widgetName ;
private String widgetName ;
public DemoCreator ( Widget ob , Dimension initSize , String wi dg etName) {
public DemoCreator ( Widget ob , Dimension initSize , String defaul tName ) {
super ( ob , initSize ) ;
super ( ob , initSize ) ;
this . widgetName = wi dg etName;
this . widgetName = defaul tName ;
}
}
@Override
@Override