First look at the test cases before refactoring:
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; /** *//** * Test: Read permission information after login, and encapsulated as tree structure * * public void Testlongin () {list<button> List = Buttonmanag
Eribatis.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); } }