Upgrade to JDK 16, Kotlin 1.3.21 and Gradle 7.1.1
This commit is contained in:
parent
c8259385f3
commit
8c86509e62
18 changed files with 74 additions and 48 deletions
|
@ -56,8 +56,8 @@ class Isgd private constructor() {
|
|||
private fun callApi(url: String): String {
|
||||
val connection = URL(url).openConnection() as HttpURLConnection
|
||||
connection.setRequestProperty(
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
|
||||
)
|
||||
if (connection.responseCode in 200..399) {
|
||||
return connection.inputStream.bufferedReader().readText()
|
||||
|
@ -77,10 +77,10 @@ class Isgd private constructor() {
|
|||
@JvmOverloads
|
||||
@Throws(IsgdException::class)
|
||||
fun lookup(
|
||||
shorturl: String,
|
||||
callback: String = "",
|
||||
format: Format = Format.SIMPLE,
|
||||
isVgd: Boolean = false
|
||||
shorturl: String,
|
||||
callback: String = "",
|
||||
format: Format = Format.SIMPLE,
|
||||
isVgd: Boolean = false
|
||||
): String {
|
||||
if (shorturl.isEmpty()) {
|
||||
throw IllegalArgumentException("Please specify a valid short URL to lookup.")
|
||||
|
@ -104,12 +104,12 @@ class Isgd private constructor() {
|
|||
@JvmOverloads
|
||||
@Throws(IsgdException::class)
|
||||
fun shorten(
|
||||
url: String,
|
||||
shorturl: String = "",
|
||||
callback: String = "",
|
||||
logstats: Boolean = false,
|
||||
format: Format = Format.SIMPLE,
|
||||
isVgd: Boolean = false
|
||||
url: String,
|
||||
shorturl: String = "",
|
||||
callback: String = "",
|
||||
logstats: Boolean = false,
|
||||
format: Format = Format.SIMPLE,
|
||||
isVgd: Boolean = false
|
||||
): String {
|
||||
if (url.isEmpty()) {
|
||||
throw IllegalArgumentException("Please enter a valid URL to shorten.")
|
||||
|
|
|
@ -45,9 +45,9 @@ class IsgdTest {
|
|||
@Test
|
||||
fun testException() {
|
||||
assertFailsWith(
|
||||
message = "URL is already shorten",
|
||||
exceptionClass = IsgdException::class,
|
||||
block = { Isgd.shorten(shortUrl) }
|
||||
message = "URL is already shorten",
|
||||
exceptionClass = IsgdException::class,
|
||||
block = { Isgd.shorten(shortUrl) }
|
||||
)
|
||||
|
||||
try {
|
||||
|
@ -68,17 +68,17 @@ class IsgdTest {
|
|||
fun testLookupJson() {
|
||||
assertEquals("{ \"url\": \"$url\" }", Isgd.lookup(shortUrl, format = Format.JSON))
|
||||
assertEquals(
|
||||
"test({ \"url\": \"$url\" });",
|
||||
Isgd.lookup(shortUrl, callback = "test", format = Format.JSON),
|
||||
"with callback"
|
||||
"test({ \"url\": \"$url\" });",
|
||||
Isgd.lookup(shortUrl, callback = "test", format = Format.JSON),
|
||||
"with callback"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLookupXml() {
|
||||
assertEquals(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><output><url>$url</url></output>",
|
||||
Isgd.lookup(shortUrl, format = Format.XML)
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><output><url>$url</url></output>",
|
||||
Isgd.lookup(shortUrl, format = Format.XML)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -92,18 +92,18 @@ class IsgdTest {
|
|||
fun testShortenJson() {
|
||||
assertEquals("{ \"shorturl\": \"$shortUrl\" }", Isgd.shorten(url, format = Format.JSON))
|
||||
assertEquals(
|
||||
"test({ \"shorturl\": \"$shortUrl\" });",
|
||||
Isgd.shorten(url, callback = "test", format = Format.JSON),
|
||||
"with callback"
|
||||
"test({ \"shorturl\": \"$shortUrl\" });",
|
||||
Isgd.shorten(url, callback = "test", format = Format.JSON),
|
||||
"with callback"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShortenXml() {
|
||||
assertEquals(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
"<output><shorturl>$shortUrl</shorturl></output>",
|
||||
Isgd.shorten(url, format = Format.XML)
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
"<output><shorturl>$shortUrl</shorturl></output>",
|
||||
Isgd.shorten(url, format = Format.XML)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue