Made config fields private
This commit is contained in:
parent
1761bb6825
commit
54d6ce6b52
3 changed files with 51 additions and 68 deletions
|
@ -52,17 +52,17 @@ class CreateConfig private constructor(
|
||||||
**/
|
**/
|
||||||
@Suppress("unused", "ArrayInDataClass")
|
@Suppress("unused", "ArrayInDataClass")
|
||||||
data class Builder(
|
data class Builder(
|
||||||
var domain: String = Constants.EMPTY,
|
private var domain: String = Constants.EMPTY,
|
||||||
var title: String = Constants.EMPTY,
|
private var title: String = Constants.EMPTY,
|
||||||
var group_guid: String = Constants.EMPTY,
|
private var group_guid: String = Constants.EMPTY,
|
||||||
var tags: Array<String> = emptyArray(),
|
private var tags: Array<String> = emptyArray(),
|
||||||
var deeplinks: Array<Map<String, String>> = emptyArray(),
|
private var deeplinks: Array<Map<String, String>> = emptyArray(),
|
||||||
var long_url: String = Constants.EMPTY,
|
private var long_url: String = Constants.EMPTY,
|
||||||
var toJson: Boolean = false
|
private var toJson: Boolean = false
|
||||||
) {
|
) {
|
||||||
fun domain(domain: String) = apply { this.domain = domain }
|
fun domain(domain: String) = apply { this.domain = domain }
|
||||||
fun title(title: String) = apply { this.title = title }
|
fun title(title: String) = apply { this.title = title }
|
||||||
fun group_guid(group_guid: String) = apply { this.group_guid = group_guid }
|
fun groupGuid(group_guid: String) = apply { this.group_guid = group_guid }
|
||||||
fun tags(tags: Array<String>) = apply { this.tags = tags }
|
fun tags(tags: Array<String>) = apply { this.tags = tags }
|
||||||
fun deeplinks(deeplinks: Array<Map<String, String>>) = apply { this.deeplinks = deeplinks }
|
fun deeplinks(deeplinks: Array<Map<String, String>>) = apply { this.deeplinks = deeplinks }
|
||||||
fun longUrl(long_url: String) = apply { this.long_url = long_url }
|
fun longUrl(long_url: String) = apply { this.long_url = long_url }
|
||||||
|
|
|
@ -59,32 +59,32 @@ class UpdateConfig private constructor(
|
||||||
**/
|
**/
|
||||||
@Suppress("unused", "ArrayInDataClass")
|
@Suppress("unused", "ArrayInDataClass")
|
||||||
data class Builder(
|
data class Builder(
|
||||||
var bitlink: String = Constants.EMPTY,
|
private var bitlink: String = Constants.EMPTY,
|
||||||
var references: Map<String, String> = emptyMap(),
|
private var references: Map<String, String> = emptyMap(),
|
||||||
var archived: Boolean = false,
|
private var archived: Boolean = false,
|
||||||
var tags: Array<String> = emptyArray(),
|
private var tags: Array<String> = emptyArray(),
|
||||||
var created_at: String = Constants.EMPTY,
|
private var created_at: String = Constants.EMPTY,
|
||||||
var title: String = Constants.EMPTY,
|
private var title: String = Constants.EMPTY,
|
||||||
var deeplinks: Array<Map<String, String>> = emptyArray(),
|
private var deeplinks: Array<Map<String, String>> = emptyArray(),
|
||||||
var created_by: String = Constants.EMPTY,
|
private var created_by: String = Constants.EMPTY,
|
||||||
var long_url: String = Constants.EMPTY,
|
private var long_url: String = Constants.EMPTY,
|
||||||
var client_id: String = Constants.EMPTY,
|
private var client_id: String = Constants.EMPTY,
|
||||||
var custom_bitlinks: Array<String> = emptyArray(),
|
private var custom_bitlinks: Array<String> = emptyArray(),
|
||||||
var link: String = Constants.EMPTY,
|
private var link: String = Constants.EMPTY,
|
||||||
var id: String = Constants.EMPTY,
|
private var id: String = Constants.EMPTY,
|
||||||
var toJson: Boolean = false
|
private var toJson: Boolean = false
|
||||||
) {
|
) {
|
||||||
fun bitlink(bitlink: String) = apply { this.bitlink = bitlink }
|
fun bitlink(bitlink: String) = apply { this.bitlink = bitlink }
|
||||||
fun references(references: Map<String, String>) = apply { this.references = references }
|
fun references(references: Map<String, String>) = apply { this.references = references }
|
||||||
fun archived(archived: Boolean) = apply { this.archived = archived }
|
fun archived(archived: Boolean) = apply { this.archived = archived }
|
||||||
fun tags(tags: Array<String>) = apply { this.tags = tags }
|
fun tags(tags: Array<String>) = apply { this.tags = tags }
|
||||||
fun createdAt(created_at: String) = apply { this.created_at = created_at }
|
fun createdAt(createdAt: String) = apply { this.created_at = createdAt }
|
||||||
fun title(title: String) = apply { this.title = title }
|
fun title(title: String) = apply { this.title = title }
|
||||||
fun deeplinks(deeplinks: Array<Map<String, String>>) = apply { this.deeplinks = deeplinks }
|
fun deepLinks(deepLinks: Array<Map<String, String>>) = apply { this.deeplinks = deepLinks }
|
||||||
fun createdBy(created_by: String) = apply { this.created_by = created_by }
|
fun createdBy(createdBy: String) = apply { this.created_by = createdBy }
|
||||||
fun longUrl(long_url: String) = apply { this.long_url = long_url }
|
fun longUrl(longUrl: String) = apply { this.long_url = longUrl }
|
||||||
fun clientId(client_id: String) = apply { this.client_id = client_id }
|
fun clientId(clientId: String) = apply { this.client_id = clientId }
|
||||||
fun customBitlinks(custom_bitlinks: Array<String>) = apply { this.custom_bitlinks = custom_bitlinks }
|
fun customBitlinks(customBitlinks: Array<String>) = apply { this.custom_bitlinks = customBitlinks }
|
||||||
fun link(link: String) = apply { this.link = link }
|
fun link(link: String) = apply { this.link = link }
|
||||||
fun id(id: String) = apply { this.id = id }
|
fun id(id: String) = apply { this.id = id }
|
||||||
fun toJson(toJson: Boolean) = apply { this.toJson = toJson }
|
fun toJson(toJson: Boolean) = apply { this.toJson = toJson }
|
||||||
|
|
|
@ -33,15 +33,7 @@ package net.thauvin.erik.bitly
|
||||||
|
|
||||||
import assertk.all
|
import assertk.all
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
import assertk.assertions.contains
|
import assertk.assertions.*
|
||||||
import assertk.assertions.isEmpty
|
|
||||||
import assertk.assertions.isEqualTo
|
|
||||||
import assertk.assertions.isFalse
|
|
||||||
import assertk.assertions.isNotEqualTo
|
|
||||||
import assertk.assertions.isTrue
|
|
||||||
import assertk.assertions.matches
|
|
||||||
import assertk.assertions.prop
|
|
||||||
import assertk.assertions.startsWith
|
|
||||||
import net.thauvin.erik.bitly.Utils.isValidUrl
|
import net.thauvin.erik.bitly.Utils.isValidUrl
|
||||||
import net.thauvin.erik.bitly.Utils.removeHttp
|
import net.thauvin.erik.bitly.Utils.removeHttp
|
||||||
import net.thauvin.erik.bitly.Utils.toEndPoint
|
import net.thauvin.erik.bitly.Utils.toEndPoint
|
||||||
|
@ -51,11 +43,7 @@ import org.json.JSONObject
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import kotlin.test.Test
|
import kotlin.test.*
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertFailsWith
|
|
||||||
import kotlin.test.assertFalse
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
class BitlyTest {
|
class BitlyTest {
|
||||||
private val bitly = with(File("local.properties")) {
|
private val bitly = with(File("local.properties")) {
|
||||||
|
@ -219,18 +207,15 @@ class BitlyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `create bitlink with config`() {
|
fun `create bitlink with config`() {
|
||||||
var config = CreateConfig.Builder().apply {
|
var config = CreateConfig.Builder().longUrl(longUrl).build()
|
||||||
long_url = longUrl
|
|
||||||
}.build()
|
|
||||||
assertThat(bitly.bitlinks().create(config), "create(config)")
|
assertThat(bitly.bitlinks().create(config), "create(config)")
|
||||||
.matches("https://\\w+.\\w{2}/\\w{7}".toRegex())
|
.matches("https://\\w+.\\w{2}/\\w{7}".toRegex())
|
||||||
|
|
||||||
config = CreateConfig.Builder().apply {
|
config = CreateConfig.Builder()
|
||||||
domain = "bit.ly"
|
.domain("bit.ly")
|
||||||
title = "Erik's Blog"
|
.title("Erik's Blog")
|
||||||
tags = arrayOf("erik", "thauvin", "blog", "weblog")
|
.tags(arrayOf("erik", "thauvin", "blog", "weblog"))
|
||||||
long_url = longUrl
|
.longUrl(longUrl).build()
|
||||||
}.build()
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
shortUrl,
|
shortUrl,
|
||||||
bitly.bitlinks().create(config)
|
bitly.bitlinks().create(config)
|
||||||
|
@ -263,36 +248,34 @@ class BitlyTest {
|
||||||
bl.update(shortUrl, link = longUrl)
|
bl.update(shortUrl, link = longUrl)
|
||||||
assertThat(bl.lastCallResponse).prop(CallResponse::isSuccessful).isTrue()
|
assertThat(bl.lastCallResponse).prop(CallResponse::isSuccessful).isTrue()
|
||||||
|
|
||||||
assertEquals(Constants.FALSE, bl.update("bit.ly/407GjJU", id = "foo"))
|
assertEquals(Constants.FALSE, bl.update("bit.ly/407GjJU", id = "foo"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `update bitlink with config`() {
|
fun `update bitlink with config`() {
|
||||||
val bl = bitly.bitlinks()
|
val bl = bitly.bitlinks()
|
||||||
var config = UpdateConfig.Builder().apply {
|
var config = UpdateConfig.Builder()
|
||||||
bitlink(shortUrl)
|
.bitlink(shortUrl)
|
||||||
title("Erik's Weblog")
|
.title("Erik's Weblog")
|
||||||
tags(arrayOf("blog", "weblog"))
|
.tags(arrayOf("blog", "weblog"))
|
||||||
archived(true)
|
.archived(true)
|
||||||
}.build()
|
.build()
|
||||||
|
|
||||||
assertEquals(Constants.TRUE, bl.update(config))
|
assertEquals(Constants.TRUE, bl.update(config))
|
||||||
|
|
||||||
config = UpdateConfig.Builder().apply {
|
config = UpdateConfig.Builder()
|
||||||
bitlink(shortUrl)
|
.bitlink(shortUrl)
|
||||||
toJson(true)
|
.toJson(true)
|
||||||
}.build()
|
.build()
|
||||||
|
|
||||||
assertThat(bl.update(config), "update(tags)").contains("\"tags\":[]")
|
assertThat(bl.update(config), "update(tags)").contains("\"tags\":[]")
|
||||||
|
|
||||||
config = UpdateConfig.Builder().apply {
|
config = UpdateConfig.Builder()
|
||||||
bitlink(shortUrl)
|
.bitlink(shortUrl)
|
||||||
link(longUrl)
|
.link(longUrl)
|
||||||
}.build()
|
.build()
|
||||||
|
|
||||||
assertEquals(Constants.TRUE, bl.update(config))
|
assertEquals(Constants.TRUE, bl.update(config))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue