9
9
10
10
import static org .hamcrest .CoreMatchers .instanceOf ;
11
11
12
+ import java .io .ByteArrayInputStream ;
12
13
import java .io .File ;
13
14
import java .io .InputStream ;
14
15
import java .nio .file .Files ;
15
16
import java .nio .file .StandardCopyOption ;
17
+ import java .util .Properties ;
16
18
17
19
import javax .inject .Inject ;
18
20
30
32
import org .jboss .forge .roaster .model .JavaType ;
31
33
import org .jboss .forge .roaster .model .source .JavaClassSource ;
32
34
import org .jboss .forge .roaster .model .source .JavaSource ;
35
+ import org .jboss .forge .roaster .model .util .FormatterProfileReader ;
33
36
import org .jboss .shrinkwrap .api .ShrinkWrap ;
34
37
import org .jboss .shrinkwrap .api .asset .FileAsset ;
35
38
import org .junit .Assert ;
@@ -105,8 +108,9 @@ public void testParserClass() throws Exception
105
108
}
106
109
107
110
@ Test
108
- public void testCustomClassFormatting () throws Exception
111
+ public void testDefaultClassFormatting () throws Exception
109
112
{
113
+ configuration .clearProperty (JavaResource .FORMATTER_PROFILE_PATH_KEY );
110
114
String forgeFormatterContents = Streams .toString (getClass ().getResourceAsStream ("formatter_forge.jv" ));
111
115
String eclipseFormatterContents = Streams .toString (getClass ().getResourceAsStream ("formatter_eclipse.jv" ));
112
116
File tmpFile = File .createTempFile ("MyClass" , ".java" );
@@ -124,4 +128,32 @@ public void testCustomClassFormatting() throws Exception
124
128
resource .setContents (forgeFormatterContents );
125
129
Assert .assertEquals (eclipseFormatterContents , resource .getContents ());
126
130
}
131
+
132
+ @ Test
133
+ public void testCustomClassFormattingProperties () throws Exception
134
+ {
135
+ configuration .clearProperty (JavaResource .FORMATTER_PROFILE_PATH_KEY );
136
+ String forgeFormatterContents = Streams .toString (getClass ().getResourceAsStream ("formatter_forge.jv" ));
137
+ File tmpFile = File .createTempFile ("MyClass" , ".java" );
138
+ tmpFile .deleteOnExit ();
139
+ JavaResource resource = resourceFactory .create (JavaResource .class , tmpFile );
140
+ resource .setContents (forgeFormatterContents );
141
+ Assert .assertEquals (forgeFormatterContents , resource .getContents ());
142
+ File profileFile = File .createTempFile ("profile" , ".xml" );
143
+ try (InputStream is = getClass ().getResourceAsStream ("eclipse_profile.xml" ))
144
+ {
145
+ Files .copy (is , profileFile .toPath (), StandardCopyOption .REPLACE_EXISTING );
146
+ }
147
+ Properties properties = null ;
148
+ try (InputStream is = getClass ().getResourceAsStream ("forge_profile.xml" ))
149
+ {
150
+ FormatterProfileReader reader = FormatterProfileReader .fromEclipseXml (is );
151
+ properties = reader .getPropertiesFor ("Forge" );
152
+ }
153
+ configuration .setProperty (JavaResource .FORMATTER_PROFILE_PATH_KEY , profileFile .getAbsolutePath ());
154
+ resource = resourceFactory .create (JavaResource .class , tmpFile );
155
+ resource .setContents (new ByteArrayInputStream (forgeFormatterContents .getBytes ()), properties );
156
+ Assert .assertEquals (forgeFormatterContents , resource .getContents ());
157
+ }
158
+
127
159
}
0 commit comments