How to use PluginFileReader class of org.mockito.internal.configuration.plugins package

Best Mockito code snippet using org.mockito.internal.configuration.plugins.PluginFileReader

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.test.configuration.plugins;
6
7import org.junit.Test;
8import org.mockito.internal.configuration.plugins.PluginFileReader;
9import org.mockito.test.mockitoutil.TestBase;
10
11import java.io.ByteArrayInputStream;
12import java.io.IOException;
13import java.io.InputStream;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNull;
17
18public class PluginFileReaderTest extends TestBase {
19
20    PluginFileReader reader = new PluginFileReader();
21
22    @Test
23    public void no_class_in_resource() throws IOException {
24        //no class
25        assertNull(reader.readPluginClass(impl("")));
26        assertNull(reader.readPluginClass(impl("  ")));
27        assertNull(reader.readPluginClass(impl(" \n ")));
28
29        //commented out
30        assertNull(reader.readPluginClass(impl("#foo")));
31        assertNull(reader.readPluginClass(impl("  # foo  ")));
32        assertNull(reader.readPluginClass(impl("  # # # java.langString # ")));
33        assertNull(reader.readPluginClass(impl("  \n # foo \n # foo \n ")));
34    }
35
36    private InputStream impl(String s) {
37        return new ByteArrayInputStream(s.getBytes());
38    }
39
40    @Test
41    public void reads_class_name() throws IOException {
42        assertEquals("java.lang.String", reader.readPluginClass(impl("java.lang.String")));
43        assertEquals("x", reader.readPluginClass(impl("x")));
44        assertEquals("x y z", reader.readPluginClass(impl(" x y z ")));
45        assertEquals("foo.Foo", reader.readPluginClass(impl(" #my class\n  foo.Foo \n #other class ")));
46        assertEquals("foo.Foo", reader.readPluginClass(impl("foo.Foo  # cool class")));
47    }
48}
49
Full Screen
copy
1/*
2 * Copyright (c) 2016 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.configuration.plugins;
6
7import java.io.InputStream;
8import java.net.URL;
9import java.util.ArrayList;
10import java.util.List;
11
12import org.mockito.exceptions.base.MockitoException;
13import org.mockito.internal.util.io.IOUtil;
14import org.mockito.plugins.PluginSwitch;
15
16class PluginFinder {
17
18    private final PluginSwitch pluginSwitch;
19
20    public PluginFinder(PluginSwitch pluginSwitch) {
21        this.pluginSwitch = pluginSwitch;
22    }
23
24    String findPluginClass(Iterable<URL> resources) {
25        for (URL resource : resources) {
26            InputStream s = null;
27            try {
28                s = resource.openStream();
29                String pluginClassName = new PluginFileReader().readPluginClass(s);
30                if (pluginClassName == null) {
31                    // For backwards compatibility
32                    // If the resource does not have plugin class name we're ignoring it
33                    continue;
34                }
35                if (!pluginSwitch.isEnabled(pluginClassName)) {
36                    continue;
37                }
38                return pluginClassName;
39            } catch (Exception e) {
40                throw new MockitoException(
41                        "Problems reading plugin implementation from: " + resource, e);
42            } finally {
43                IOUtil.closeQuietly(s);
44            }
45        }
46        return null;
47    }
48
49    List<String> findPluginClasses(Iterable<URL> resources) {
50        List<String> pluginClassNames = new ArrayList<>();
51        for (URL resource : resources) {
52            InputStream s = null;
53            try {
54                s = resource.openStream();
55                String pluginClassName = new PluginFileReader().readPluginClass(s);
56                if (pluginClassName == null) {
57                    // For backwards compatibility
58                    // If the resource does not have plugin class name we're ignoring it
59                    continue;
60                }
61                if (!pluginSwitch.isEnabled(pluginClassName)) {
62                    continue;
63                }
64                pluginClassNames.add(pluginClassName);
65            } catch (Exception e) {
66                throw new MockitoException(
67                        "Problems reading plugin implementation from: " + resource, e);
68            } finally {
69                IOUtil.closeQuietly(s);
70            }
71        }
72        return pluginClassNames;
73    }
74}
75
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on PluginFileReader

    No relevant questions found for this class 😞

Most used methods in PluginFileReader

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)