Java Code Examples for org.powermock.core.classloader.annotations.PrepareForTest

The following examples show how to use org.powermock.core.classloader.annotations.PrepareForTest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 2
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 3
@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);
}
 
Example 4
Source Project: vividus   Source File: ProxyServerFactoryTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source Project: vividus   Source File: ElementStepsTests.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 6
Source Project: vividus   Source File: BddStepPrinterTests.java    License: Apache License 2.0 6 votes vote down vote up
@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)));
}
 
Example 7
Source Project: vividus   Source File: MongoDbStepsTests.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 8
Source Project: hop   Source File: StartExecutionPipelineServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 9
Source Project: hop   Source File: RemovePipelineServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 10
Source Project: hop   Source File: StopWorkflowServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 11
Source Project: hop   Source File: RemoveWorkflowServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 12
Source Project: hop   Source File: StartPipelineServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 13
Source Project: hop   Source File: PausePipelineServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 14
Source Project: hop   Source File: GetWorkflowStatusServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );

}
 
Example 15
Source Project: hop   Source File: GetPipelineStatusServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 16
Source Project: hop   Source File: StartWorkflowServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 17
Source Project: hop   Source File: SniffTransformServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 18
Source Project: hop   Source File: PrepareExecutionPipelineServletTest.java    License: Apache License 2.0 6 votes vote down vote up
@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() );
}
 
Example 19
Source Project: hop   Source File: TransformWithMappingMetaTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 ) );
}
 
Example 20
Source Project: hop   Source File: TransformWithMappingMetaTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 ) );
}
 
Example 21
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 22
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@PrepareForTest(LocalFileSystem.class)
@Test
public void testVirtualFileFromURINull() {
  PowerMockito.mockStatic(LocalFileSystem.class);
  PowerMockito.when(LocalFileSystem.getInstance()).thenThrow(URISyntaxException.class);

  Assert.assertNull(FileUtils.virtualFileFromURI("foobar"));
}
 
Example 23
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 24
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 25
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@PrepareForTest(LocalFileSystem.class)
@Test
public void testURIToVFSNull() {
  PowerMockito.mockStatic(LocalFileSystem.class);
  PowerMockito.when(LocalFileSystem.getInstance()).thenThrow(URISyntaxException.class);
  Assert.assertNull(FileUtils.URIToVFS("foobar"));
}
 
Example 26
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 27
Source Project: lsp4intellij   Source File: FileUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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)));
}
 
Example 28
Source Project: vividus   Source File: AllureReportGeneratorTests.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 29
Source Project: vividus   Source File: AllureReportGeneratorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@PrepareForTest(AllureReportGenerator.class)
public void testEndNotStarted() throws Exception
{
    AllureReportGenerator spy = PowerMockito.spy(allureReportGenerator);
    spy.end();
    PowerMockito.verifyPrivate(spy, never()).invoke("generateReport");
}
 
Example 30
Source Project: vividus   Source File: AllureReportGeneratorTests.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}