From c014da295558149e09d8753c7550bfcfad96427d Mon Sep 17 00:00:00 2001 From: Leonhardt Koepsell Date: Mon, 2 Apr 2018 20:47:07 -0500 Subject: [PATCH] Whitespace --- .../io/leonhardt/coffee/latte/UUIDTable.kt | 12 +++++----- .../coffee/latte/coffee/CoffeeData.kt | 21 ++++++++-------- .../coffee/latte/friends/FriendData.kt | 22 ++++++++--------- .../coffee/latte/groups/GroupData.kt | 18 +++++++------- .../coffee/latte/LatteApplicationTests.kt | 6 ++--- .../coffee/CoffeeCreateControllerTest.kt | 22 +++++++---------- .../friends/FriendCreateControllerTest.kt | 22 +++++++---------- .../FriendFindAllByGroupControllerTest.kt | 18 +++++++------- .../latte/groups/GroupCreateControllerTest.kt | 24 ++++++++----------- .../latte/groups/GroupGetAllControllerTest.kt | 24 +++++++++---------- .../coffee/latte/support/IsCloseToNow.kt | 16 ++++++------- 11 files changed, 94 insertions(+), 111 deletions(-) diff --git a/latte/src/main/kotlin/io/leonhardt/coffee/latte/UUIDTable.kt b/latte/src/main/kotlin/io/leonhardt/coffee/latte/UUIDTable.kt index b159fc1..c1870c7 100644 --- a/latte/src/main/kotlin/io/leonhardt/coffee/latte/UUIDTable.kt +++ b/latte/src/main/kotlin/io/leonhardt/coffee/latte/UUIDTable.kt @@ -10,14 +10,14 @@ import java.util.* abstract class UUIDEntity(id: EntityID) : Entity(id) -abstract class UUIDEntityClass( - table: IdTable, - entityType: Class? = null +abstract class UUIDEntityClass( + table: IdTable, + entityType: Class? = null ) : EntityClass(table, entityType) open class UUIDTable(name: String = "", columnName: String = "id") : IdTable(name) { override val id: Column> = varchar(columnName, 36) - .clientDefault { UUID.randomUUID().toString().toUpperCase() } - .primaryKey() - .entityId() + .clientDefault { UUID.randomUUID().toString().toUpperCase() } + .primaryKey() + .entityId() } diff --git a/latte/src/main/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeData.kt b/latte/src/main/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeData.kt index dab0ed0..84958df 100644 --- a/latte/src/main/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeData.kt +++ b/latte/src/main/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeData.kt @@ -3,7 +3,8 @@ 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.* @@ -11,9 +12,9 @@ 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") { @@ -28,10 +29,8 @@ class CoffeeEntity(id: EntityID) : 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) +) diff --git a/latte/src/main/kotlin/io/leonhardt/coffee/latte/friends/FriendData.kt b/latte/src/main/kotlin/io/leonhardt/coffee/latte/friends/FriendData.kt index 37d8a1d..502f28b 100644 --- a/latte/src/main/kotlin/io/leonhardt/coffee/latte/friends/FriendData.kt +++ b/latte/src/main/kotlin/io/leonhardt/coffee/latte/friends/FriendData.kt @@ -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, - val groupId: UUID + val id: UUID, + val name: String, + val coffees: List, + val groupId: UUID ) object FriendTable : UUIDTable("friend") { @@ -34,11 +34,9 @@ class FriendEntity(id: EntityID) : 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) +) diff --git a/latte/src/main/kotlin/io/leonhardt/coffee/latte/groups/GroupData.kt b/latte/src/main/kotlin/io/leonhardt/coffee/latte/groups/GroupData.kt index 04ef7a0..3f284e4 100644 --- a/latte/src/main/kotlin/io/leonhardt/coffee/latte/groups/GroupData.kt +++ b/latte/src/main/kotlin/io/leonhardt/coffee/latte/groups/GroupData.kt @@ -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 + val id: UUID, + val name: String, + val friends: List ) object GroupTable : UUIDTable("group_table") { @@ -29,10 +29,8 @@ class GroupEntity(id: EntityID) : 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() } +) diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/LatteApplicationTests.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/LatteApplicationTests.kt index 9034690..512808a 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/LatteApplicationTests.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/LatteApplicationTests.kt @@ -11,8 +11,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ActiveProfiles("test") class LatteApplicationTests { - @Test - fun `context loads`() { - } + @Test + fun `context loads`() { + } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeCreateControllerTest.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeCreateControllerTest.kt index ce61512..7faf639 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeCreateControllerTest.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/coffee/CoffeeCreateControllerTest.kt @@ -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 @@ -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"))) } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendCreateControllerTest.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendCreateControllerTest.kt index 83314f3..46ea3c1 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendCreateControllerTest.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendCreateControllerTest.kt @@ -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 @@ -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"))) } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendFindAllByGroupControllerTest.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendFindAllByGroupControllerTest.kt index 112876c..d947152 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendFindAllByGroupControllerTest.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/friends/FriendFindAllByGroupControllerTest.kt @@ -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 @@ -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"))) } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupCreateControllerTest.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupCreateControllerTest.kt index 57a566b..60d2dd7 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupCreateControllerTest.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupCreateControllerTest.kt @@ -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.* @@ -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 @@ -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"))) } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupGetAllControllerTest.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupGetAllControllerTest.kt index 05b6122..ad0a9c7 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupGetAllControllerTest.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/groups/GroupGetAllControllerTest.kt @@ -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.* @@ -20,16 +20,16 @@ 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 @@ -37,10 +37,10 @@ class GroupGetAllControllerTest { 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"))) } } diff --git a/latte/src/test/kotlin/io/leonhardt/coffee/latte/support/IsCloseToNow.kt b/latte/src/test/kotlin/io/leonhardt/coffee/latte/support/IsCloseToNow.kt index 0b9aea8..2917880 100644 --- a/latte/src/test/kotlin/io/leonhardt/coffee/latte/support/IsCloseToNow.kt +++ b/latte/src/test/kotlin/io/leonhardt/coffee/latte/support/IsCloseToNow.kt @@ -15,11 +15,11 @@ class IsCloseToNow(val delta: Duration) : TypeSafeDiagnosingMatcher() { 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 } @@ -28,9 +28,9 @@ class IsCloseToNow(val delta: Duration) : TypeSafeDiagnosingMatcher() { override fun describeTo(description: Description) { description.appendText("an Instant within ") - .appendValue(delta) - .appendText(" of ") - .appendValue(now) + .appendValue(delta) + .appendText(" of ") + .appendValue(now) } }