Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mvysny/fake-servlet
Fake implementation of both javax.servlet and jakartaee.servlet
https://github.com/mvysny/fake-servlet
Last synced: 28 days ago
JSON representation
Fake implementation of both javax.servlet and jakartaee.servlet
- Host: GitHub
- URL: https://github.com/mvysny/fake-servlet
- Owner: mvysny
- License: mit
- Created: 2024-03-14T11:54:53.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-08-26T09:45:15.000Z (3 months ago)
- Last Synced: 2024-10-05T11:09:47.529Z (about 1 month ago)
- Language: Kotlin
- Size: 185 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fake Servlet
A fake implementation of both `javax.servlet` and `javaee.servlet` APIs. Requires Java 8+. Written in Kotlin.
To start, just add the following lines into your Gradle `build.gradle` file:
```groovy
repositories {
mavenCentral()
}
dependencies {
testImplementation("com.github.mvysny.fake-servlet:fake-servlet:1.0") // for javax.servlet
testImplementation("com.github.mvysny.fake-servlet:fake-servlet5:1.0") // for javaee.servlet
}
```> Note: obtain the newest version from the tag name above
For Maven it's really easy: the jar is published on Maven Central, so all you need to do is to add the dependency
to your `pom.xml`:```xml
com.github.mvysny.fake-servlet
fake-servlet
1.0
test
```
## Quickstart
Use the following code to obtain the mock/fake instances:
```kotlin
val context: ServletContext = FakeContext()
val servletConfig: ServletConfig = FakeServletConfig(context)
val session: HttpSession = FakeHttpSession.create(context)
val request: HttpServletRequest = FakeRequest(session)
val response: HttpServletResponse = FakeResponse()
```See the `FakeHttpEnvironment` class to tune the values returned by the `Fake*` classes;
also take a look at the individual `Fake*` classes for further configuration options.