Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #44 from SaltyNote/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
zhouhao authored Feb 23, 2024
2 parents 312fe6e + 6b7df34 commit 0176bca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 46 deletions.
9 changes: 3 additions & 6 deletions src/main/kotlin/com/saltynote/service/ServiceApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ class ServiceApplication {
.build()
)
}
}

companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(ServiceApplication::class.java, *args)
}
}
fun main(args: Array<String>) {
SpringApplication.run(ServiceApplication::class.java, *args)
}
41 changes: 17 additions & 24 deletions src/main/kotlin/com/saltynote/service/utils/BaseUtils.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package com.saltynote.service.utils

import com.saltynote.service.exception.IllegalInitialException
import org.apache.commons.lang3.StringUtils

class BaseUtils private constructor() {
init {
throw IllegalInitialException("Do not instantiate me.")
}

companion object {
private var baseUrl = "https://saltynote.com"
object BaseUtils {
private var baseUrl = "https://saltynote.com"

// This is used for test or dev usage, do not call it in prod.
fun setBaseUrl(baseUrl: String) {
if (StringUtils.startsWithIgnoreCase(baseUrl, "http")) {
Companion.baseUrl = baseUrl
}
// This is used for test or dev usage, do not call it in prod.
fun setBaseUrl(baseUrl: String) {
if (StringUtils.startsWithIgnoreCase(baseUrl, "http")) {
BaseUtils.baseUrl = baseUrl
}
}

fun getPasswordResetUrl(secret: String): String {
return "$baseUrl/password/reset?token=$secret"
}
fun getPasswordResetUrl(secret: String): String {
return "$baseUrl/password/reset?token=$secret"
}

fun containsAllIgnoreCase(src: String, queries: Iterable<String>): Boolean {
if (StringUtils.isBlank(src)) {
fun containsAllIgnoreCase(src: String, queries: Iterable<String>): Boolean {
if (StringUtils.isBlank(src)) {
return false
}
for (q in queries) {
if (StringUtils.isNotBlank(q) && !StringUtils.containsIgnoreCase(src, q.trim { it <= ' ' })) {
return false
}
for (q in queries) {
if (StringUtils.isNotBlank(q) && !StringUtils.containsIgnoreCase(src, q.trim { it <= ' ' })) {
return false
}
}
return true
}
return true
}
}
16 changes: 0 additions & 16 deletions src/test/kotlin/com/saltynote/service/utils/BaseUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
package com.saltynote.service.utils

import com.saltynote.service.exception.IllegalInitialException
import com.saltynote.service.utils.BaseUtils
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import java.lang.reflect.InvocationTargetException

internal class BaseUtilsTest {
@Test
fun exceptionWhenInit() {
val exception: Exception = assertThrows(InvocationTargetException::class.java) {
val pcc = BaseUtils::class.java.getDeclaredConstructor()
pcc.setAccessible(true)
val baseUtils = pcc.newInstance()
println(baseUtils.toString())
}
assertTrue(exception.cause is IllegalInitialException)
assertThat(exception.cause!!.message).isEqualTo("Do not instantiate me.")
}

@Test
fun testSetBaseUrl() {
BaseUtils.setBaseUrl("http://baseUrl")
Expand Down

0 comments on commit 0176bca

Please sign in to comment.