4646import static org .junit .jupiter .api .Assertions .assertNotNull ;
4747import static org .junit .jupiter .api .Assertions .assertThrows ;
4848import static org .mockito .Mockito .mock ;
49+ import static org .mockito .Mockito .spy ;
4950import static org .mockito .Mockito .when ;
5051
5152class DefaultPluginXmlFactoryReadWriteTest {
@@ -73,9 +74,9 @@ void readFromInputStreamParsesPluginDescriptorCorrectly() {
7374 PluginDescriptor descriptor = defaultPluginXmlFactory .read (XmlReaderRequest .builder ()
7475 .inputStream (new ByteArrayInputStream (SAMPLE_PLUGIN_XML .getBytes ()))
7576 .build ());
76- assertThat (descriptor .getName ()).isEqualTo (NAME );
77- assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
7877 assertThat (descriptor .getArtifactId ()).isEqualTo ("sample-plugin" );
78+ assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
79+ assertThat (descriptor .getName ()).isEqualTo (NAME );
7980 assertThat (descriptor .getVersion ()).isEqualTo ("1.0.0" );
8081 }
8182
@@ -160,18 +161,18 @@ void toXmlStringGeneratesValidXml() {
160161 .artifactId ("sample-plugin" )
161162 .version ("1.0.0" )
162163 .build ());
163- assertThat (xml ).contains ("<name>" + NAME + "</name>" );
164- assertThat (xml ).contains ("<groupId>org.example</groupId>" );
165164 assertThat (xml ).contains ("<artifactId>sample-plugin</artifactId>" );
165+ assertThat (xml ).contains ("<groupId>org.example</groupId>" );
166+ assertThat (xml ).contains ("<name>" + NAME + "</name>" );
166167 assertThat (xml ).contains ("<version>1.0.0</version>" );
167168 }
168169
169170 @ Test
170171 void staticFromXmlParsesValidXml () {
171172 PluginDescriptor descriptor = DefaultPluginXmlFactory .fromXml (SAMPLE_PLUGIN_XML );
172- assertThat (descriptor .getName ()).isEqualTo (NAME );
173- assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
174173 assertThat (descriptor .getArtifactId ()).isEqualTo ("sample-plugin" );
174+ assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
175+ assertThat (descriptor .getName ()).isEqualTo (NAME );
175176 assertThat (descriptor .getVersion ()).isEqualTo ("1.0.0" );
176177 }
177178
@@ -184,22 +185,21 @@ void staticToXmlGeneratesValidXml() {
184185 .version ("1.0.0" )
185186 .build ());
186187 assertThat (xml ).contains ("<name>" + NAME + "</name>" );
187- assertThat (xml ).contains ("<name>" + NAME + "</name>" );
188188 assertThat (xml ).contains ("<groupId>org.example</groupId>" );
189189 assertThat (xml ).contains ("<artifactId>sample-plugin</artifactId>" );
190190 assertThat (xml ).contains ("<version>1.0.0</version>" );
191191 }
192192
193193 @ Test
194194 void writeWithFailingWriterThrowsXmlWriterException () {
195- String unableToWritePlugin = "Unable to write plugin" + randomUUID () ;
196- String ioEx = "ioEx" + randomUUID () ;
195+ String unableToWritePlugin = "Unable to write plugin: " + NAME ;
196+ String ioEx = "ioEx: " + NAME ;
197197 XmlWriterException exception = assertThatExceptionOfType (XmlWriterException .class )
198198 .isThrownBy (() -> defaultPluginXmlFactory .write (XmlWriterRequest .<PluginDescriptor >builder ()
199199 .writer (new Writer () {
200200 @ Override
201201 public void write (char [] cbuf , int off , int len ) {
202- throw new XmlWriterException (unableToWritePlugin , null , new IOException (ioEx ));
202+ throw new XmlWriterException (NAME , null , new IOException (ioEx ));
203203 }
204204
205205 @ Override
@@ -213,10 +213,10 @@ public void close() {}
213213 .build ())
214214 .build ()))
215215 .actual ();
216- assertThat (exception .getMessage ()).contains (unableToWritePlugin );
217216 assertThat (exception .getCause ()).isInstanceOf (XmlWriterException .class );
218217 assertThat (exception .getCause ().getCause ().getMessage ()).isEqualTo (ioEx );
219- assertThat (exception .getCause ().getMessage ()).isEqualTo (unableToWritePlugin );
218+ assertThat (exception .getCause ().getMessage ()).isEqualTo (NAME );
219+ assertThat (exception .getMessage ()).isEqualTo (unableToWritePlugin );
220220 }
221221
222222 @ Test
@@ -239,8 +239,8 @@ void readMalformedXmlThrowsXmlReaderException() {
239239 .inputStream (new ByteArrayInputStream ("<plugin><name>Broken Plugin" .getBytes ()))
240240 .build ()))
241241 .actual ();
242- assertThat (exception .getMessage ()).contains ("Unable to read plugin" );
243242 assertThat (exception .getCause ()).isInstanceOf (WstxEOFException .class );
243+ assertThat (exception .getMessage ()).contains ("Unable to read plugin" );
244244 }
245245
246246 @ Test
@@ -258,19 +258,19 @@ void readFromUrlParsesPluginDescriptorCorrectly() throws Exception {
258258 PluginDescriptor descriptor = defaultPluginXmlFactory .read (XmlReaderRequest .builder ()
259259 .inputStream (xmlFile .toUri ().toURL ().openStream ())
260260 .build ());
261- assertThat (descriptor .getName ()).isEqualTo (NAME );
262- assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
263261 assertThat (descriptor .getArtifactId ()).isEqualTo ("sample-plugin" );
262+ assertThat (descriptor .getGroupId ()).isEqualTo ("org.example" );
263+ assertThat (descriptor .getName ()).isEqualTo (NAME );
264264 assertThat (descriptor .getVersion ()).isEqualTo ("1.0.0" );
265265 }
266266
267267 @ Test
268268 void testReadWithPath () throws Exception {
269269 Path tempPath = Files .createTempFile ("plugin" , ".xml" );
270270 Files .writeString (tempPath , "<plugin/>" );
271- XmlReaderRequest request = mock (XmlReaderRequest .class );
272- when (request .getPath ()).thenReturn (tempPath );
271+ XmlReaderRequest request = spy (XmlReaderRequest .class );
273272 when (request .getInputStream ()).thenReturn (null );
273+ when (request .getPath ()).thenReturn (tempPath );
274274 when (request .getReader ()).thenReturn (null );
275275 when (request .getURL ()).thenReturn (null );
276276 when (request .isAddDefaultEntities ()).thenReturn (false );
@@ -283,9 +283,9 @@ void testReadWithPath() throws Exception {
283283 void testReadWithPathUrlDefault () throws Exception {
284284 Path tempPath = Files .createTempFile ("plugin" , ".xml" );
285285 Files .writeString (tempPath , "<plugin/>" );
286- XmlReaderRequest request = mock (XmlReaderRequest .class );
287- when (request .getPath ()).thenReturn (null );
286+ XmlReaderRequest request = spy (XmlReaderRequest .class );
288287 when (request .getInputStream ()).thenReturn (null );
288+ when (request .getPath ()).thenReturn (null );
289289 when (request .getReader ()).thenReturn (null );
290290 when (request .getURL ()).thenReturn (tempPath .toUri ().toURL ());
291291 when (request .isAddDefaultEntities ()).thenReturn (false );
0 commit comments