Skip to content

Commit 4f0842f

Browse files
committed
test(generator): added first snapshot test of with class
1 parent e2635be commit 4f0842f

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

app.hypermedia.testing.dsl/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,15 @@
236236
<artifactId>commons-io</artifactId>
237237
<version>2.5</version>
238238
</dependency>
239+
<dependency>
240+
<groupId>io.github.json-snapshot</groupId>
241+
<artifactId>json-snapshot</artifactId>
242+
<version>1.0.17</version>
243+
</dependency>
244+
<dependency>
245+
<groupId>org.json</groupId>
246+
<artifactId>json</artifactId>
247+
<version>20180813</version>
248+
</dependency>
239249
</dependencies>
240250
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
app.hypermedia.testing.dsl.tests.CoreGeneratorTest.emptyWithClass_generatesStep=[
2+
{
3+
"map": {
4+
"steps": {
5+
"myArrayList": [
6+
{
7+
"map": {
8+
"children": {
9+
"myArrayList": [ ],
10+
"empty": true
11+
},
12+
"classId": "Foo",
13+
"type": "Class"
14+
},
15+
"empty": false
16+
}
17+
],
18+
"empty": false
19+
}
20+
},
21+
"empty": false
22+
}
23+
]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package app.hypermedia.testing.dsl.tests
2+
3+
import org.eclipse.xtext.generator.InMemoryFileSystemAccess
4+
import org.junit.jupiter.api.^extension.ExtendWith
5+
import org.eclipse.xtext.testing.extensions.InjectionExtension
6+
import org.eclipse.xtext.testing.InjectWith
7+
import com.google.inject.Inject
8+
import org.eclipse.xtext.testing.util.ParseHelper
9+
import app.hypermedia.testing.dsl.core.Model
10+
import org.junit.jupiter.api.Test
11+
import static io.github.jsonSnapshot.SnapshotMatcher.*
12+
import org.eclipse.xtext.util.CancelIndicator
13+
import org.eclipse.xtext.generator.IGeneratorContext
14+
import org.eclipse.xtext.generator.IGenerator2
15+
import org.junit.jupiter.api.BeforeAll
16+
import org.junit.jupiter.api.AfterAll
17+
import org.json.JSONObject
18+
19+
@ExtendWith(InjectionExtension)
20+
@InjectWith(CoreInjectorProvider)
21+
class CoreGeneratorTest {
22+
@Inject IGenerator2 generator
23+
@Inject ParseHelper<Model> parseHelper
24+
25+
@BeforeAll
26+
static def beforeAll() {
27+
start()
28+
}
29+
30+
@AfterAll
31+
static def afterAll() {
32+
validateSnapshots();
33+
}
34+
35+
@Test
36+
def emptyWithClass_generatesStep() {
37+
// given
38+
val model = parseHelper.parse('''
39+
With Class "Foo" {
40+
41+
}
42+
''')
43+
44+
// when
45+
val fsa = new InMemoryFileSystemAccess()
46+
generator.doGenerate(model.eResource, fsa, new GeneratorContext())
47+
println(fsa.textFiles)
48+
49+
// then
50+
val file = new JSONObject(fsa.textFiles.values.get(0).toString)
51+
expect(file).toMatchSnapshot()
52+
}
53+
54+
private static class GeneratorContext implements IGeneratorContext {
55+
56+
override getCancelIndicator() {
57+
return CancelIndicator.NullImpl
58+
}
59+
60+
}
61+
}

0 commit comments

Comments
 (0)