下面列出了java.util.EmptyStackException#org.powermock.core.classloader.annotations.PrepareForTest 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@PrepareForTest(FileEditorManager.class)
@Test
public void testEditorFromVirtualFile() {
VirtualFile file = PowerMockito.mock(VirtualFile.class);
Project project = PowerMockito.mock(Project.class);
Editor editor = PowerMockito.mock(Editor.class);
TextEditor textEditor = PowerMockito.mock(TextEditor.class);
PowerMockito.when(textEditor.getEditor()).thenReturn(editor);
FileEditorManagerEx fileEditorManagerEx = PowerMockito.mock(FileEditorManagerEx.class);
PowerMockito.mockStatic(FileEditorManager.class);
PowerMockito.when(fileEditorManagerEx.getAllEditors(file))
.thenReturn(new FileEditor[]{textEditor})
.thenReturn(new FileEditor[0]);
PowerMockito.when(FileEditorManager.getInstance(project)).thenReturn(fileEditorManagerEx);
Assert.assertEquals(editor, FileUtils.editorFromVirtualFile(file, project));
Assert.assertNull(FileUtils.editorFromVirtualFile(file, project));
}
@PrepareForTest(FileUtils.class)
@Test
public void testEditorToProjectFolderPath() throws Exception {
Assert.assertNull(FileUtils.editorToProjectFolderPath(null));
PowerMockito.spy(FileUtils.class);
Editor editor = PowerMockito.mock(Editor.class);
PowerMockito.when(editor.getProject()).thenReturn(PowerMockito.mock(Project.class));
PowerMockito.when(editor.getProject().getBasePath()).thenReturn("test");
File file = PowerMockito.mock(File.class);
PowerMockito.when(file.getAbsolutePath()).thenReturn("fooBar");
PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file);
Assert.assertEquals("fooBar", FileUtils.editorToProjectFolderPath(editor));
}
@Test
@PrepareForTest({HttpClients.class, HttpClientContext.class, HttpHost.class})
public void bundledPluginsTest() {
URL warURL = this.getClass().getResource("/bundledplugintest.war");
File testWar = new File(warURL.getFile());
Config config = Config.builder()
.withJenkinsWar(testWar.toString())
.build();
PluginManager pluginManager = new PluginManager(config);
Map <String, Plugin> expectedPlugins = new HashMap<>();
expectedPlugins.put("credentials", new Plugin("credentials","2.1.18", null, null));
expectedPlugins.put("display-url-api", new Plugin("display-url-api","2.0", null, null));
expectedPlugins.put("github-branch-source", new Plugin("github-branch-source", "1.8", null, null));
Map<String, Plugin> actualPlugins = pluginManager.bundledPlugins();
List<String> actualPluginInfo = convertPluginsToStrings(new ArrayList(actualPlugins.values()));
List<String> expectedPluginInfo = convertPluginsToStrings(new ArrayList<>(expectedPlugins.values()));
assertEquals(expectedPluginInfo, actualPluginInfo);
}
@Test
@PrepareForTest({BrowserUpProxyServer.class, ThreadPoolConfiguration.class, ProxyServerFactory.class})
public void testCreateProxyServerConfigDisableMitm() throws Exception
{
MitmManagerOptions mitmManagerOptions = mock(MitmManagerOptions.class);
IMitmManagerFactory mitmManagerFactory = mock(IMitmManagerFactory.class);
MitmManager mitmManager = mock(MitmManager.class);
when(mitmManagerFactory.createMitmManager(mitmManagerOptions)).thenReturn(mitmManager);
BrowserUpProxyServer mockedServer = mock(BrowserUpProxyServer.class);
PowerMockito.whenNew(BrowserUpProxyServer.class).withNoArguments().thenReturn(mockedServer);
proxyServerFactory.setMitmManagerOptions(mitmManagerOptions);
proxyServerFactory.setMitmManagerFactory(mitmManagerFactory);
proxyServerFactory.setMitmEnabled(true);
proxyServerFactory.createProxyServer();
verify(mockedServer).setMitmManager(mitmManager);
}
@Test
@PrepareForTest({ ElementSteps.class, FileUtils.class })
public void testLoadFileFromJar() throws Exception
{
File file = mockFileForUpload();
PowerMockito.mockStatic(FileUtils.class);
PowerMockito.whenNew(File.class).withArguments(FILE_PATH).thenReturn(file);
Resource resource = mockResource("jar:file:/D:/archive.jar!/file.txt", file, true);
InputStream inputStream = new ByteArrayInputStream(TEXT.getBytes(StandardCharsets.UTF_8));
when(resource.getInputStream()).thenReturn(inputStream);
mockResourceLoader(resource);
when(softAssert.assertTrue(FILE_FILE_PATH_EXISTS, true)).thenReturn(true);
SearchAttributes searchAttributes = new SearchAttributes(ActionAttributeType.XPATH,
new SearchParameters(XPATH).setVisibility(Visibility.ALL));
when(baseValidations.assertIfElementExists(AN_ELEMENT, searchAttributes)).thenReturn(webElement);
elementSteps.uploadFile(searchAttributes, FILE_PATH);
verify(webElement).sendKeys(ABSOLUTE_PATH);
PowerMockito.verifyStatic(FileUtils.class);
FileUtils.copyInputStreamToFile(eq(resource.getInputStream()), any(File.class));
}
@Test
@PrepareForTest({ Vividus.class, BeanFactory.class, FileUtils.class })
public void testPrintToFile() throws Exception
{
List<String> expectedOutput = mockStepCandidates();
String filePath = "mocked" + File.separator + "file";
mockStatic(FileUtils.class);
BddStepPrinter.main(new String[] {"-f", filePath});
Path file = Paths.get(filePath);
assertOutput(List.of("File with BDD steps: " + file.toAbsolutePath()));
PowerMockito.verifyStatic(FileUtils.class);
FileUtils.writeLines(argThat(f -> filePath.equals(f.toString())), argThat(steps -> steps.stream()
.map(Object::toString)
.collect(Collectors.toList())
.equals(expectedOutput)));
}
@SuppressWarnings("unchecked")
@PrepareForTest(MongoClients.class)
@Test
public void testExecuteCommands()
{
MongoDatabase database = mockDatabase();
MongoCollection<Document> collection = mock(MongoCollection.class);
when(database.getCollection(COLLECTION_KEY)).thenReturn(collection);
Bson argument = mock(Bson.class);
FindIterable<Document> findIterable = mock(FindIterable.class);
when(collection.find(argument)).thenReturn(findIterable);
when(findIterable.spliterator()).thenReturn(List.of(DOCUMENT).spliterator());
MongoDbSteps steps = new MongoDbSteps(Map.of(LOCAL_KEY, CONNECTION_KEY), jsonUtils, context);
steps.executeCommands(List.of(
commandEntry(MongoCommand.FIND, argument),
commandEntry(MongoCommand.COLLECT, argument)
), COLLECTION_KEY, LOCAL_KEY, LOCAL_KEY, Set.of(VariableScope.STORY), VARIABLE_KEY);
verify(context).putVariable(Set.of(VariableScope.STORY), VARIABLE_KEY, String.format("[%s]", DOCUMENT_JSON));
}
@Test
@PrepareForTest( { Encode.class } )
public void testStartExecutionPipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartExecutionPipelineServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
startExecutionPipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testRemovePipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( RemovePipelineServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
removePipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testStopJobServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StopWorkflowServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
stopWorkflowServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testRemoveWorkflowServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveWorkflowServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
removeWorkflowServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testStartPipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartPipelineServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
startPipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testPausePipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( PausePipelineServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
pausePipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testGetJobStatusServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( GetWorkflowStatusServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
getWorkflowStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testGetPipelineStatusServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( GetPipelineStatusServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
getPipelineStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testStartWorkflowServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( StartWorkflowServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
startJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testSniffTransformServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( SniffTransformServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
sniffTransformServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( { Encode.class } )
public void testPausePipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter( out );
PowerMockito.spy( Encode.class );
when( mockHttpServletRequest.getContextPath() ).thenReturn( PrepareExecutionPipelineServlet.CONTEXT_PATH );
when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );
prepareExecutionPipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );
PowerMockito.verifyStatic( atLeastOnce() );
Encode.forHtml( anyString() );
}
@Test
@PrepareForTest( TransformWithMappingMeta.class )
public void activateParamsTest() throws Exception {
String childParam = "childParam";
String childValue = "childValue";
String paramOverwrite = "paramOverwrite";
String parentValue = "parentValue";
String transformValue = "transformValue";
IVariables parent = new Variables();
parent.setVariable( paramOverwrite, parentValue );
PipelineMeta childVariableSpace = new PipelineMeta();
childVariableSpace.addParameterDefinition( childParam, "", "" );
childVariableSpace.setParameterValue( childParam, childValue );
String[] parameters = childVariableSpace.listParameters();
TransformWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parent,
parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, transformValue }, true );
Assert.assertEquals( childValue, childVariableSpace.getVariable( childParam ) );
// the transform parameter prevails
Assert.assertEquals( transformValue, childVariableSpace.getVariable( paramOverwrite ) );
}
@Test
@PrepareForTest( TransformWithMappingMeta.class )
public void activateParamsTestWithNoParameterChild() throws Exception {
String newParam = "newParamParent";
String parentValue = "parentValue";
PipelineMeta parentMeta = new PipelineMeta();
PipelineMeta childVariableSpace = new PipelineMeta();
String[] parameters = childVariableSpace.listParameters();
TransformWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parentMeta,
parameters, new String[] { newParam }, new String[] { parentValue }, true );
Assert.assertEquals( parentValue, childVariableSpace.getParameterValue( newParam ) );
}
@PrepareForTest(LocalFileSystem.class)
@Test
public void testVirtualFileFromURI() {
LocalFileSystem localFileSystem = PowerMockito.mock(LocalFileSystem.class);
PowerMockito.mockStatic(LocalFileSystem.class);
PowerMockito.when(LocalFileSystem.getInstance()).thenReturn(localFileSystem);
PowerMockito.when(LocalFileSystem.getInstance().findFileByIoFile(Mockito.any()))
.thenReturn(new BinaryLightVirtualFile("testFile"));
Assert.assertEquals(new BinaryLightVirtualFile("testFile").toString(),
FileUtils.virtualFileFromURI("file://foobar").toString());
}
@PrepareForTest(LocalFileSystem.class)
@Test
public void testVirtualFileFromURINull() {
PowerMockito.mockStatic(LocalFileSystem.class);
PowerMockito.when(LocalFileSystem.getInstance()).thenThrow(URISyntaxException.class);
Assert.assertNull(FileUtils.virtualFileFromURI("foobar"));
}
@PrepareForTest(FileUtils.class)
@Test
public void testSanitizeURIWindows() {
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.getProperty(Mockito.anyString())).thenReturn("Windows");
Assert.assertEquals("file:///Foo:/Bar", FileUtils.sanitizeURI("file:foo%3A/Bar"));
}
@PrepareForTest(LocalFileSystem.class)
@Test
public void testURIToVFS() {
LocalFileSystem localFileSystem = PowerMockito.mock(LocalFileSystem.class);
PowerMockito.mockStatic(LocalFileSystem.class);
PowerMockito.when(LocalFileSystem.getInstance()).thenReturn(localFileSystem);
PowerMockito.when(LocalFileSystem.getInstance().findFileByIoFile(Mockito.any()))
.thenReturn(new BinaryLightVirtualFile("testFile"));
Assert.assertEquals(new BinaryLightVirtualFile("testFile").toString(),
FileUtils.URIToVFS("file://foobar").toString());
}
@PrepareForTest(LocalFileSystem.class)
@Test
public void testURIToVFSNull() {
PowerMockito.mockStatic(LocalFileSystem.class);
PowerMockito.when(LocalFileSystem.getInstance()).thenThrow(URISyntaxException.class);
Assert.assertNull(FileUtils.URIToVFS("foobar"));
}
@PrepareForTest(FileUtils.class)
@Test
public void testProjectToUri() {
Assert.assertNull(FileUtils.projectToUri(null));
PowerMockito.spy(FileUtils.class);
Project project = PowerMockito.mock(Project.class);
PowerMockito.when(project.getBasePath()).thenReturn("test");
PowerMockito.when(FileUtils.pathToUri(Mockito.anyString())).thenReturn("fooBar");
Assert.assertEquals("fooBar", FileUtils.projectToUri(project));
}
@PrepareForTest(FileDocumentManager.class)
@Test
public void testIsEditorSupported() {
VirtualFile virtualFile1 = PowerMockito.mock(VirtualFile.class);
PowerMockito.when(virtualFile1.getUrl()).thenReturn("jar:");
PowerMockito.mockStatic(FileDocumentManager.class);
FileDocumentManager fileDocumentManager = PowerMockito.mock(FileDocumentManager.class);
PowerMockito.when(fileDocumentManager.getFile(Mockito.mock(Document.class)))
.thenReturn(virtualFile1);
PowerMockito.when(FileDocumentManager.getInstance()).thenReturn(fileDocumentManager);
Assert.assertFalse(FileUtils.isEditorSupported(Mockito.mock(Editor.class)));
}
@Test
@PrepareForTest(FileUtils.class)
public void testStartException() throws IOException
{
File reportDirectory = Mockito.mock(File.class);
allureReportGenerator.setReportDirectory(reportDirectory);
when(reportDirectory.exists()).thenReturn(true);
IOException ioException = Mockito.mock(IOException.class);
PowerMockito.mockStatic(FileUtils.class);
PowerMockito.doThrow(ioException).when(FileUtils.class);
FileUtils.cleanDirectory(reportDirectory);
Exception thrown = assertThrows(IllegalStateException.class, () -> allureReportGenerator.start());
assertEquals(ioException, thrown.getCause());
}
@Test
@PrepareForTest(AllureReportGenerator.class)
public void testEndNotStarted() throws Exception
{
AllureReportGenerator spy = PowerMockito.spy(allureReportGenerator);
spy.end();
PowerMockito.verifyPrivate(spy, never()).invoke("generateReport");
}
@Test
@PrepareForTest({ReportGenerator.class, AllureReportGenerator.class, FileUtils.class})
public void testEndWhenResultsDirectoryDoesNotExist() throws Exception
{
resultsDirectory = new File(testFolder.getRoot(), "allure-results-to-be-created");
System.setProperty(ALLURE_RESULTS_DIRECTORY_PROPERTY, resultsDirectory.getAbsolutePath());
allureReportGenerator = new AllureReportGenerator(propertyMapper, resourcePatternResolver);
testEnd();
}