1 package org.robolectric.annotation.processing.validator; 2 3 import static com.google.common.truth.Truth.assertAbout; 4 import static com.google.testing.compile.JavaFileObjects.forResource; 5 import static com.google.testing.compile.JavaSourcesSubjectFactory.javaSources; 6 import static org.robolectric.annotation.processing.RobolectricProcessorTest.DEFAULT_OPTS; 7 import static org.robolectric.annotation.processing.validator.SingleClassSubject.singleClass; 8 import static org.robolectric.annotation.processing.validator.Utils.SHADOW_EXTRACTOR_SOURCE; 9 10 import com.google.common.collect.ImmutableList; 11 import org.junit.Test; 12 import org.robolectric.annotation.processing.RobolectricProcessor; 13 14 public class RealObjectValidatorTest { 15 @Test 16 public void realObjectWithoutImplements_shouldNotCompile() { 17 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithoutImplements"; 18 assertAbout(singleClass()) 19 .that(testClass) 20 .failsToCompile() 21 .withErrorContaining("@RealObject without @Implements") 22 .onLine(7); 23 } 24 25 @Test 26 public void realObjectParameterizedMissingParameters_shouldNotCompile() { 27 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectParameterizedMissingParameters"; 28 assertAbout(singleClass()) 29 .that(testClass) 30 .failsToCompile() 31 .withErrorContaining("@RealObject is missing type parameters") 32 .onLine(11); 33 } 34 35 @Test 36 public void realObjectParameterizedMismatch_shouldNotCompile() { 37 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectParameterizedMismatch"; 38 assertAbout(singleClass()) 39 .that(testClass) 40 .failsToCompile() 41 .withErrorContaining("Parameter type mismatch: expecting <T,S>, was <S,T>") 42 .onLine(11); 43 } 44 45 @Test 46 public void realObjectWithEmptyImplements_shouldNotRaiseOwnError() { 47 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithEmptyImplements"; 48 assertAbout(singleClass()) 49 .that(testClass) 50 .failsToCompile() 51 .withNoErrorContaining("@RealObject"); 52 } 53 54 @Test 55 public void realObjectWithMissingClassName_shouldNotRaiseOwnError() { 56 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithMissingClassName"; 57 assertAbout(singleClass()) 58 .that(testClass) 59 .failsToCompile() 60 .withNoErrorContaining("@RealObject"); 61 } 62 63 @Test 64 public void realObjectWithEmptyClassNameNoAnything_shouldNotRaiseOwnError() { 65 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithEmptyClassNameNoAnything"; 66 assertAbout(singleClass()) 67 .that(testClass) 68 .failsToCompile() 69 .withNoErrorContaining("@RealObject"); 70 } 71 72 @Test 73 public void realObjectWithTypeMismatch_shouldNotCompile() { 74 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithWrongType"; 75 assertAbout(singleClass()) 76 .that(testClass) 77 .failsToCompile() 78 .withErrorContaining("@RealObject with type <com.example.objects.UniqueDummy>; expected <com.example.objects.Dummy>") 79 .onLine(11); 80 } 81 82 @Test 83 public void realObjectWithClassName_typeMismatch_shouldNotCompile() { 84 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithIncorrectClassName"; 85 assertAbout(singleClass()) 86 .that(testClass) 87 .failsToCompile() 88 .withErrorContaining("@RealObject with type <com.example.objects.UniqueDummy>; expected <com.example.objects.Dummy>") 89 .onLine(10); 90 } 91 92 @Test 93 public void realObjectWithCorrectType_shouldCompile() { 94 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithCorrectType"; 95 assertAbout(singleClass()) 96 .that(testClass) 97 .compilesWithoutError(); 98 } 99 100 @Test 101 public void realObjectWithCorrectType_withoutAnything_shouldCompile() { 102 assertAbout(javaSources()) 103 .that(ImmutableList.of( 104 SHADOW_EXTRACTOR_SOURCE, 105 forResource("org/robolectric/annotation/processing/shadows/ShadowRealObjectWithCorrectType.java"))) 106 .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) 107 .compilesWithoutError(); 108 } 109 110 @Test 111 public void realObjectWithCorrectAnything_shouldCompile() { 112 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithCorrectAnything"; 113 assertAbout(singleClass()) 114 .that(testClass) 115 .compilesWithoutError(); 116 } 117 118 @Test 119 public void realObjectWithCorrectClassName_shouldCompile() { 120 assertAbout(javaSources()) 121 .that(ImmutableList.of( 122 SHADOW_EXTRACTOR_SOURCE, 123 forResource("org/robolectric/annotation/processing/shadows/ShadowRealObjectWithCorrectClassName.java"))) 124 .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) 125 .compilesWithoutError(); 126 } 127 128 @Test 129 public void realObjectWithNestedClassName_shouldCompile() { 130 final String testClass = "org.robolectric.annotation.processing.shadows.ShadowRealObjectWithNestedClassName"; 131 assertAbout(singleClass()) 132 .that(testClass) 133 .compilesWithoutError(); 134 } 135 } 136