先看下重构前的测试用例:
public class TestLogin extends TestCase{ private ButtonManagerIbatis buttonManagerIbatis; protected void setUp() throws Exception { context = getContext(); buttonManagerIbatis = (ButtonManagerIbatis)context.getBean ("buttonManagerIbatis"); super.setUp(); } ApplicationContext context ; protected ApplicationContext getContext() { String[] paths = {"/context/application_context.xml"}; ApplicationContext ctx = new ClassPathXmlApplicationContext(paths); return ctx; } /** *//** * 测试:登陆后读取权限信息,并且封装为树形结构 */ public void testLongin(){ List<Button> list = buttonManagerIbatis.getAuth("0000"); testall(list); } Map<String,Model> modelmap = new HashMap<String,Model>(); Map<String,Menu> fmenumap = new HashMap<String,Menu>(); Map<String,Menu> smenumap = new HashMap<String,Menu>(); public void testall(List<Button> buttonList){ for(Button button :buttonList){ test(modelmap,button); } for(Model model : modelmap.values()){ test2(smenumap,model); } for(Menu menu : smenumap.values()){ test3(fmenumap,menu); } for(Menu fmenu :fmenumap.values() ){ System.out.println(fmenu.getMenuName()); for(Menu smenu :fmenu.getMenus() ){ System.out.println(" "+smenu.getMenuName()); for(Model model : smenu.getModels()){ System.out.println(" "+model.getName()); for(Button b:model.getButtons()){ System.out.println(" "+ b.getButtonDesc()); } } } } } public void test(Map<String,Model> modelmap , Button b){ Model m = b.getModel(); if(!modelmap.containsKey(m.getId())) modelmap.put(m.getId(),m); modelmap.get(m.getId()).getButtons().add(b); } public void test2(Map<String,Menu> menumap , Model m){ Menu menu = m.getMenu(); if(!menumap.containsKey(menu.getId())) menumap.put(menu.getId(),menu); menumap.get(menu.getId()).getModels().add(m); } public void test3(Map<String,Menu> menumap , Menu smenu){ Menu fmenu = smenu.getMenu(); if(!menumap.containsKey(fmenu.getId())) menumap.put(fmenu.getId(),fmenu); menumap.get(fmenu.getId()).getMenus().add(smenu); } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索menu
, applicationcontext
, public
containskey
c重构函数、函数重构、php 重构函数、js函数重构、python 函数重构,以便于您获取更多的相关知识。
时间: 2025-01-28 03:57:36