1 | package com.framsticks.model; |
---|
2 | |
---|
3 | import java.io.InputStream; |
---|
4 | |
---|
5 | import org.testng.annotations.DataProvider; |
---|
6 | import org.testng.annotations.Test; |
---|
7 | |
---|
8 | import com.framsticks.params.FramsClass; |
---|
9 | import com.framsticks.params.ReflectionAccess; |
---|
10 | import com.framsticks.params.SourceInterface; |
---|
11 | import com.framsticks.parsers.FileSource; |
---|
12 | import com.framsticks.parsers.Loaders; |
---|
13 | import com.framsticks.test.TestConfiguration; |
---|
14 | |
---|
15 | import static org.fest.assertions.Assertions.*; |
---|
16 | |
---|
17 | @Test |
---|
18 | public class PackageTest extends TestConfiguration { |
---|
19 | |
---|
20 | @Test(dataProvider = "classesList") |
---|
21 | public void testFramsClass(Class<?> javaClass, String name, int paramCount) throws InstantiationException, IllegalAccessException { |
---|
22 | // log.info("testing " + name + " " + javaClass + " " + Package.class.getResource(filename)); |
---|
23 | String filename = "/info/" + name + ".info"; |
---|
24 | InputStream stream = Package.class.getResourceAsStream(filename); |
---|
25 | assertThat(stream).describedAs("stream " + filename).isNotNull(); |
---|
26 | |
---|
27 | SourceInterface source = new FileSource(stream, filename); |
---|
28 | |
---|
29 | assertThat(source.isClosed()).isFalse(); |
---|
30 | FramsClass framsClass = Loaders.loadFramsClass(source); |
---|
31 | assertThat(framsClass).isNotNull(); |
---|
32 | |
---|
33 | assertThat(framsClass.getParamCount()).isEqualTo(paramCount); |
---|
34 | ReflectionAccess access = new ReflectionAccess(javaClass, framsClass); |
---|
35 | Object object = javaClass.newInstance(); |
---|
36 | access.select(object); |
---|
37 | } |
---|
38 | |
---|
39 | @DataProvider |
---|
40 | public Object[][] classesList() { |
---|
41 | return new Object[][] { |
---|
42 | { MechPart.class, "MechPart", 20 }, |
---|
43 | { Joint.class, "Joint", 16 }, |
---|
44 | { MechJoint.class, "MechJoint", 10 }, |
---|
45 | { Neuro.class, "Neuro", 21}, |
---|
46 | { NeuroDef.class, "NeuroDef", 9}, |
---|
47 | { Part.class, "Part", 18}, |
---|
48 | // { Model.class, "Model" }, |
---|
49 | { Creature.class, "Creature", 64 }, |
---|
50 | { Genotype.class, "Genotype", 37 }, |
---|
51 | { World.class, "World", 10 } |
---|
52 | }; |
---|
53 | } |
---|
54 | } |
---|