Remove most usage of com.google.truth (#382)
* Remove most usage of com.google.truth * Remove truth entirely
This commit is contained in:
Родитель
7ee5ff7993
Коммит
ae31baf36d
|
@ -67,7 +67,6 @@ allprojects {
|
|||
|
||||
testing: [
|
||||
'junit:junit:4.12',
|
||||
'com.google.truth:truth:1.0.1',
|
||||
'org.hamcrest:hamcrest-all:1.3',
|
||||
dependencies.create('io.kotest:kotest-assertions-jvm:4.0.5') {
|
||||
exclude module: 'kotlin-stdlib'
|
||||
|
|
|
@ -35,6 +35,4 @@ dependencies {
|
|||
implementation project(':thrifty-runtime')
|
||||
|
||||
testImplementation libraries.testing
|
||||
|
||||
testImplementation 'com.google.testing.compile:compile-testing:0.18'
|
||||
}
|
|
@ -20,22 +20,20 @@
|
|||
*/
|
||||
package com.microsoft.thrifty.gen
|
||||
|
||||
import com.google.common.truth.Truth.assertAbout
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.google.common.truth.Truth.assertWithMessage
|
||||
import com.google.testing.compile.JavaSourceSubjectFactory.javaSource
|
||||
import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources
|
||||
import com.microsoft.thrifty.schema.Loader
|
||||
import com.microsoft.thrifty.schema.Schema
|
||||
import com.squareup.javapoet.JavaFile
|
||||
import io.kotest.assertions.fail
|
||||
import io.kotest.matchers.collections.shouldHaveSize
|
||||
import io.kotest.matchers.shouldBe
|
||||
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 java.io.File
|
||||
import java.util.*
|
||||
import javax.tools.JavaFileObject
|
||||
|
||||
/**
|
||||
* These tests ensure that various constructs produce valid Java code.
|
||||
|
@ -46,51 +44,6 @@ import javax.tools.JavaFileObject
|
|||
class ThriftyCodeGeneratorTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test
|
||||
fun redactedToStringCompiles() {
|
||||
val thrift = """
|
||||
namespace java test
|
||||
|
||||
struct foo {
|
||||
1: required list<string> (python.immutable) ssn (redacted)
|
||||
}
|
||||
"""
|
||||
|
||||
val schema = parse("foo.thrift", thrift)
|
||||
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val javaFiles = gen.generateTypes()
|
||||
|
||||
assertThat(javaFiles).hasSize(1)
|
||||
|
||||
assertAbout(javaSource())
|
||||
.that(javaFiles[0].toJavaFileObject())
|
||||
.compilesWithoutError()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enumGeneration() {
|
||||
val thrift = """
|
||||
namespace java enums
|
||||
|
||||
// a generated enum
|
||||
enum BuildStatus {
|
||||
OK = 0,
|
||||
FAIL = 1
|
||||
}
|
||||
"""
|
||||
|
||||
val schema = parse("enum.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val java = gen.generateTypes()
|
||||
|
||||
assertThat(java).hasSize(1)
|
||||
|
||||
assertAbout(javaSource())
|
||||
.that(java[0].toJavaFileObject())
|
||||
.compilesWithoutError()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fieldWithConstInitializer() {
|
||||
val thrift = """
|
||||
|
@ -106,25 +59,12 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("fields.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val java = gen.generateTypes()
|
||||
val jfos = ArrayList<JavaFileObject>()
|
||||
|
||||
var found = false
|
||||
for (javaFile in java) {
|
||||
if (javaFile.toString().contains("foo = fields.Constants.TEST_CONST;")) {
|
||||
found = true
|
||||
}
|
||||
if (java.none { it.toString().contains("foo = fields.Constants.TEST_CONST;") }) {
|
||||
fail("Const reference was not found in field assignment")
|
||||
}
|
||||
|
||||
assertWithMessage("Const reference was not found in field assignment").that(found).isTrue()
|
||||
|
||||
assertThat(java).hasSize(2)
|
||||
for (javaFile in java) {
|
||||
jfos.add(javaFile.toJavaFileObject())
|
||||
}
|
||||
|
||||
assertAbout(javaSources())
|
||||
.that(jfos)
|
||||
.compilesWithoutError()
|
||||
java shouldHaveSize 2
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -139,17 +79,9 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("dep.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val java = gen.generateTypes()
|
||||
val jfos = ArrayList<JavaFileObject>(java.size)
|
||||
|
||||
for (javaFile in java) {
|
||||
jfos.add(javaFile.toJavaFileObject())
|
||||
}
|
||||
|
||||
assertAbout(javaSources()).that(jfos).compilesWithoutError()
|
||||
|
||||
val file = java[0].toString()
|
||||
|
||||
assertThat(file).contains("@Deprecated") // note the change in case
|
||||
file shouldContain "@Deprecated" // note the change in case
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -163,17 +95,9 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("dep.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val java = gen.generateTypes()
|
||||
val jfos = ArrayList<JavaFileObject>(java.size)
|
||||
|
||||
for (javaFile in java) {
|
||||
jfos.add(javaFile.toJavaFileObject())
|
||||
}
|
||||
|
||||
assertAbout(javaSources()).that(jfos).compilesWithoutError()
|
||||
|
||||
val file = java[0].toString()
|
||||
|
||||
assertThat(file).contains("@Deprecated")
|
||||
file shouldContain "@Deprecated"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -187,11 +111,9 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("enum.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("@Deprecated")
|
||||
file shouldContain "@Deprecated"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -207,11 +129,9 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("enum.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("@Deprecated\n ONE(1)")
|
||||
file shouldContain "@Deprecated\n ONE(1)"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -229,11 +149,9 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("enum_nullable.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema).nullabilityAnnotationType(NullabilityAnnotationType.ANDROID_SUPPORT)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("@Nullable\n public static BuildStatus findByValue")
|
||||
file shouldContain "@Nullable\n public static BuildStatus findByValue"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -249,13 +167,11 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("no_nullability.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema).nullabilityAnnotationType(NullabilityAnnotationType.NONE)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).doesNotContain("@Nullable")
|
||||
assertThat(java).doesNotContain("import android.support.annotation")
|
||||
assertThat(java).doesNotContain("import androidx.annotation")
|
||||
file shouldNotContain "@Nullable"
|
||||
file shouldNotContain "import android.support.annotation"
|
||||
file shouldNotContain "import androidx.annotation"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -271,13 +187,11 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("nullable_android_support.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema).nullabilityAnnotationType(NullabilityAnnotationType.ANDROID_SUPPORT)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("@Nullable\n public final String bar")
|
||||
assertThat(java).contains("import android.support.annotation")
|
||||
assertThat(java).doesNotContain("import androidx.annotation")
|
||||
file shouldContain "@Nullable\n public final String bar"
|
||||
file shouldContain "import android.support.annotation"
|
||||
file shouldNotContain "import androidx.annotation"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -293,13 +207,11 @@ class ThriftyCodeGeneratorTest {
|
|||
val schema = parse("nullable_androidx.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema).nullabilityAnnotationType(NullabilityAnnotationType.ANDROIDX)
|
||||
val javaFiles = gen.generateTypes()
|
||||
val file = javaFiles[0]
|
||||
val file = javaFiles[0].toString()
|
||||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("@Nullable\n public final String bar")
|
||||
assertThat(java).contains("import androidx.annotation")
|
||||
assertThat(java).doesNotContain("import android.support.annotation")
|
||||
file shouldContain "@Nullable\n public final String bar"
|
||||
file shouldNotContain "import android.support.annotation"
|
||||
file shouldContain "import androidx.annotation"
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -327,7 +239,7 @@ class ThriftyCodeGeneratorTest {
|
|||
"""
|
||||
|
||||
val file = compile("bytes.thrift", thrift)[0]
|
||||
assertThat(file.toString()).isEqualTo("""
|
||||
file.toString() shouldBe """
|
||||
package byte_consts;
|
||||
|
||||
public final class Constants {
|
||||
|
@ -338,7 +250,7 @@ class ThriftyCodeGeneratorTest {
|
|||
}
|
||||
}
|
||||
|
||||
""".trimRawString())
|
||||
""".trimRawString()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -350,7 +262,7 @@ class ThriftyCodeGeneratorTest {
|
|||
"""
|
||||
|
||||
val file = compile("shorts.thrift", thrift)[0]
|
||||
assertThat(file.toString()).isEqualTo("""
|
||||
file.toString() shouldBe """
|
||||
package short_consts;
|
||||
|
||||
public final class Constants {
|
||||
|
@ -361,7 +273,7 @@ class ThriftyCodeGeneratorTest {
|
|||
}
|
||||
}
|
||||
|
||||
""".trimRawString())
|
||||
""".trimRawString()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -373,7 +285,7 @@ class ThriftyCodeGeneratorTest {
|
|||
"""
|
||||
|
||||
val file = compile("ints.thrift", thrift)[0]
|
||||
assertThat(file.toString()).isEqualTo("""
|
||||
file.toString() shouldBe """
|
||||
package int_consts;
|
||||
|
||||
public final class Constants {
|
||||
|
@ -384,7 +296,7 @@ class ThriftyCodeGeneratorTest {
|
|||
}
|
||||
}
|
||||
|
||||
""".trimRawString())
|
||||
""".trimRawString()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -396,7 +308,7 @@ class ThriftyCodeGeneratorTest {
|
|||
"""
|
||||
|
||||
val file = compile("longs.thrift", thrift)[0]
|
||||
assertThat(file.toString()).isEqualTo("""
|
||||
file.toString() shouldBe """
|
||||
package long_consts;
|
||||
|
||||
public final class Constants {
|
||||
|
@ -407,7 +319,7 @@ class ThriftyCodeGeneratorTest {
|
|||
}
|
||||
}
|
||||
|
||||
""".trimRawString())
|
||||
""".trimRawString()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -434,7 +346,7 @@ class ThriftyCodeGeneratorTest {
|
|||
|
||||
val file = compile("numberEquality.thrift", thrift)[0]
|
||||
|
||||
assertThat(file.toString()).contains(expectedEqualsMethod)
|
||||
file.toString() shouldContain expectedEqualsMethod
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -471,7 +383,7 @@ class ThriftyCodeGeneratorTest {
|
|||
val javaText = javaFile.toString()
|
||||
val expected = String.format(expectedFormat, thriftFile.name)
|
||||
|
||||
assertThat(javaText).isEqualTo(expected)
|
||||
javaText shouldBe expected
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -515,9 +427,9 @@ class ThriftyCodeGeneratorTest {
|
|||
""".trimRawString()
|
||||
|
||||
val thriftFile = tmp.newFile("sigil_enums.thrift")
|
||||
val javaFile = compile(thriftFile, thrift)[0]
|
||||
val javaFile = compile(thriftFile, thrift)[0].toString()
|
||||
|
||||
assertThat(javaFile.toString()).isEqualTo(expected)
|
||||
javaFile shouldBe expected
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -548,9 +460,9 @@ class ThriftyCodeGeneratorTest {
|
|||
"""
|
||||
|
||||
val thriftFile = tmp.newFile("structs_enums.thrift")
|
||||
val javaFile = compile(thriftFile, thrift)[1]
|
||||
val javaFile = compile(thriftFile, thrift)[1].toString()
|
||||
|
||||
assertThat(javaFile.toString()).contains(expected)
|
||||
javaFile shouldContain expected
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -598,7 +510,7 @@ class ThriftyCodeGeneratorTest {
|
|||
val gen = ThriftyCodeGenerator(schema).emitFileComment(false).failOnUnknownEnumValues(false)
|
||||
val javaFile = gen.generateTypes()[1]
|
||||
|
||||
assertThat(javaFile.toString()).contains(expected)
|
||||
javaFile.toString() shouldContain expected
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -633,7 +545,7 @@ class ThriftyCodeGeneratorTest {
|
|||
val thriftFile = tmp.newFile("maps_enums.thrift")
|
||||
val javaFile = compile(thriftFile, thrift)[2]
|
||||
|
||||
assertThat(javaFile.toString()).contains(expected)
|
||||
javaFile.toString() shouldContain expected
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -668,8 +580,10 @@ class ThriftyCodeGeneratorTest {
|
|||
|
||||
val thriftFile = tmp.newFile("sigil_enums.thrift")
|
||||
val javaFile = compile(thriftFile, thrift)[0]
|
||||
assertThat(javaFile.toString()).contains(expectedClassJavadoc)
|
||||
assertThat(javaFile.toString()).contains(expectedFieldJavadoc)
|
||||
val javaText = javaFile.toString()
|
||||
|
||||
javaText shouldContain expectedClassJavadoc
|
||||
javaText shouldContain expectedFieldJavadoc
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -689,28 +603,7 @@ class ThriftyCodeGeneratorTest {
|
|||
|
||||
val java = file.toString()
|
||||
|
||||
assertThat(java).contains("public Builder(@NonNull Foo struct)")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun generationWithWildcardNamespace() {
|
||||
val thrift = """
|
||||
namespace * namespace.catchall
|
||||
|
||||
struct Foo {
|
||||
1: required string bar
|
||||
}
|
||||
"""
|
||||
|
||||
val schema = parse("namespace.thrift", thrift)
|
||||
val gen = ThriftyCodeGenerator(schema)
|
||||
val java = gen.generateTypes()
|
||||
|
||||
assertThat(java).hasSize(1)
|
||||
|
||||
assertAbout(javaSource())
|
||||
.that(java[0].toJavaFileObject())
|
||||
.compilesWithoutError()
|
||||
java shouldContain "public Builder(@NonNull Foo struct)"
|
||||
}
|
||||
|
||||
private fun compile(filename: String, text: String): List<JavaFile> {
|
||||
|
|
|
@ -26,11 +26,12 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.microsoft.thrifty.TType.I32;
|
||||
import static com.microsoft.thrifty.TType.STRING;
|
||||
import static com.microsoft.thrifty.service.TMessageType.CALL;
|
||||
import static okio.ByteString.encodeUtf8;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
@ -53,7 +54,7 @@ public final class DecorationgProtocolTest {
|
|||
public void testCtor() {
|
||||
Protocol binaryProtocol = new BinaryProtocol(new BufferTransport());
|
||||
Protocol decoratingProtocol = new DecoratingProtocol(binaryProtocol) {};
|
||||
assertThat(decoratingProtocol.transport).isSameInstanceAs(binaryProtocol.transport);
|
||||
assertThat(decoratingProtocol.transport, sameInstance(binaryProtocol.transport));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,12 +24,12 @@ import com.microsoft.thrifty.TType;
|
|||
import com.microsoft.thrifty.transport.BufferTransport;
|
||||
import okio.Buffer;
|
||||
import okio.ByteString;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class JsonProtocolTest {
|
||||
private Buffer buffer;
|
||||
|
@ -45,25 +45,25 @@ public class JsonProtocolTest {
|
|||
@Test
|
||||
public void emptyJsonString() throws Exception {
|
||||
protocol.writeString("");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\"");
|
||||
assertThat(buffer.readUtf8(), is("\"\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapesNamedControlChars() throws Exception {
|
||||
protocol.writeString("\b\f\r\n\t");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\\b\\f\\r\\n\\t\"");
|
||||
assertThat(buffer.readUtf8(), is("\"\\b\\f\\r\\n\\t\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapesQuotes() throws Exception {
|
||||
protocol.writeString("\"");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\\\"\""); // or, in other words, "\""
|
||||
assertThat(buffer.readUtf8(), is("\"\\\"\"")); // or, in other words, "\""
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalStringIsQuoted() throws Exception {
|
||||
protocol.writeString("y u no quote me?");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"y u no quote me?\"");
|
||||
assertThat(buffer.readUtf8(), is("\"y u no quote me?\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,7 +71,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeListBegin(TType.STRING, 0);
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",0]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",0]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,7 +80,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeString("foo");
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",1,\"foo\"]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",1,\"foo\"]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -90,7 +90,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeString("bar");
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",2,\"foo\",\"bar\"]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",2,\"foo\",\"bar\"]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -98,7 +98,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeMapBegin(TType.STRING, TType.I32, 0);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",\"i32\",0,{}]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",\"i32\",0,{}]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -108,7 +108,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeI32(1);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",\"i32\",1,{\"key1\":1}]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",\"i32\",1,{\"key1\":1}]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -120,7 +120,7 @@ public class JsonProtocolTest {
|
|||
protocol.writeI32(2);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"str\",\"i32\",2,{\"key1\":1,\"key2\":2}]");
|
||||
assertThat(buffer.readUtf8(), is("[\"str\",\"i32\",2,{\"key1\":1,\"key2\":2}]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -139,7 +139,7 @@ public class JsonProtocolTest {
|
|||
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"map\",2,[\"str\",\"i32\",1,{\"1\":10}],[\"str\",\"i32\",1,{\"2\":20}]]");
|
||||
assertThat(buffer.readUtf8(), is("[\"map\",2,[\"str\",\"i32\",1,{\"1\":10}],[\"str\",\"i32\",1,{\"2\":20}]]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -154,21 +154,21 @@ public class JsonProtocolTest {
|
|||
|
||||
Xtruct.ADAPTER.write(protocol, xtruct);
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("" +
|
||||
assertThat(buffer.readUtf8(), is("" +
|
||||
"{" +
|
||||
"\"1\":{\"str\":\"five\"}," +
|
||||
"\"4\":{\"i8\":1}," +
|
||||
"\"9\":{\"i32\":3}," +
|
||||
"\"11\":{\"i64\":4}," +
|
||||
"\"13\":{\"dbl\":2.0}" +
|
||||
"}");
|
||||
"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binary() throws Exception {
|
||||
protocol.writeBinary(ByteString.encodeUtf8("foobar"));
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"Zm9vYmFy\"");
|
||||
assertThat(buffer.readUtf8(), is("\"Zm9vYmFy\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -190,6 +190,6 @@ public class JsonProtocolTest {
|
|||
|
||||
Xtruct read = Xtruct.ADAPTER.read(new JsonProtocol(transport));
|
||||
|
||||
Assert.assertThat(read, equalTo(xtruct));
|
||||
assertThat(read, is(xtruct));
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ import okio.Buffer;
|
|||
import okio.ByteString;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class SimpleJsonProtocolTest {
|
||||
private Buffer buffer = new Buffer();
|
||||
|
@ -36,25 +37,25 @@ public class SimpleJsonProtocolTest {
|
|||
@Test
|
||||
public void emptyJsonString() throws Exception {
|
||||
protocol.writeString("");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\"");
|
||||
assertThat(buffer.readUtf8(), is("\"\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapesNamedControlChars() throws Exception {
|
||||
protocol.writeString("\b\f\r\n\t");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\\b\\f\\r\\n\\t\"");
|
||||
assertThat(buffer.readUtf8(), is("\"\\b\\f\\r\\n\\t\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapesQuotes() throws Exception {
|
||||
protocol.writeString("\"");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"\\\"\""); // or, in other words, "\""
|
||||
assertThat(buffer.readUtf8(), is("\"\\\"\"")); // or, in other words, "\""
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalStringIsQuoted() throws Exception {
|
||||
protocol.writeString("y u no quote me?");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"y u no quote me?\"");
|
||||
assertThat(buffer.readUtf8(), is("\"y u no quote me?\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,7 +63,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeListBegin(TType.STRING, 0);
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[]");
|
||||
assertThat(buffer.readUtf8(), is("[]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,7 +72,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeString("foo");
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"foo\"]");
|
||||
assertThat(buffer.readUtf8(), is("[\"foo\"]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -81,7 +82,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeString("bar");
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
assertThat(buffer.readUtf8(), is("[\"foo\",\"bar\"]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,7 +90,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeMapBegin(TType.STRING, TType.I32, 0);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("{}");
|
||||
assertThat(buffer.readUtf8(), is("{}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,7 +100,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeI32(1);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("{\"key1\":1}");
|
||||
assertThat(buffer.readUtf8(), is("{\"key1\":1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,7 +112,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.writeI32(2);
|
||||
protocol.writeMapEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("{\"key1\":1,\"key2\":2}");
|
||||
assertThat(buffer.readUtf8(), is("{\"key1\":1,\"key2\":2}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,7 +131,7 @@ public class SimpleJsonProtocolTest {
|
|||
|
||||
protocol.writeListEnd();
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("[{\"1\":10},{\"2\":20}]");
|
||||
assertThat(buffer.readUtf8(), is("[{\"1\":10},{\"2\":20}]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,13 +146,13 @@ public class SimpleJsonProtocolTest {
|
|||
|
||||
Xtruct.ADAPTER.write(protocol, xtruct);
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("" +
|
||||
assertThat(buffer.readUtf8(), is("" +
|
||||
"{\"__thriftStruct\":\"Xtruct\"," +
|
||||
"\"string_thing\":\"five\"," +
|
||||
"\"byte_thing\":1," +
|
||||
"\"i32_thing\":3," +
|
||||
"\"i64_thing\":4," +
|
||||
"\"double_thing\":2.0}");
|
||||
"\"double_thing\":2.0}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -159,7 +160,7 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.withBinaryOutputMode(SimpleJsonProtocol.BinaryOutputMode.HEX)
|
||||
.writeBinary(ByteString.of(new byte[] { 0, 127, -1 }));
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"007fff\"");
|
||||
assertThat(buffer.readUtf8(), is("\"007fff\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,12 +168,12 @@ public class SimpleJsonProtocolTest {
|
|||
protocol.withBinaryOutputMode(SimpleJsonProtocol.BinaryOutputMode.BASE_64)
|
||||
.writeBinary(ByteString.encodeUtf8("foobar"));
|
||||
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"Zm9vYmFy\"");
|
||||
assertThat(buffer.readUtf8(), is("\"Zm9vYmFy\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonAsciiCharacters() throws Exception {
|
||||
protocol.writeString("测试");
|
||||
assertThat(buffer.readUtf8()).isEqualTo("\"测试\"");
|
||||
assertThat(buffer.readUtf8(), is("\"测试\""));
|
||||
}
|
||||
}
|
|
@ -20,11 +20,11 @@
|
|||
*/
|
||||
package com.microsoft.thrifty.transport;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import okio.Buffer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
@ -36,7 +36,7 @@ public class FramedTransportTest {
|
|||
BufferTransport bufferTranport = new BufferTransport(buffer);
|
||||
FramedTransport transport = new FramedTransport(bufferTranport);
|
||||
|
||||
transport.write("abcde".getBytes(Charsets.UTF_8));
|
||||
transport.write("abcde".getBytes(StandardCharsets.UTF_8));
|
||||
transport.flush();
|
||||
|
||||
assertThat(buffer.readInt(), is(5));
|
||||
|
@ -55,7 +55,7 @@ public class FramedTransportTest {
|
|||
assertThat(transport.read(readBuffer, 0, 5), is(5));
|
||||
assertThat(buffer.size(), is(5L)); // 4 bytes of header plus 5 bytes of frame data were read
|
||||
|
||||
assertThat(new String(readBuffer, Charsets.US_ASCII), is("abcde"));
|
||||
assertThat(new String(readBuffer, StandardCharsets.US_ASCII), is("abcde"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,7 +87,7 @@ public class FramedTransportTest {
|
|||
byte[] readBuffer = new byte[10];
|
||||
assertThat(transport.read(readBuffer, 0, 10), is(6));
|
||||
assertThat(transport.read(readBuffer, 6, 4), is(4));
|
||||
assertThat(new String(readBuffer, Charsets.UTF_8), is("abcdefghij"));
|
||||
assertThat(new String(readBuffer, StandardCharsets.UTF_8), is("abcdefghij"));
|
||||
}
|
||||
|
||||
@Test(expected = EOFException.class)
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
*/
|
||||
package com.microsoft.thrifty.util;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -43,7 +42,9 @@ public class ObfuscationUtilTest {
|
|||
|
||||
@Test
|
||||
public void summarizeObjectSet() {
|
||||
Set<Long> set = Sets.newHashSet(3L, 4L);
|
||||
Set<Long> set = new HashSet<>();
|
||||
set.add(3L);
|
||||
set.add(4L);
|
||||
String summary = ObfuscationUtil.summarizeCollection(set, "set", "i64");
|
||||
assertThat(summary, is("set<i64>(size=2)"));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
package com.microsoft.thrifty.schema
|
||||
|
||||
import com.google.common.collect.HashMultimap
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import com.microsoft.thrifty.schema.parser.ListTypeElement
|
||||
import com.microsoft.thrifty.schema.parser.MapTypeElement
|
||||
import com.microsoft.thrifty.schema.parser.ScalarTypeElement
|
||||
|
@ -379,7 +378,7 @@ internal class Linker(
|
|||
|
||||
fun resolveType(type: TypeElement): ThriftType {
|
||||
val annotationElement = type.annotations
|
||||
val annotations = annotationElement?.values ?: ImmutableMap.of()
|
||||
val annotations = annotationElement?.values ?: emptyMap()
|
||||
|
||||
typesByName[type.name]?.let {
|
||||
// If we are resolving e.g. the type of a field element, the type
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
package com.microsoft.thrifty.schema
|
||||
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import com.microsoft.thrifty.schema.parser.AnnotationElement
|
||||
import com.microsoft.thrifty.schema.parser.FieldElement
|
||||
import com.microsoft.thrifty.schema.parser.ScalarTypeElement
|
||||
|
@ -136,7 +135,7 @@ class FieldTest {
|
|||
val fieldElement = field()
|
||||
val field = Field(fieldElement, emptyMap())
|
||||
|
||||
val annotations = ImmutableMap.of<String, String>()
|
||||
val annotations = emptyMap<String, String>()
|
||||
val thriftType = BuiltinType.DOUBLE
|
||||
|
||||
val builderField = field.toBuilder()
|
||||
|
|
Загрузка…
Ссылка в новой задаче