Fix SubnetTest
This commit is contained in:
@@ -7,7 +7,6 @@ import android.os.Build
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v7.util.SortedList
|
||||
import android.util.TypedValue
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.net.InetAddress
|
||||
@@ -15,7 +14,11 @@ import java.net.URLConnection
|
||||
|
||||
private val isNumericMethod by lazy { InetAddress::class.java.getMethod("isNumeric", String::class.java) }
|
||||
private val parseNumericAddressMethod by lazy {
|
||||
InetAddress::class.java.getMethod("parseNumericAddress", String::class.java)
|
||||
try {
|
||||
InetAddress::class.java.getMethod("parseNumericAddress", String::class.java)
|
||||
} catch (_: NoSuchMethodException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
private val fieldChildFragmentManager by lazy {
|
||||
val field = Fragment::class.java.getDeclaredField("mChildFragmentManager")
|
||||
@@ -24,11 +27,12 @@ private val fieldChildFragmentManager by lazy {
|
||||
}
|
||||
|
||||
fun String.isNumericAddress(): Boolean = isNumericMethod.invoke(null, this) as Boolean
|
||||
fun String.parseNumericAddress(): InetAddress = try {
|
||||
parseNumericAddressMethod.invoke(null, this) as InetAddress
|
||||
} catch (exc: InvocationTargetException) {
|
||||
throw exc.cause ?: exc
|
||||
}
|
||||
fun String.parseNumericAddress(): InetAddress =
|
||||
if (parseNumericAddressMethod == null) InetAddress.getByName(this) else try {
|
||||
parseNumericAddressMethod!!.invoke(null, this) as InetAddress
|
||||
} catch (exc: InvocationTargetException) {
|
||||
throw exc.cause ?: exc
|
||||
}
|
||||
|
||||
fun parsePort(str: String?, default: Int, min: Int = 1025): Int {
|
||||
val x = str?.toIntOrNull() ?: default
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see [Testing documentation](http://d.android.com/tools/testing)
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, (2 + 2).toLong())
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import com.github.shadowsocks.utils.Subnet
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.net.InetAddress
|
||||
|
||||
object SubnetTest {
|
||||
class SubnetTest {
|
||||
@Test
|
||||
fun parsingAndEquals() {
|
||||
Assert.assertEquals(Subnet(InetAddress.getByName("1.10.11.12"), 25), Subnet.fromString("1.10.11.12/25"))
|
||||
|
||||
Reference in New Issue
Block a user