Skip to content

Commit

Permalink
Whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lnhrdt committed Apr 3, 2018
1 parent 9c531c6 commit c014da2
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 111 deletions.
12 changes: 6 additions & 6 deletions latte/src/main/kotlin/io/leonhardt/coffee/latte/UUIDTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import java.util.*
abstract class UUIDEntity(id: EntityID<String>) : Entity<String>(id)


abstract class UUIDEntityClass<out EntityType: UUIDEntity>(
table: IdTable<String>,
entityType: Class<EntityType>? = null
abstract class UUIDEntityClass<out EntityType : UUIDEntity>(
table: IdTable<String>,
entityType: Class<EntityType>? = null
) : EntityClass<String, EntityType>(table, entityType)

open class UUIDTable(name: String = "", columnName: String = "id") : IdTable<String>(name) {
override val id: Column<EntityID<String>> = varchar(columnName, 36)
.clientDefault { UUID.randomUUID().toString().toUpperCase() }
.primaryKey()
.entityId()
.clientDefault { UUID.randomUUID().toString().toUpperCase() }
.primaryKey()
.entityId()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package io.leonhardt.coffee.latte.coffee
import io.leonhardt.coffee.latte.UUIDEntity
import io.leonhardt.coffee.latte.UUIDEntityClass
import io.leonhardt.coffee.latte.UUIDTable
import io.leonhardt.coffee.latte.friends.*
import io.leonhardt.coffee.latte.friends.FriendEntity
import io.leonhardt.coffee.latte.friends.FriendTable
import org.jetbrains.exposed.dao.EntityID
import java.time.Instant
import java.util.*

data class CoffeeNew(val friendId: UUID)

data class Coffee(
val id: UUID,
val friendId: UUID,
val dateTime: Instant
val id: UUID,
val friendId: UUID,
val dateTime: Instant
)

object CoffeeTable : UUIDTable("coffee") {
Expand All @@ -28,10 +29,8 @@ class CoffeeEntity(id: EntityID<String>) : UUIDEntity(id) {
var dateTime by CoffeeTable.dateTime
}

fun CoffeeEntity.toCoffee(): Coffee {
return Coffee(
id = UUID.fromString(id.value),
friendId = UUID.fromString(friend.id.value),
dateTime = Instant.ofEpochMilli(dateTime.millis)
)
}
fun CoffeeEntity.toCoffee(): Coffee = Coffee(
id = UUID.fromString(id.value),
friendId = UUID.fromString(friend.id.value),
dateTime = Instant.ofEpochMilli(dateTime.millis)
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import java.util.*
data class FriendNew(val name: String, val groupId: UUID)

data class Friend(
val id: UUID,
val name: String,
val coffees: List<Coffee>,
val groupId: UUID
val id: UUID,
val name: String,
val coffees: List<Coffee>,
val groupId: UUID
)

object FriendTable : UUIDTable("friend") {
Expand All @@ -34,11 +34,9 @@ class FriendEntity(id: EntityID<String>) : UUIDEntity(id) {
var group by GroupEntity referencedOn FriendTable.group
}

fun FriendEntity.toFriend(): Friend {
return Friend(
id = UUID.fromString(id.value),
name = name,
coffees = coffees.map { it.toCoffee() },
groupId = UUID.fromString(group.id.value)
)
}
fun FriendEntity.toFriend(): Friend = Friend(
id = UUID.fromString(id.value),
name = name,
coffees = coffees.map { it.toCoffee() },
groupId = UUID.fromString(group.id.value)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import java.util.*
data class GroupNew(val name: String)

data class Group(
val id: UUID,
val name: String,
val friends: List<Friend>
val id: UUID,
val name: String,
val friends: List<Friend>
)

object GroupTable : UUIDTable("group_table") {
Expand All @@ -29,10 +29,8 @@ class GroupEntity(id: EntityID<String>) : UUIDEntity(id) {
val friends by FriendEntity referrersOn FriendTable.group
}

fun GroupEntity.toGroup(): Group {
return Group(
id = UUID.fromString(id.value),
name = name,
friends = friends.map { it.toFriend() }
)
}
fun GroupEntity.toGroup(): Group = Group(
id = UUID.fromString(id.value),
name = name,
friends = friends.map { it.toFriend() }
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension
@ActiveProfiles("test")
class LatteApplicationTests {

@Test
fun `context loads`() {
}
@Test
fun `context loads`() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class CoffeeCreateControllerTest {
val coffee = Coffee(id = UUID.randomUUID(), friendId = request.friendId, dateTime = Instant.now())
whenever(coffeeCreateService.create(request)).thenReturn(Either.right(coffee))

mockMvc.perform(post("/api/coffees")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.id", equalTo(coffee.id.toString())))
.andExpect(jsonPath("$", not(hasKey("errors"))))
mockMvc.perform(post("/api/coffees").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.id", equalTo(coffee.id.toString())))
.andExpect(jsonPath("$", not(hasKey("errors"))))
}

@Test
Expand All @@ -41,12 +39,10 @@ class CoffeeCreateControllerTest {
val errors = mapOf("mistake" to "you did it wrong")
whenever(coffeeCreateService.create(request)).thenReturn(Either.left(errors))

mockMvc.perform(post("/api/coffees")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", not(hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", equalTo("you did it wrong")))
mockMvc.perform(post("/api/coffees").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", not(hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", equalTo("you did it wrong")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class FriendCreateControllerTest {
val friend = Friend(id = UUID.randomUUID(), name = "William Ramsey", coffees = emptyList(), groupId = groupId)
whenever(friendCreateService.create(request)).thenReturn(Either.right(friend))

mockMvc.perform(post("/api/friends")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.id", equalTo(friend.id.toString())))
.andExpect(jsonPath("$", not(hasKey("errors"))))
mockMvc.perform(post("/api/friends").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.id", equalTo(friend.id.toString())))
.andExpect(jsonPath("$", not(hasKey("errors"))))
}

@Test
Expand All @@ -42,12 +40,10 @@ class FriendCreateControllerTest {
val errors = mapOf("mistake" to "you did it wrong")
whenever(friendCreateService.create(request)).thenReturn(Either.left(errors))

mockMvc.perform(post("/api/friends")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", not(hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", equalTo("you did it wrong")))
mockMvc.perform(post("/api/friends").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", not(hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", equalTo("you did it wrong")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class FriendFindAllByGroupControllerTest {
fun `when service succeeds, returns the Friends`() {
val groupId = UUID.randomUUID()
val friends = listOf(
Friend(id = UUID.randomUUID(), name = "Thomas Shouler", coffees = emptyList(), groupId = groupId),
Friend(id = UUID.randomUUID(), name = "Alex Thornburg", coffees = emptyList(), groupId = groupId),
Friend(id = UUID.randomUUID(), name = "Rodolfo Sanchez", coffees = emptyList(), groupId = groupId)
Friend(id = UUID.randomUUID(), name = "Thomas Shouler", coffees = emptyList(), groupId = groupId),
Friend(id = UUID.randomUUID(), name = "Alex Thornburg", coffees = emptyList(), groupId = groupId),
Friend(id = UUID.randomUUID(), name = "Rodolfo Sanchez", coffees = emptyList(), groupId = groupId)
)

whenever(friendFindAllByGroupService.findAllByGroup(groupId)).thenReturn(Either.right(friends))

mockMvc.perform(get("/api/groups/$groupId/friends"))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.length()").value(3))
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.length()").value(3))
}

@Test
Expand All @@ -41,9 +41,9 @@ class FriendFindAllByGroupControllerTest {
whenever(friendFindAllByGroupService.findAllByGroup(groupId)).thenReturn(Either.left(errors))

mockMvc.perform(get("/api/groups/$groupId/friends"))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
.andExpect(status().isBadRequest)
.andExpect(jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.hamcrest.Matchers
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import java.util.*
Expand All @@ -25,12 +25,10 @@ class GroupCreateControllerTest {
val group = Group(id = UUID.randomUUID(), name = "Singapore", friends = emptyList())
whenever(groupCreateService.create(request)).thenReturn(Either.right(group))

mockMvc.perform(MockMvcRequestBuilders.post("/api/groups")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(MockMvcResultMatchers.status().isOk)
.andExpect(MockMvcResultMatchers.jsonPath("$.data.id", Matchers.equalTo(group.id.toString())))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("errors"))))
mockMvc.perform(post("/api/groups").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(MockMvcResultMatchers.status().isOk)
.andExpect(MockMvcResultMatchers.jsonPath("$.data.id", Matchers.equalTo(group.id.toString())))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("errors"))))
}

@Test
Expand All @@ -39,12 +37,10 @@ class GroupCreateControllerTest {
val errors = mapOf("mistake" to "you did it wrong")
whenever(groupCreateService.create(request)).thenReturn(Either.left(errors))

mockMvc.perform(MockMvcRequestBuilders.post("/api/groups")
.contentType(MediaType.APPLICATION_JSON)
.content(request.asJson))
.andExpect(MockMvcResultMatchers.status().isBadRequest)
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
mockMvc.perform(post("/api/groups").contentType(MediaType.APPLICATION_JSON).content(request.asJson))
.andExpect(MockMvcResultMatchers.status().isBadRequest)
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.nhaarman.mockitokotlin2.whenever
import org.hamcrest.Matchers
import org.junit.jupiter.api.Test
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import java.util.*
Expand All @@ -20,27 +20,27 @@ class GroupGetAllControllerTest {
@Test
fun `when service succeeds, returns the Groups`() {
val groups = listOf(
Group(id = UUID.randomUUID(), name = "Group 1", friends = emptyList()),
Group(id = UUID.randomUUID(), name = "Group 2", friends = emptyList()),
Group(id = UUID.randomUUID(), name = "Group 3", friends = emptyList())
Group(id = UUID.randomUUID(), name = "Group 1", friends = emptyList()),
Group(id = UUID.randomUUID(), name = "Group 2", friends = emptyList()),
Group(id = UUID.randomUUID(), name = "Group 3", friends = emptyList())
)

whenever(groupGetAllService.getAll()).thenReturn(Either.right(groups))

mockMvc.perform(MockMvcRequestBuilders.get("/api/groups"))
.andExpect(MockMvcResultMatchers.status().isOk)
.andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(3))
mockMvc.perform(get("/api/groups"))
.andExpect(MockMvcResultMatchers.status().isOk)
.andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(3))
}

@Test
fun `when service fails, returns the errors`() {
val errors = mapOf("mistake" to "you did it wrong")
whenever(groupGetAllService.getAll()).thenReturn(Either.left(errors))

mockMvc.perform(MockMvcRequestBuilders.get("/api/groups"))
.andExpect(MockMvcResultMatchers.status().isBadRequest)
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
mockMvc.perform(get("/api/groups"))
.andExpect(MockMvcResultMatchers.status().isBadRequest)
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.not(Matchers.hasKey("data"))))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.length()", Matchers.equalTo(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.errors.mistake", Matchers.equalTo("you did it wrong")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class IsCloseToNow(val delta: Duration) : TypeSafeDiagnosingMatcher<Instant>() {

if (difference.abs() > delta) {
mismatchDescription
.appendValue(item)
.appendText(" was more than ")
.appendValue(delta)
.appendText(" from ")
.appendValue(now)
.appendValue(item)
.appendText(" was more than ")
.appendValue(delta)
.appendText(" from ")
.appendValue(now)
return false
}

Expand All @@ -28,9 +28,9 @@ class IsCloseToNow(val delta: Duration) : TypeSafeDiagnosingMatcher<Instant>() {

override fun describeTo(description: Description) {
description.appendText("an Instant within ")
.appendValue(delta)
.appendText(" of ")
.appendValue(now)
.appendValue(delta)
.appendText(" of ")
.appendValue(now)
}
}

Expand Down

0 comments on commit c014da2

Please sign in to comment.