Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Henri Tremblay
    @henri-tremblay
    amanuelyohannes
    @amanuelyohannes
    hello there
    i need help
    i want to test Spring MVC Controller using EasyMock
    Henri Tremblay
    @henri-tremblay
    Hi. You have a controller with dependencies and want to test the controller and mock the dependencies?
    amanuelyohannes
    @amanuelyohannes
    HEY NICE TO HERE FROM U
    Yes i have a project that i want to test all my controllers using EasyMock
    Henri Tremblay
    @henri-tremblay
    Ok. EasyMock can be used to mock your dependencies. So you can unit test every controller.
    amanuelyohannes
    @amanuelyohannes
    okay great.
    The thing is, this is my first exposure for testing and i never implement any kind of testing
    Henri Tremblay
    @henri-tremblay
    Ok. I can't give you a complete course about testing. That would take a bit too much time. So I will recommand some documentation
    amanuelyohannes
    @amanuelyohannes
    okay nice idea
    Thank you.
    will it be okay if i share you my code snippet ?
    Henri Tremblay
    @henri-tremblay
    If you have access to plural sight, this course is good: https://app.pluralsight.com/library/courses/java-testing-introduction/table-of-contents
    amanuelyohannes
    @amanuelyohannes
    i dont have access right now but i will check it,
    Yes, you can share some code
    amanuelyohannes
    @amanuelyohannes
    okay tnx
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (!StringUtils.isBlank(request.getParameter("link"))) {
    //save the new post
    final LinkPost linkPost = new LinkPost();
    linkPost.setLink(request.getParameter("link"));
    linkPost.setTitle(request.getParameter("title"));
    postService.saveOrUpdate(linkPost);
    return new ModelAndView("redirect:/homepage.blr");
    }
    return super.handleRequestInternal(request, response);
    }
    i have a home page which aallows user to post text, link and qoute. This method in my controller class handles requests related to "link". it sets the titles and link save and desplays it in my home page
    Henri Tremblay
    @henri-tremblay
    Looking at this, you only need to mock postService
    So you will have something like:
    ```
    PostService server = createMock(PostService.class);
    postService.saveOrUpdate(linkPost);
    replay(postService);
    call to you controller
    verify(postService);
    amanuelyohannes
    @amanuelyohannes
    okay thanks
    but how can i make test my controller properly handle the request and respond?
    and another thing shouldn't i test my ModelAndView?
    Henri Tremblay
    @henri-tremblay
    You should look at SpringMVC test suite
    amanuelyohannes
    @amanuelyohannes
    Thank you so much.
    Henri Tremblay
    @henri-tremblay
    no problem. Have fun
    gaurav20-07
    @gaurav20-07
    Hi.
    I am trying to use EasyMock with IntelliJ. How to go about it?
    Henri Tremblay
    @henri-tremblay
    What do you need? It's like any java library. You add it to the classpath.
    There is nothing specific to IntelliJ
    holubec-petr
    @holubec-petr
    Hi, are you considering support for Kotlin? Now, in my opinion base on our project, it's usable but with some tricky problems. One of the biggest problem is "inconsistent stack height" when mocking class with Kotlin specific constructs (like lambdas or default parameter values). Thanks for your answer.
    Henri Tremblay
    @henri-tremblay
    @holubec-petr Sorry... I really missed your question. I am all in favour of supporting Kotlin. However, I don't know what the current problems are. Can you elaborate on the "inconsistent stack height"? What is it?
    Henri Tremblay
    @henri-tremblay
    @/all EasyMock 3.5 was just delivered tonight. A lot of cool improvements and bug fixes https://github.com/easymock/easymock/releases/tag/easymock-3.5
    mallorygiles
    @mallorygiles
    Will there be support for using default methods of interfaces. Right now if I try to create a partial mock and then call a method on that mock that calls a default interface method, it calls that method (doesn't automatically mock it like other abstract methods). If I try to add as a mock by using addMockedMethod, I get java.lang.IllegalArgumentException: Method not found (or private)