Created
November 23, 2012 09:16
-
-
Save egocks/4134693 to your computer and use it in GitHub Desktop.
Servlet unit testing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pointwest.example; | |
import org.junit.Before; | |
import org.junit.Test; | |
import com.mockrunner.mock.web.WebMockObjectFactory; | |
import com.mockrunner.servlet.ServletTestModule; | |
public class SettingServletTest { | |
private ServletTestModule tester; | |
private WebMockObjectFactory factory; | |
@Before | |
public void setup() { | |
factory = new WebMockObjectFactory(); | |
tester = new ServletTestModule(factory); | |
} | |
@Test | |
public void doGetRoleSuperUserOnly(){ | |
String userId = "chan"; | |
String expected; | |
String role = "SuperUser"; | |
factory.getMockRequest().setUserInRole(role, true); | |
tester.createServlet(SettingsServlet.class); | |
tester.doGet(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment