diff --git a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala index 6aa717de3b8..e30c06d2fa1 100644 --- a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala +++ b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala @@ -1,12 +1,13 @@ package tests.telemetry +import java.util.Optional +import java.{util => ju} + import scala.util.Random.nextBoolean + import scala.meta.internal.jdk.CollectionConverters._ import scala.meta.internal.telemetry -import java.util.Optional -import java.{util => ju} - object SampleReports { private case class OptionalControl(setEmpty: Boolean) private case class MapControl(setEmpty: Boolean) diff --git a/tests/unit/src/test/scala/tests/telemetry/SerializationSuite.scala b/tests/unit/src/test/scala/tests/telemetry/SerializationSuite.scala index 82e121af5a6..f2f59ddd420 100644 --- a/tests/unit/src/test/scala/tests/telemetry/SerializationSuite.scala +++ b/tests/unit/src/test/scala/tests/telemetry/SerializationSuite.scala @@ -1,8 +1,9 @@ package tests.telemetry -import tests.BaseSuite import scala.meta.internal.telemetry +import tests.BaseSuite + /* Test checking correctness of to/from JSON serialization for telemetry model. It's purpouse is to check if Optional[T] fields and Java collections are correctly serialized. Optional fields would be used to evolve the model in backward compatible way, however by default GSON can initialize Optional fields to null if they're missing in the json fields. diff --git a/tests/unit/src/test/scala/tests/telemetry/SourceCodeSanitizerSuite.scala b/tests/unit/src/test/scala/tests/telemetry/SourceCodeSanitizerSuite.scala index 26f652020dd..ecab1f4027d 100644 --- a/tests/unit/src/test/scala/tests/telemetry/SourceCodeSanitizerSuite.scala +++ b/tests/unit/src/test/scala/tests/telemetry/SourceCodeSanitizerSuite.scala @@ -1,14 +1,15 @@ package tests.telemetry -import tests.BaseSuite -import scala.meta.internal.metals.SourceCodeSanitizer import scala.meta.internal.metals.ScalametaSourceCodeTransformer +import scala.meta.internal.metals.SourceCodeSanitizer + +import tests.BaseSuite class SourceCodeSanitizerSuite extends BaseSuite { val sanitizer = new SourceCodeSanitizer(ScalametaSourceCodeTransformer) - val sampleScalaInput = + val sampleScalaInput: String = """ |package some.namespace.of.my.app |class Foo{ @@ -23,14 +24,14 @@ class SourceCodeSanitizerSuite extends BaseSuite { | else -1 |} """.stripMargin - val sampleScalaOutput = + val sampleScalaOutput: String = """package som0.namxxxxx1.of.my.ap4 |class Fo0 { def myFx5: Int = 42 } |trait Ba1 { def myBxxxxxxx6: String = "--_-----------------" } |object Fooxx7 extends Fo0 with Ba1 { def comxxx8(inpx9: String, oth10: Ba1): Unit = if (myBxxxxxxx6.contains("-----------------") || this.myBxxxxxxx6 == oth10.myBxxxxxxx6) myFx5 * 42 else -1 } """.stripMargin - val sampleStackTraceElements = + val sampleStackTraceElements: String = """ |scala.meta.internal.pc.completions.OverrideCompletions.scala$meta$internal$pc$completions$OverrideCompletions$$getMembers(OverrideCompletions.scala:180) | scala.meta.internal.pc.completions.OverrideCompletions$OverrideCompletion.contribute(OverrideCompletions.scala:79) @@ -41,7 +42,7 @@ class SourceCodeSanitizerSuite extends BaseSuite { | |""".stripMargin - val sampleJavaInput = + val sampleJavaInput: String = """ |package scala.meta.internal.telemetry; | @@ -67,7 +68,7 @@ class SourceCodeSanitizerSuite extends BaseSuite { } """.stripMargin - val sampleStackTrace = + val sampleStackTrace: String = """ |java.lang.RuntimeException | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) @@ -85,12 +86,12 @@ class SourceCodeSanitizerSuite extends BaseSuite { test("erases names from sources in Scala") { val input = sampleScalaInput val expected = sampleScalaOutput - assertEquals(expected.trim(), sanitizer(input).trim()) + assertNoDiff(sanitizer(input), expected) } test("erases sources in non parsable sources") { // TODO: Java parsing val input = sampleJavaInput - assertEquals("", sanitizer(input).trim()) + assertNoDiff(sanitizer(input), "") } test("erases names from markdown snippets") { @@ -155,7 +156,7 @@ class SourceCodeSanitizerSuite extends BaseSuite { .map(_.trim()) .filterNot(_.isEmpty()) .mkString(System.lineSeparator()) - assertEquals(trimLines(expected), trimLines(sanitizer(input))) + assertNoDiff(trimLines(sanitizer(input)), trimLines(expected)) } } diff --git a/tests/unit/src/test/scala/tests/telemetry/TelemetryReporterSuite.scala b/tests/unit/src/test/scala/tests/telemetry/TelemetryReporterSuite.scala index 35fa1686673..92091f7b79d 100644 --- a/tests/unit/src/test/scala/tests/telemetry/TelemetryReporterSuite.scala +++ b/tests/unit/src/test/scala/tests/telemetry/TelemetryReporterSuite.scala @@ -1,22 +1,24 @@ package tests.telemetry -import tests.BaseSuite -import tests.telemetry.SampleReports -import scala.meta.internal.telemetry -import scala.meta.internal.metals +import java.io.IOException +import java.net.InetSocketAddress +import java.net.ServerSocket + +import scala.collection.mutable +import scala.util.control.NonFatal + import scala.meta.internal.jdk.CollectionConverters._ import scala.meta.internal.jdk.OptionConverters._ +import scala.meta.internal.metals +import scala.meta.internal.telemetry -import io.undertow.server.handlers.PathHandler -import java.net.ServerSocket -import java.io.IOException -import scala.util.control.NonFatal -import scala.collection.mutable -import java.net.InetSocketAddress import io.undertow.server.handlers.BlockingHandler +import io.undertow.server.handlers.PathHandler +import tests.BaseSuite +import tests.telemetry.SampleReports class TelemetryReporterSuite extends BaseSuite { - def simpleReport(id: String) = metals.Report( + def simpleReport(id: String): metals.Report = metals.Report( name = "name", text = "text", shortSummary = "sumamry", @@ -106,7 +108,7 @@ object MockTelemetryServer { def apply( host: String, preferredPort: Int, - )(implicit ctx: Context) = { + )(implicit ctx: Context): Undertow = { val port = freePort(host, preferredPort) val baseHandler = path()