Skip to content

Commit

Permalink
add multipart method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Coser committed Nov 5, 2020
1 parent 1d544d4 commit 8b7ade0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/kotlin/daikon/core/Part.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package daikon.core

data class Part(val name: String, val type: String?, val content: ByteArray) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Part

if (name != other.name) return false
if (type != other.type) return false
if (!content.contentEquals(other.content)) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + content.contentHashCode()
return result
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/daikon/core/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ interface Request {
fun header(name: String): String
fun hasHeader(name: String): Boolean
fun body(): String
fun multipart(name: String): Part
fun url(): String
fun path(): String
fun <T> attribute(key: String, value: T)
fun <T> attribute(key: String) : T
fun hasAttribute(key: String) : Boolean
fun method(): Method
fun withPathParams(value: String): Request
}
}

22 changes: 22 additions & 0 deletions src/test/kotlin/daikon/core/PartTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package daikon.core

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class PartTest {
@Test
fun `same parts are equal`() {
val part1 = Part("name", null, byteArrayOf(112, 124, 111, 54))
val part2 = Part("name", null, byteArrayOf(112, 124, 111, 54))

assertThat(part1).isEqualTo(part2)
}

@Test
fun `parts with different bytearray are different`() {
val part1 = Part("name", null, byteArrayOf(112, 124, 111, 54))
val part2 = Part("name", null, byteArrayOf(112, 124, 111, 0))

assertThat(part1).isNotEqualTo(part2)
}
}
4 changes: 4 additions & 0 deletions src/test/kotlin/daikon/core/TestRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class TestRequest(
TODO("Not yet implemented")
}

override fun multipart(name: String): Part {
TODO("Not yet implemented")
}

override fun url(): String {
TODO("Not yet implemented")
}
Expand Down

0 comments on commit 8b7ade0

Please sign in to comment.