Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.