Mocking FacesContext

前端 未结 7 1076
执念已碎
执念已碎 2021-02-18 19:20

I am trying to add some unit tests to a JSF application. This application didnt rely heavily on any best practices, so many service methods use the FacesContext to

7条回答
  •  情歌与酒
    2021-02-18 19:47

    in my case i was able to mock it in pure groovy. i provide a map of MockBeans that it can return:

    private FacesContext getMockFacesContext(def map){
            def fc = [
              "getApplication": {
                return ["getVariableResolver": {
                  return ["resolveVariable": { FacesContext fc, String name ->
                    return map[name]
                  }] as VariableResolver
                }] as Application
              },
              "addMessage": {String key, FacesMessage val ->
                println "added key: [${key}] value: [${val.getDetail()}] to JsfContext messages"
              },
              "getMessages": {return null}
            ] as FacesContext;
            return fc;
          }
    

提交回复
热议问题