Skip to content

Commit

Permalink
#66 test for determination of empty body in NettyRequestAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Aug 1, 2013
1 parent d3946a1 commit b49fe80
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package co.freeside.betamax.message.servlet
import io.netty.buffer.Unpooled
import io.netty.handler.codec.http.*
import org.apache.commons.collections.iterators.*
import spock.lang.Specification
import spock.lang.*
import static io.netty.handler.codec.http.HttpHeaders.Names.*
import static io.netty.handler.codec.http.HttpMethod.GET
import static io.netty.util.CharsetUtil.UTF_8

@Unroll
class NettyRequestAdapterSpec extends Specification {

private static final IteratorEnumeration EMPTY_ENUMERATION = new IteratorEnumeration(EmptyIterator.INSTANCE)
Expand Down Expand Up @@ -101,4 +103,24 @@ class NettyRequestAdapterSpec extends Specification {
request.bodyAsBinary.bytes == body
}

void "request #description if the content buffer is #contentDescription"() {
given:
nettyRequest.content() >> content

and:
def request = new NettyRequestAdapter(nettyRequest)

expect:
request.hasBody() == consideredToHaveBody

where:
content | consideredToHaveBody
Unpooled.copiedBuffer("O HAI", UTF_8) | true
Unpooled.EMPTY_BUFFER | false
null | false

description = consideredToHaveBody ? "has a body" : "does not have a body"
contentDescription = content ? "${content.readableBytes()} bytes long" : "null"
}

}

0 comments on commit b49fe80

Please sign in to comment.