@@ -36,21 +36,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
3636 """
3737 )
3838
39- private val jsonStub =
40- java(
41- """
42- package com.squareup.moshi;
43-
44- import java.lang.annotation.Retention;
45- import java.lang.annotation.RetentionPolicy;
46-
47- @Retention(RetentionPolicy.RUNTIME)
48- public @interface Json {
49- String name();
50- }
51- """
52- )
53-
5439 private val adaptedByStub =
5540 kotlin(
5641 """
@@ -114,7 +99,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
11499 lint()
115100 .files(
116101 jsonClassStub,
117- jsonStub,
118102 jsonInflaterStub,
119103 kotlin(
120104 """
@@ -146,7 +130,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
146130 lint()
147131 .files(
148132 jsonClassStub,
149- jsonStub,
150133 jsonInflaterStub,
151134 kotlin(
152135 """
@@ -180,7 +163,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
180163 lint()
181164 .files(
182165 jsonClassStub,
183- jsonStub,
184166 jsonInflaterStub,
185167 kotlin(
186168 """
@@ -212,7 +194,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
212194 lint()
213195 .files(
214196 jsonClassStub,
215- jsonStub,
216197 jsonInflaterStub,
217198 adaptedByStub,
218199 kotlin(
@@ -245,7 +226,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
245226 lint()
246227 .files(
247228 jsonClassStub,
248- jsonStub,
249229 jsonInflaterStub,
250230 adaptedByStub,
251231 parameterizedTypeStub,
@@ -284,7 +264,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
284264 lint()
285265 .files(
286266 jsonClassStub,
287- jsonStub,
288267 jsonInflaterStub,
289268 adaptedByStub,
290269 parameterizedTypeStub,
@@ -331,8 +310,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
331310 fun testMissingJsonClassAnnotation () {
332311 lint()
333312 .files(
334- jsonClassStub,
335- jsonStub,
336313 jsonInflaterStub,
337314 kotlin(
338315 """
@@ -372,7 +349,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
372349 lint()
373350 .files(
374351 jsonClassStub,
375- jsonStub,
376352 jsonInflaterStub,
377353 kotlin(
378354 """
@@ -404,7 +380,6 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
404380 lint()
405381 .files(
406382 jsonClassStub,
407- jsonStub,
408383 jsonInflaterStub,
409384 kotlin(
410385 """
@@ -440,4 +415,79 @@ class JsonInflaterMoshiCompatibilityDetectorTest : LintDetectorTest() {
440415 """
441416 )
442417 }
418+
419+ @Test
420+ fun testEnumClass () {
421+ lint()
422+ .files(
423+ jsonClassStub,
424+ jsonInflaterStub,
425+ kotlin(
426+ """
427+ package test
428+
429+ import com.squareup.moshi.JsonClass
430+ import slack.commons.json.JsonInflater
431+
432+ @JsonClass(generateAdapter = false)
433+ enum class ValidEnum {
434+ UNKNOWN,
435+ UP,
436+ DOWN,
437+ LEFT,
438+ RIGHT
439+ }
440+
441+ fun useJsonInflater(jsonInflater: JsonInflater) {
442+ val model = jsonInflater.inflate("{}", ValidEnum::class.java)
443+ val json = jsonInflater.deflate(model, ValidEnum::class.java)
444+ }
445+ """
446+ ),
447+ )
448+ .run ()
449+ .expectClean()
450+ }
451+
452+ @Test
453+ fun testEnumClassMissingJsonClassAnnotation () {
454+ lint()
455+ .files(
456+ jsonClassStub,
457+ jsonInflaterStub,
458+ kotlin(
459+ """
460+ package test
461+
462+ import com.squareup.moshi.JsonClass
463+ import slack.commons.json.JsonInflater
464+
465+ enum class ValidEnum {
466+ UNKNOWN,
467+ UP,
468+ DOWN,
469+ LEFT,
470+ RIGHT
471+ }
472+
473+ fun useJsonInflater(jsonInflater: JsonInflater) {
474+ val model = jsonInflater.inflate("{}", ValidEnum::class.java)
475+ val json = jsonInflater.deflate(model, ValidEnum::class.java)
476+ }
477+ """
478+ ),
479+ )
480+ .run ()
481+ .expect(
482+ """
483+ src/test/ValidEnum.kt:16: Error: Using JsonInflater.inflate/deflate with a Moshi-incompatible type. [JsonInflaterMoshiIncompatibleType]
484+ val model = jsonInflater.inflate("{}", ValidEnum::class.java)
485+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
486+ src/test/ValidEnum.kt:17: Error: Using JsonInflater.inflate/deflate with a Moshi-incompatible type. [JsonInflaterMoshiIncompatibleType]
487+ val json = jsonInflater.deflate(model, ValidEnum::class.java)
488+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489+ 2 errors
490+ """
491+ )
492+ }
443493}
0 commit comments