This commit is contained in:
Ben Bader 2020-08-24 09:16:49 -07:00 коммит произвёл GitHub
Родитель ace0fddfb5
Коммит c9be396db8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 152 добавлений и 180 удалений

Просмотреть файл

@ -66,7 +66,8 @@ allprojects {
],
testing: [
'junit:junit:4.13',
"org.junit.jupiter:junit-jupiter:5.6.2",
'org.hamcrest:hamcrest:2.2',
dependencies.create('io.kotest:kotest-assertions-jvm:4.0.5') {
exclude module: 'kotlin-stdlib'
@ -124,6 +125,8 @@ subprojects { sp ->
showExceptions true
showCauses true
}
useJUnitPlatform()
}
}

Просмотреть файл

@ -24,5 +24,4 @@ apply plugin: 'com.vanniktech.maven.publish'
dependencies {
api libraries.javaPoet
api libraries.kotlinPoet
testImplementation group: 'junit', name: 'junit', version: '4.13'
}

Просмотреть файл

@ -26,8 +26,6 @@ dependencies {
implementation libraries.kotlin
implementation libraries.kotlinPoet
testImplementation group: 'junit', name: 'junit', version: '4.11'
}
jar {

Просмотреть файл

@ -26,7 +26,7 @@ import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.File
class ThriftyGradlePluginTest {

Просмотреть файл

@ -24,7 +24,7 @@ import com.microsoft.thrifty.integration.gen.HasCommentBasedRedaction;
import com.microsoft.thrifty.integration.gen.HasObfuscation;
import com.microsoft.thrifty.integration.gen.HasRedaction;
import com.microsoft.thrifty.integration.gen.ObfuscatedCollections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;

Просмотреть файл

@ -40,10 +40,10 @@ import com.microsoft.thrifty.transport.Transport;
import kotlin.Unit;
import okio.ByteString;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.Arrays;
import java.util.HashMap;
@ -76,7 +76,8 @@ public abstract class ConformanceBase {
* on values returned by the abstract methods
* {@link #getServerProtocol()} and {@link #getServerTransport()}.
*/
@Rule public TestServer testServer;
@RegisterExtension
TestServer testServer;
private Transport transport;
private Protocol protocol;
@ -88,7 +89,7 @@ public abstract class ConformanceBase {
testServer = new TestServer(serverProtocol, serverTransport);
}
@Before
@BeforeEach
public void setup() throws Exception {
int port = testServer.port();
SocketTransport transport = new SocketTransport.Builder("localhost", port)
@ -133,7 +134,7 @@ public abstract class ConformanceBase {
protected abstract Protocol createProtocol(Transport transport);
@After
@AfterEach
public void teardown() throws Exception {
if (client != null) {
client.close();

Просмотреть файл

@ -28,7 +28,7 @@ import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot
import io.kotest.matchers.string.contain
import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.Arrays
import java.util.Collections

Просмотреть файл

@ -49,25 +49,30 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import okio.ByteString.Companion.encodeUtf8
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
class BinaryCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.BLOCKING, ServerProtocol.BINARY)
class CompactCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.BLOCKING, ServerProtocol.COMPACT)
class JsonCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.BLOCKING, ServerProtocol.JSON)
class NonblockingBinaryCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.NON_BLOCKING, ServerProtocol.BINARY)
class NonblockingCompactCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.NON_BLOCKING, ServerProtocol.COMPACT)
class NonblockingJsonCoroutineConformanceTest : CoroutineConformanceTests(ServerTransport.NON_BLOCKING, ServerProtocol.JSON)
/**
* A test of auto-generated service code for the standard ThriftTest
* service.
*
*
* Conformance is checked by roundtripping requests to a local server that
* is run on the official Apache Thrift Java codebase. The test server has
* an implementation of ThriftTest methods with semantics as described in the
* .thrift file itself and in the Apache Thrift git repo, along with Java code
* generated by their compiler.
*/
@RunWith(Parameterized::class)
class CoroutineConformanceTests(
abstract class CoroutineConformanceTests(
private val serverTransport: ServerTransport,
private val serverProtocol: ServerProtocol
) {
@ -78,26 +83,13 @@ class CoroutineConformanceTests(
* on values returned by the abstract methods
* [.getServerProtocol] and [.getServerTransport].
*/
lateinit var testServer: TestServer
@JvmField @RegisterExtension
val testServer: TestServer = TestServer(serverProtocol, serverTransport)
lateinit var transport: Transport
lateinit var protocol: Protocol
lateinit var client: ThriftTestClient
companion object {
@Suppress("unused")
@JvmStatic
@get:Parameterized.Parameters(name = "{0} - {1}")
val parameters: Collection<*> = listOf(
arrayOf(ServerTransport.BLOCKING, ServerProtocol.COMPACT),
arrayOf(ServerTransport.BLOCKING, ServerProtocol.JSON),
arrayOf(ServerTransport.BLOCKING, ServerProtocol.BINARY),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.COMPACT),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.JSON),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.BINARY)
)
}
/**
* When overridden in a derived class, wraps the given transport
* in a decorator, e.g. a framed transport.
@ -117,11 +109,8 @@ class CoroutineConformanceTests(
}
}
@Before
@BeforeEach
fun setup() {
testServer = TestServer(serverProtocol, serverTransport)
testServer.run()
val port = testServer.port()
val transport = SocketTransport.Builder("localhost", port)
.readTimeout(2000)
@ -142,7 +131,7 @@ class CoroutineConformanceTests(
})
}
@After
@AfterEach
fun teardown() {
client.close()
protocol.close()

Просмотреть файл

@ -48,25 +48,30 @@ import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
class BinaryConformanceTest : KotlinConformanceTest(ServerTransport.BLOCKING, ServerProtocol.BINARY)
class CompactConformanceTest : KotlinConformanceTest(ServerTransport.BLOCKING, ServerProtocol.COMPACT)
class JsonConformanceTest : KotlinConformanceTest(ServerTransport.BLOCKING, ServerProtocol.JSON)
class NonblockingBinaryConformanceTest : KotlinConformanceTest(ServerTransport.NON_BLOCKING, ServerProtocol.BINARY)
class NonblockingCompactConformanceTest : KotlinConformanceTest(ServerTransport.NON_BLOCKING, ServerProtocol.COMPACT)
class NonblockingJsonConformanceTest : KotlinConformanceTest(ServerTransport.NON_BLOCKING, ServerProtocol.JSON)
/**
* A test of auto-generated service code for the standard ThriftTest
* service.
*
*
* Conformance is checked by roundtripping requests to a local server that
* is run on the official Apache Thrift Java codebase. The test server has
* an implementation of ThriftTest methods with semantics as described in the
* .thrift file itself and in the Apache Thrift git repo, along with Java code
* generated by their compiler.
*/
@RunWith(Parameterized::class)
class KotlinConformanceTest(
abstract class KotlinConformanceTest(
private val serverTransport: ServerTransport,
private val serverProtocol: ServerProtocol
) {
@ -77,26 +82,14 @@ class KotlinConformanceTest(
* on values returned by the abstract methods
* [.getServerProtocol] and [.getServerTransport].
*/
lateinit var testServer: TestServer
@RegisterExtension
@JvmField
val testServer: TestServer = TestServer(serverProtocol, serverTransport)
lateinit var transport: Transport
lateinit var protocol: Protocol
lateinit var client: ThriftTestClient
companion object {
@Suppress("unused")
@JvmStatic
@get:Parameterized.Parameters(name = "{0} - {1}")
val parameters: Collection<*> = listOf(
arrayOf(ServerTransport.BLOCKING, ServerProtocol.BINARY),
arrayOf(ServerTransport.BLOCKING, ServerProtocol.COMPACT),
arrayOf(ServerTransport.BLOCKING, ServerProtocol.JSON),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.BINARY),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.COMPACT),
arrayOf(ServerTransport.NON_BLOCKING, ServerProtocol.JSON)
)
}
/**
* When overridden in a derived class, wraps the given transport
* in a decorator, e.g. a framed transport.
@ -116,11 +109,8 @@ class KotlinConformanceTest(
}
}
@Before
@BeforeEach
fun setup() {
testServer = TestServer(serverProtocol, serverTransport)
testServer.run()
val port = testServer.port()
val transport = SocketTransport.Builder("localhost", port)
.readTimeout(2000)
@ -141,7 +131,8 @@ class KotlinConformanceTest(
})
}
@After fun teardown() {
@AfterEach
fun teardown() {
client.close()
protocol.close()
transport.close()

Просмотреть файл

@ -30,9 +30,8 @@ import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldNotContain
import okio.buffer
import okio.sink
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File
/**
@ -42,7 +41,8 @@ import java.io.File
* Semantic tests can be found in `thrifty-integration-tests`.
*/
class ThriftyCodeGeneratorTest {
@get:Rule val tmp = TemporaryFolder()
@TempDir
lateinit var tmp: File
@Test
fun fieldWithConstInitializer() {
@ -377,7 +377,7 @@ class ThriftyCodeGeneratorTest {
""".trimRawString()
val thriftFile = tmp.newFile("sigils_consts.thrift")
val thriftFile = File(tmp, "sigils_consts.thrift")
val javaFile = compile(thriftFile, thrift)[0]
val javaText = javaFile.toString()
@ -426,7 +426,7 @@ class ThriftyCodeGeneratorTest {
""".trimRawString()
val thriftFile = tmp.newFile("sigil_enums.thrift")
val thriftFile = File(tmp, "sigil_enums.thrift")
val javaFile = compile(thriftFile, thrift)[0].toString()
javaFile shouldBe expected
@ -459,7 +459,7 @@ class ThriftyCodeGeneratorTest {
break;
"""
val thriftFile = tmp.newFile("structs_enums.thrift")
val thriftFile = File(tmp, "structs_enums.thrift")
val javaFile = compile(thriftFile, thrift)[1].toString()
javaFile shouldContain expected
@ -505,7 +505,7 @@ class ThriftyCodeGeneratorTest {
break;
"""
val thriftFile = tmp.newFile("structs_enums.thrift")
val thriftFile = File(tmp, "structs_enums.thrift")
val schema = parse(thriftFile, thrift)
val gen = ThriftyCodeGenerator(schema).emitFileComment(false).failOnUnknownEnumValues(false)
val javaFile = gen.generateTypes()[1]
@ -542,7 +542,7 @@ class ThriftyCodeGeneratorTest {
}
"""
val thriftFile = tmp.newFile("maps_enums.thrift")
val thriftFile = File(tmp, "maps_enums.thrift")
val javaFile = compile(thriftFile, thrift)[2]
javaFile.toString() shouldContain expected
@ -578,7 +578,7 @@ class ThriftyCodeGeneratorTest {
public final String bar;
"""
val thriftFile = tmp.newFile("sigil_enums.thrift")
val thriftFile = File(tmp, "sigil_enums.thrift")
val javaFile = compile(thriftFile, thrift)[0]
val javaText = javaFile.toString()
@ -619,7 +619,7 @@ class ThriftyCodeGeneratorTest {
}
private fun parse(filename: String, text: String): Schema {
return parse(tmp.newFile(filename), text)
return parse(File(tmp, filename), text)
}
private fun parse(file: File, text: String): Schema {

Просмотреть файл

@ -35,14 +35,13 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot
import io.kotest.matchers.string.contain
import io.kotest.matchers.string.shouldContain
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File
class KotlinCodeGeneratorTest {
@get:Rule
val tempDir = TemporaryFolder()
@TempDir
lateinit var tempDir: File
@Test
fun `struct to data class`() {
@ -546,7 +545,6 @@ class KotlinCodeGeneratorTest {
""".trimMargin())
}
@Ignore
@Test
fun `union wont generate struct when disabled`() {
val thrift = """
@ -958,7 +956,7 @@ class KotlinCodeGeneratorTest {
}
private fun load(thrift: String): Schema {
val file = tempDir.newFile("test.thrift").also { it.writeText(thrift) }
val file = File(tempDir, "test.thrift").also { it.writeText(thrift) }
val loader = Loader().apply { addThriftFile(file.toPath()) }
return loader.load()
}

Просмотреть файл

@ -25,7 +25,7 @@ import com.microsoft.thrifty.schema.BuiltinType
import com.squareup.kotlinpoet.*
import io.kotest.matchers.shouldBe
import okio.ByteString
import org.junit.Test
import org.junit.jupiter.api.Test
class TypeUtilsTests {
@Test fun `typeCode of builtins`() {

Просмотреть файл

@ -31,7 +31,7 @@ import okio.Buffer
import okio.ByteString
import okio.ByteString.Companion.decodeHex
import okio.ByteString.Companion.encodeUtf8
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.IOException
import java.net.ProtocolException

Просмотреть файл

@ -23,7 +23,7 @@ package com.microsoft.thrifty.protocol
import com.microsoft.thrifty.transport.BufferTransport
import io.kotest.matchers.shouldBe
import okio.Buffer
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.IOException
class CompactProtocolTest {

Просмотреть файл

@ -25,7 +25,7 @@ import com.microsoft.thrifty.transport.BufferTransport
import io.kotest.matchers.shouldBe
import okio.Buffer
import okio.ByteString.Companion.encodeUtf8
import org.junit.Test
import org.junit.jupiter.api.Test
class JsonProtocolTest {
private val buffer = Buffer()

Просмотреть файл

@ -26,7 +26,7 @@ import io.kotest.matchers.shouldBe
import okio.Buffer
import okio.ByteString.Companion.encodeUtf8
import okio.ByteString.Companion.toByteString
import org.junit.Test
import org.junit.jupiter.api.Test
class SimpleJsonProtocolTest {
private val buffer = Buffer()

Просмотреть файл

@ -20,9 +20,10 @@
*/
package com.microsoft.thrifty.transport
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import okio.Buffer
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.EOFException
import java.nio.charset.StandardCharsets
@ -81,11 +82,11 @@ class FramedTransportTest {
String(readBuffer, Charsets.UTF_8) shouldBe "abcdefghij"
}
@Test(expected = EOFException::class)
@Test
fun readHeaderWhenEOFReached() {
val buffer = Buffer()
val transport = FramedTransport(BufferTransport(buffer))
val readBuffer = ByteArray(10)
transport.read(readBuffer, 0, 10)
shouldThrow<EOFException> { transport.read(readBuffer, 0, 10) }
}
}

Просмотреть файл

@ -21,7 +21,7 @@
package com.microsoft.thrifty.util
import io.kotest.matchers.shouldBe
import org.junit.Test
import org.junit.jupiter.api.Test
class ObfuscationUtilTest {
@Test

Просмотреть файл

@ -30,7 +30,7 @@ import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.throwable.shouldHaveMessage
import okio.Buffer
import okio.ByteString.Companion.encodeUtf8
import org.junit.Test
import org.junit.jupiter.api.Test
import java.net.ProtocolException
class ProtocolUtilTest {

Просмотреть файл

@ -21,7 +21,7 @@
package com.microsoft.thrifty.schema
import io.kotest.matchers.shouldBe
import org.junit.Test
import org.junit.jupiter.api.Test
class BuiltinTypeTest {
@Test

Просмотреть файл

@ -35,7 +35,7 @@ import com.microsoft.thrifty.schema.parser.TypedefElement
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import org.junit.Test
import org.junit.jupiter.api.Test
class ConstantTest {
private val symbolTable = TestSymbolTable()

Просмотреть файл

@ -21,7 +21,7 @@
package com.microsoft.thrifty.schema
import io.kotest.matchers.shouldBe
import org.junit.Test
import org.junit.jupiter.api.Test
class FieldNamingPolicyTest {
@Test

Просмотреть файл

@ -24,13 +24,8 @@ import com.microsoft.thrifty.schema.parser.AnnotationElement
import com.microsoft.thrifty.schema.parser.FieldElement
import com.microsoft.thrifty.schema.parser.ScalarTypeElement
import com.microsoft.thrifty.schema.parser.TypeElement
import org.junit.Test
import java.util.Collections
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
class FieldTest {
private var location: Location = Location.get("", "")
@ -47,8 +42,8 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.required)
assertFalse(field.optional)
field.required shouldBe true
field.optional shouldBe false
}
@Test
@ -56,24 +51,24 @@ class FieldTest {
requiredness = Requiredness.OPTIONAL
val element = field()
val field = Field(element, emptyMap())
assertFalse(field.required)
assertTrue(field.optional)
field.required shouldBe false
field.optional shouldBe true
}
@Test
fun defaultFields() {
val element = field()
val field = Field(element, emptyMap())
assertFalse(field.required)
assertFalse(field.optional)
field.required shouldBe false
field.optional shouldBe false
}
@Test
fun unredactedAndUnobfuscatedByDefault() {
val element = field()
val field = Field(element, emptyMap())
assertFalse(field.isRedacted)
assertFalse(field.isObfuscated)
field.isRedacted shouldBe false
field.isObfuscated shouldBe false
}
@Test
@ -82,7 +77,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isRedacted)
field.isRedacted shouldBe true
}
@Test
@ -91,7 +86,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isRedacted)
field.isRedacted shouldBe true
}
@Test
@ -100,7 +95,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isRedacted)
field.isRedacted shouldBe true
}
@Test
@ -109,7 +104,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isObfuscated)
field.isObfuscated shouldBe true
}
@Test
@ -118,7 +113,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isObfuscated)
field.isObfuscated shouldBe true
}
@Test
@ -127,7 +122,7 @@ class FieldTest {
val element = field()
val field = Field(element, emptyMap())
assertTrue(field.isObfuscated)
field.isObfuscated shouldBe true
}
@Test
@ -143,12 +138,12 @@ class FieldTest {
.type(thriftType)
.build()
assertEquals(builderField.annotations, annotations)
assertEquals(builderField.type, thriftType)
builderField.annotations shouldBe annotations
builderField.type shouldBe thriftType
}
private fun annotation(name: String): AnnotationElement {
return AnnotationElement(Location.get("", ""), Collections.singletonMap(name, "true"))
return AnnotationElement(Location.get("", ""), mapOf(name to "true"))
}
private fun field(): FieldElement {

Просмотреть файл

@ -28,14 +28,13 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.throwable.shouldHaveMessage
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File
class LoaderTest {
@get:Rule
val tempDir = TemporaryFolder()
@TempDir
lateinit var tempDir: File
@Test
fun basicTest() {
@ -110,7 +109,7 @@ class LoaderTest {
}
"""
val f = tempDir.newFile("toInclude.thrift")
val f = File(tempDir, "toInclude.thrift")
f.writeText(included)
val thrift = """
@ -124,7 +123,7 @@ class LoaderTest {
}
"""
val f1 = tempDir.newFile()
val f1 = File.createTempFile("test", ".thrift", tempDir)
f1.writeText(thrift)
val schema = load(f, f1)
@ -138,8 +137,8 @@ class LoaderTest {
@Test
fun includedTypesMustBeScoped() {
val f = tempDir.newFile("toInclude.thrift")
val f1 = tempDir.newFile()
val f = File(tempDir, "toInclude.thrift")
val f1 = File.createTempFile("test", ".thrift", tempDir)
val included = """
namespace java com.microsoft.thrifty.test.scopedInclude
@ -168,8 +167,8 @@ class LoaderTest {
@Test
fun includedConstants() {
val producer = tempDir.newFile("p.thrift")
val consumer = tempDir.newFile("c.thrift")
val producer = File(tempDir, "p.thrift")
val consumer = File(tempDir, "c.thrift")
val producerThrift = "const i32 foo = 10"
@ -189,8 +188,8 @@ class LoaderTest {
@Test
fun includedConstantsMustBeScoped() {
val producer = tempDir.newFile("p.thrift")
val consumer = tempDir.newFile("c.thrift")
val producer = File(tempDir, "p.thrift")
val consumer = File(tempDir, "c.thrift")
val producerThrift = "const i32 foo = 10"
@ -211,10 +210,10 @@ class LoaderTest {
@Test
fun crazyIncludes() {
val nestedDir = tempDir.newFolder("nested")
val nestedDir = File(tempDir, "nested").apply { mkdir() }
val f1 = File(nestedDir, "a.thrift")
val f2 = tempDir.newFile("b.thrift")
val f3 = tempDir.newFile("c.thrift")
val f2 = File(tempDir, "b.thrift")
val f3 = File(tempDir, "c.thrift")
val a = """
namespace java com.microsoft.thrifty.test.crazyIncludes
@ -260,10 +259,10 @@ class LoaderTest {
@Test
fun circularInclude() {
val f1 = tempDir.newFile("A")
val f2 = tempDir.newFile("B")
val f3 = tempDir.newFile("C")
val f4 = tempDir.newFile("D")
val f1 = File(tempDir, "A")
val f2 = File(tempDir, "B")
val f3 = File(tempDir, "C")
val f4 = File(tempDir, "D")
f1.writeText("include '${f2.name}'")
f2.writeText("include '${f3.name}'")
@ -379,9 +378,9 @@ class LoaderTest {
@Test
fun includesWithRelativePaths() {
tempDir.newFolder("b")
val f1 = tempDir.newFile("a.thrift")
val f2 = tempDir.newFile("b${File.separator}b.thrift")
val dir = File(tempDir, "b").apply { mkdir() }
val f1 = File(tempDir, "a.thrift")
val f2 = File(dir, "b.thrift")
val a = """
namespace java com.microsoft.thrifty.test.includesWithRelativePaths
@ -745,8 +744,8 @@ class LoaderTest {
}
"""
val src = tempDir.newFile("src.thrift")
val dest = tempDir.newFile("dest.thrift")
val src = File(tempDir, "src.thrift")
val dest = File(tempDir, "dest.thrift")
src.writeText(imported)
dest.writeText(target)
@ -772,7 +771,7 @@ class LoaderTest {
@Test
fun addingNonExistentFileThrows() {
val folder = tempDir.newFolder().toPath()
val folder = File(tempDir, "testDir").toPath()
val doesNotExist = folder.resolve("nope.thrift")
val loader = Loader()
@ -782,7 +781,7 @@ class LoaderTest {
@Test
fun addingNonExistentIncludeDirectoryThrows() {
val doesNotExist = tempDir.root.toPath().resolve("notCreatedYet")
val doesNotExist = File(tempDir, "notCreatedYet").toPath()
val loader = Loader()
shouldThrowMessage("path must be a directory") { loader.addIncludePath(doesNotExist) }
}
@ -894,7 +893,7 @@ class LoaderTest {
@Test
fun addIncludeFileSmokeTest() {
val thriftFile = tempDir.newFile("example.thrift")
val thriftFile = File(tempDir, "example.thrift")
thriftFile.writeText("""
namespace java example
@ -902,7 +901,7 @@ class LoaderTest {
""")
val schema = Loader()
.addIncludePath(tempDir.root.toPath())
.addIncludePath(tempDir.toPath())
.load()
schema.typedefs shouldHaveSize 1
@ -961,7 +960,7 @@ class LoaderTest {
}
private fun load(thrift: String): Schema {
val f = tempDir.newFile()
val f = File.createTempFile("test", ".thrift", tempDir)
f.writeText(thrift)
val loader = Loader()

Просмотреть файл

@ -22,7 +22,7 @@ package com.microsoft.thrifty.schema
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.File
class LocationTest {

Просмотреть файл

@ -21,7 +21,7 @@
package com.microsoft.thrifty.schema
import io.kotest.matchers.shouldBe
import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.Collections
import java.util.concurrent.atomic.AtomicInteger

Просмотреть файл

@ -32,14 +32,14 @@ import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.startWith
import okio.buffer
import okio.source
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.util.UUID
class ThriftParserTest {
@Before
@BeforeEach
fun setup() {
ThriftyParserPlugins.setUUIDProvider(object : ThriftyParserPlugins.UUIDProvider {
override fun call(): UUID {
@ -48,7 +48,7 @@ class ThriftParserTest {
})
}
@After
@AfterEach
fun tearDown() {
ThriftyParserPlugins.reset()
}

Просмотреть файл

@ -19,6 +19,6 @@
* See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
*/
dependencies {
api group: 'junit', name: 'junit', version: '4.13'
api "org.junit.jupiter:junit-jupiter-api:5.6.2"
implementation 'org.apache.thrift:libthrift:0.12.0'
}

Просмотреть файл

@ -33,16 +33,19 @@ import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class TestServer implements TestRule {
public class TestServer implements Extension,
BeforeEachCallback,
AfterEachCallback {
private final ServerProtocol protocol;
private final ServerTransport transport;
@ -95,18 +98,13 @@ public class TestServer implements TestRule {
}
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
run();
base.evaluate();
} finally {
cleanupServer();
}
}
};
public void beforeEach(ExtensionContext context) {
run();
}
@Override
public void afterEach(ExtensionContext context) {
cleanupServer();
}
public void close() {