|
22 | 22 | import java.util.stream.Collectors; |
23 | 23 | import java.util.stream.Stream; |
24 | 24 |
|
| 25 | +import org.apache.commons.io.FileUtils; |
| 26 | +import org.hamcrest.MatcherAssert; |
| 27 | +import org.hamcrest.core.StringContains; |
25 | 28 | import org.junit.Assert; |
26 | 29 | import org.junit.Before; |
27 | 30 | import org.junit.Rule; |
|
33 | 36 | import com.vaadin.flow.server.frontend.scanner.FrontendDependencies; |
34 | 37 |
|
35 | 38 | import elemental.json.Json; |
| 39 | +import elemental.json.JsonException; |
36 | 40 | import elemental.json.JsonObject; |
37 | 41 | import static com.vaadin.flow.server.Constants.COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT; |
38 | 42 | import static com.vaadin.flow.server.Constants.RESOURCES_FRONTEND_DEFAULT; |
| 43 | +import static java.nio.charset.StandardCharsets.UTF_8; |
39 | 44 |
|
40 | 45 | public class NodeUpdaterTest { |
41 | 46 |
|
@@ -188,6 +193,24 @@ public void updateDefaultDependencies_newerVersionsAreNotChanged() |
188 | 193 | .getObject(NodeUpdater.DEV_DEPENDENCIES).getString("webpack")); |
189 | 194 | } |
190 | 195 |
|
| 196 | + @Test |
| 197 | + public void getJsonFileContent_incorrectPackageJsonContent_throwsExceptionWithFileName() |
| 198 | + throws IOException { |
| 199 | + File brokenPackageJsonFile = temporaryFolder |
| 200 | + .newFile("broken-package.json"); |
| 201 | + FileUtils.writeStringToFile(brokenPackageJsonFile, |
| 202 | + "{ some broken json ", UTF_8); |
| 203 | + |
| 204 | + JsonException exception = Assert.assertThrows(JsonException.class, |
| 205 | + () -> NodeUpdater.getJsonFileContent(brokenPackageJsonFile)); |
| 206 | + |
| 207 | + MatcherAssert.assertThat(exception.getMessage(), |
| 208 | + StringContains.containsString( |
| 209 | + "Cannot parse package file ")); |
| 210 | + MatcherAssert.assertThat(exception.getMessage(), |
| 211 | + StringContains.containsString("broken-package.json")); |
| 212 | + } |
| 213 | + |
191 | 214 | private String getPolymerVersion(JsonObject object) { |
192 | 215 | JsonObject deps = object.get("dependencies"); |
193 | 216 | String version = deps.getString("@polymer/polymer"); |
|
0 commit comments