|
1 | 1 | package org.scm4j.releaser.cli; |
2 | 2 |
|
| 3 | +import static org.fusesource.jansi.Ansi.ansi; |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | +import static org.junit.Assert.assertTrue; |
| 6 | +import static org.mockito.Matchers.any; |
| 7 | +import static org.mockito.Matchers.eq; |
| 8 | +import static org.mockito.Mockito.doReturn; |
| 9 | +import static org.mockito.Mockito.doThrow; |
| 10 | +import static org.mockito.Mockito.mock; |
| 11 | +import static org.mockito.Mockito.never; |
| 12 | +import static org.mockito.Mockito.spy; |
| 13 | +import static org.mockito.Mockito.verify; |
| 14 | +import static org.scm4j.releaser.testutils.VerificationModeSometime.sometime; |
| 15 | + |
| 16 | +import java.io.File; |
| 17 | +import java.io.PrintStream; |
| 18 | +import java.net.URL; |
| 19 | +import java.nio.charset.StandardCharsets; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.List; |
| 22 | + |
3 | 23 | import org.apache.commons.io.FileUtils; |
4 | 24 | import org.apache.commons.io.filefilter.FileFilterUtils; |
5 | 25 | import org.fusesource.jansi.Ansi; |
|
12 | 32 | import org.mockito.Matchers; |
13 | 33 | import org.scm4j.commons.progress.IProgress; |
14 | 34 | import org.scm4j.commons.regexconfig.EConfig; |
15 | | -import org.scm4j.releaser.*; |
| 35 | +import org.scm4j.releaser.ActionTreeBuilder; |
| 36 | +import org.scm4j.releaser.CachedStatuses; |
| 37 | +import org.scm4j.releaser.Constants; |
| 38 | +import org.scm4j.releaser.ExtendedStatus; |
| 39 | +import org.scm4j.releaser.ExtendedStatusBuilder; |
| 40 | +import org.scm4j.releaser.Utils; |
16 | 41 | import org.scm4j.releaser.actions.IAction; |
17 | 42 | import org.scm4j.releaser.conf.Component; |
18 | 43 | import org.scm4j.releaser.conf.DefaultConfigUrls; |
19 | 44 | import org.scm4j.releaser.conf.IConfigUrls; |
20 | 45 | import org.scm4j.releaser.conf.VCSRepositoryFactory; |
| 46 | +import org.scm4j.releaser.exceptions.EBuildStatus; |
21 | 47 | import org.scm4j.releaser.exceptions.EReleaserException; |
22 | 48 | import org.scm4j.releaser.exceptions.cmdline.ECmdLineNoCommand; |
23 | 49 | import org.scm4j.releaser.exceptions.cmdline.ECmdLineNoProduct; |
24 | 50 | import org.scm4j.releaser.exceptions.cmdline.ECmdLineUnknownCommand; |
25 | 51 | import org.scm4j.releaser.exceptions.cmdline.ECmdLineUnknownOption; |
26 | 52 | import org.scm4j.releaser.testutils.TestEnvironment; |
27 | 53 |
|
28 | | -import java.io.File; |
29 | | -import java.io.PrintStream; |
30 | | -import java.net.URL; |
31 | | -import java.nio.charset.StandardCharsets; |
32 | | -import java.util.ArrayList; |
33 | | -import java.util.List; |
34 | | - |
35 | | -import static org.fusesource.jansi.Ansi.ansi; |
36 | | -import static org.junit.Assert.*; |
37 | | -import static org.mockito.Matchers.any; |
38 | | -import static org.mockito.Matchers.eq; |
39 | | -import static org.mockito.Mockito.*; |
40 | | -import static org.scm4j.releaser.testutils.VerificationModeSometime.sometime; |
41 | | - |
42 | 54 | public class CLITest { |
43 | 55 |
|
44 | 56 | private static final String TEST_CONFIG_CONTENT = "# test config content"; |
45 | 57 | private static final String TEST_EXCEPTION_MESSAGE = "test exception"; |
46 | 58 | private static final String UNTILL = "eu.untill:unTill"; |
| 59 | + private static final String UNTILLDB = "eu.untill:unTillDb"; |
47 | 60 | private IAction mockedAction; |
48 | 61 | private PrintStream mockedPS; |
49 | 62 | private CLI mockedCLI; |
@@ -298,6 +311,23 @@ public void testInitWorkingDir() throws Exception { |
298 | 311 | assertEquals(srcFileNames.size(), dstFileNames.size()); |
299 | 312 | assertEquals(TEST_CONFIG_CONTENT, FileUtils.readFileToString(customConfigTemplateFile, StandardCharsets.UTF_8)); |
300 | 313 | } |
| 314 | + |
| 315 | + @Test |
| 316 | + public void testBriefCompInfoOnBuildStatusFailure() throws Exception { |
| 317 | + String[] args = new String[] { CLICommand.STATUS.getCmdLineStr(), UNTILLDB }; |
| 318 | + RuntimeException testException = new RuntimeException("test exception"); |
| 319 | + try (TestEnvironment env = new TestEnvironment()) { |
| 320 | + env.generateTestEnvironment(); |
| 321 | + Component compUnTillDb = new Component(UNTILLDB); |
| 322 | + doThrow(testException).when(mockedRepoFactory).getVCSRepository(compUnTillDb); |
| 323 | + mockedCLI = spy(new CLI(mockedPS, new ExtendedStatusBuilder(mockedRepoFactory), mockedActionTreeBuilder, mockedRepoFactory)); |
| 324 | + |
| 325 | + assertEquals(CLI.EXIT_CODE_ERROR, mockedCLI.exec(args)); |
| 326 | + assertTrue(mockedCLI.getLastException() instanceof EBuildStatus); |
| 327 | + assertEquals(compUnTillDb, ((EBuildStatus) mockedCLI.getLastException()).getComp()); |
| 328 | + verify(mockedPS, sometime()).println(Matchers.contains(((EBuildStatus) mockedCLI.getLastException()).getMessage())); |
| 329 | + } |
| 330 | + } |
301 | 331 |
|
302 | 332 | private File getResourceFile(Class<?> forClass) throws Exception { |
303 | 333 | URL url = forClass.getResource(CLI.CONFIG_TEMPLATES_ROSURCE_PATH); |
|
0 commit comments