Skip to content

Commit bbf71ef

Browse files
authored
XML file formatting test added (#243)
1 parent ccea9c6 commit bbf71ef

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

vscode/src/test/constants.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,49 @@ public class RefactorActions {
163163
}
164164
`;
165165

166+
export const FORMATTED_POM_XML: string = `<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
167+
<modelVersion>4.0.0</modelVersion>
168+
<groupId>org.netbeans.demo.vscode.t1</groupId>
169+
<artifactId>basicapp</artifactId>
170+
<version>1.0</version>
171+
<properties>
172+
<maven.compiler.source>1.8</maven.compiler.source>
173+
<maven.compiler.target>1.8</maven.compiler.target>
174+
<exec.mainClass>pkg.Main</exec.mainClass>
175+
</properties>
176+
<build>
177+
<plugins>
178+
<plugin>
179+
<groupId>org.apache.maven.plugins</groupId>
180+
<artifactId>maven-surefire-plugin</artifactId>
181+
<version>2.22.0</version>
182+
</plugin>
183+
</plugins>
184+
</build>
185+
<dependencies>
186+
<dependency>
187+
<groupId>org.junit.jupiter</groupId>
188+
<artifactId>junit-jupiter-api</artifactId>
189+
<version>5.3.1</version>
190+
<scope>test</scope>
191+
</dependency>
192+
<dependency>
193+
<groupId>org.junit.jupiter</groupId>
194+
<artifactId>junit-jupiter-params</artifactId>
195+
<version>5.3.1</version>
196+
<scope>test</scope>
197+
</dependency>
198+
<dependency>
199+
<groupId>org.junit.jupiter</groupId>
200+
<artifactId>junit-jupiter-engine</artifactId>
201+
<version>5.3.1</version>
202+
<scope>test</scope>
203+
</dependency>
204+
</dependencies>
205+
</project>
206+
`;
207+
208+
166209
export const SAMPLE_BUILD_GRADLE =
167210
`
168211
plugins {

vscode/src/test/suite/general/extension.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import * as myExtension from '../../../extension';
3030
import * as myExplorer from '../../../explorer';
3131
import { CodeAction, commands, extensions, Selection, Uri, window, workspace, TreeItem } from 'vscode';
3232
import { assertWorkspace, dumpJava, getFilePaths, openFile, prepareProject, replaceCode } from '../../testutils';
33-
import { SAMPLE_CODE_FORMAT_DOCUMENT, SAMPLE_CODE_SORT_IMPORTS, SAMPLE_CODE_UNUSED_IMPORTS } from '../../constants';
33+
import { FORMATTED_POM_XML, SAMPLE_CODE_FORMAT_DOCUMENT, SAMPLE_CODE_SORT_IMPORTS, SAMPLE_CODE_UNUSED_IMPORTS } from '../../constants';
3434

3535
suite('Extension Test Suite', function () {
3636
window.showInformationMessage('Start all tests.');
@@ -298,4 +298,13 @@ suite('Extension Test Suite', function () {
298298
assert.ok(!fs.existsSync(mainClass), "Class created by compilation: " + mainClass);
299299
}).timeout(10000);
300300

301+
// Check if xml document formatting is executed successfully
302+
test("XML Format document", async () => {
303+
const editor = await openFile(filePaths.pom);
304+
await commands.executeCommand('editor.action.formatDocument');
305+
306+
const formattedContents = editor.document.getText().trim();
307+
assert.ok(formattedContents == FORMATTED_POM_XML.trim(), "pom.xml is not formatted");
308+
}).timeout(10000);
309+
301310
});

0 commit comments

Comments
 (0)