/** * @param port port to use * @param tempDirectory directory to use */ public RestartableTestingServer(int port, File tempDirectory) throws Exception { super(new InstanceSpec(tempDirectory, port, -1, -1, true, -1), true); mTestingZooKeeperServer = Whitebox.getInternalState(this, "testingZooKeeperServer"); }
@Override public void destroy() { //hack to get setModuleClassloader tested classLoader = Whitebox.getInternalState(this, "classLoader"); }
@Test public void testSetupChildListener() throws Exception { final Checker checker = new Checker(); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<>(), Thread.currentThread().getContextClassLoader()); checker.setModuleFactory(factory); final Configuration config = new DefaultConfiguration( DebugAuditAdapter.class.getCanonicalName()); checker.setupChild(config); final List<AuditListener> listeners = Whitebox.getInternalState(checker, "listeners"); assertTrue("Invalid child listener class", listeners.get(listeners.size() - 1) instanceof DebugAuditAdapter); }
@Test public void testParserConfiguredSuccessfully() throws Exception { final DummyLoader dummyLoader = new DummyLoader(new HashMap<>(1)); final XMLReader parser = Whitebox.getInternalState(dummyLoader, "parser"); assertEquals("Invalid entity resolver", dummyLoader, parser.getEntityResolver()); }
@Test public void testBehaviourWithZeroChecks() throws Exception { final TreeWalker treeWalker = new TreeWalker(); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<>(), Thread.currentThread().getContextClassLoader()); treeWalker.setModuleFactory(factory); // create file that should throw exception final File file = temporaryFolder.newFile("file.java"); final FileText fileText = new FileText(file, new ArrayList<>()); treeWalker.processFiltered(file, fileText); final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks"); assertTrue("No checks -> No parsing", checks.isEmpty()); }
/** * Test of setHeader method, of class RegexpHeaderCheck. */ @Test public void testSetHeaderSimple() { final RegexpHeaderCheck instance = new RegexpHeaderCheck(); // check valid header passes final String header = "abc.*"; instance.setHeader(header); final List<Pattern> headerRegexps = Whitebox.getInternalState(instance, "headerRegexps"); assertEquals("Expected one pattern", 1, headerRegexps.size()); assertEquals("Invalid header regexp", header, headerRegexps.get(0).pattern()); }
/** * Test of setHeader method, of class RegexpHeaderCheck. */ @Test public void testSetHeaderEmpty() { // check null passes final RegexpHeaderCheck instance = new RegexpHeaderCheck(); // check empty string passes final String header = ""; instance.setHeader(header); final List<Pattern> headerRegexps = Whitebox.getInternalState(instance, "headerRegexps"); assertTrue("When header is empty regexps should not be set", headerRegexps.isEmpty()); }
/** * Test of setHeader method, of class RegexpHeaderCheck. */ @Test public void testSetHeaderNull() { // check null passes final RegexpHeaderCheck instance = new RegexpHeaderCheck(); // recreate for each test because multiple invocations fail final String header = null; instance.setHeader(header); final List<Pattern> headerRegexps = Whitebox.getInternalState(instance, "headerRegexps"); assertTrue("When header is null regexps should not be set", headerRegexps.isEmpty()); }
@Test public void testSettingModuleId() throws Exception { final FilterSet fc = SuppressionsLoader.loadSuppressions(getPath("InputSuppressionsLoaderWithId.xml")); final SuppressElement suppressElement = (SuppressElement) fc.getFilters().toArray()[0]; final String id = Whitebox.getInternalState(suppressElement, "moduleId"); assertEquals("Id has to be defined", "someId", id); }
@Test public void testCleatBundleCache() { Locale.setDefault(Locale.FRENCH); LocalizedMessage.setLocale(Locale.ROOT); final LocalizedMessage localizedMessage = createSampleLocalizedMessage(); assertEquals("Invalid message", "Empty statement.", localizedMessage.getMessage()); final Map<String, ResourceBundle> bundleCache = Whitebox.getInternalState(LocalizedMessage.class, "BUNDLE_CACHE"); assertEquals("Invalid bundle cache size", 1, bundleCache.size()); LocalizedMessage.setLocale(Locale.CHINA); assertEquals("Invalid bundle cache size", 0, bundleCache.size()); }
@Test public void testSettersForParameters() throws Exception { final TreeWalker treeWalker = new TreeWalker(); final DefaultConfiguration config = new DefaultConfiguration("default config"); treeWalker.setTabWidth(1); treeWalker.configure(config); treeWalker.setCacheFile(temporaryFolder.newFile().getPath()); assertEquals("Invalid setter result", 1, (int) Whitebox.getInternalState(treeWalker, "tabWidth")); assertEquals("Invalid configuration", config, Whitebox.getInternalState(treeWalker, "configuration")); }
@Test public void testStyleProp() { Component component = Text.create(mContext, 0, TextSizeStyle) .text("text") .build(); assertThat((int) getInternalState(component, "textSize")) .isEqualTo(mDimen); }
@Test public void setFileExtension() { final Checker checker = new Checker(); checker.setFileExtensions(".test1", "test2"); final String[] actual = Whitebox.getInternalState(checker, "fileExtensions"); assertArrayEquals("Extensions are not expected", new String[] {".test1", ".test2"}, actual); }
@Test public void testClearCacheWhenCacheFileIsNotSet() { // The idea of the test is to check that when cache file is not set, // the invocation of clearCache method does not throw an exception. final Checker checker = new Checker(); checker.clearCache(); assertNull("If cache file is not set the cache should default to null", Whitebox.getInternalState(checker, "cacheFile")); }
@Test public void testProcessNonJavaFilesWithoutException() throws Exception { final TreeWalker treeWalker = new TreeWalker(); treeWalker.setTabWidth(1); treeWalker.configure(new DefaultConfiguration("default config")); final File file = new File(getPath("InputTreeWalkerNotJava.xml")); final FileText fileText = new FileText(file, StandardCharsets.ISO_8859_1.name()); treeWalker.processFiltered(file, fileText); final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks"); assertTrue("No checks -> No parsing", checks.isEmpty()); }
@Test public void testCreate() { ComponentTree componentTree = ComponentTree.create(mContext, mComponent) .build(); creationCommonChecks(componentTree); // Both the main thread and the background layout state shouldn't be calculated yet. Assert.assertNull(Whitebox.getInternalState(componentTree, "mMainThreadLayoutState")); Assert.assertNull(Whitebox.getInternalState(componentTree, "mBackgroundLayoutState")); Assert.assertFalse(componentTreeHasSizeSpec(componentTree)); }
private void addAbsent(AlluxioURI path) throws Exception { final ThreadPoolExecutor pool = Whitebox.getInternalState(mUfsAbsentPathCache, "mPool"); final long initialTasks = pool.getCompletedTaskCount(); mUfsAbsentPathCache.process(path, Collections.emptyList()); // Wait until the async task is completed. CommonUtils.waitFor("path (" + path + ") to be added to absent cache", () -> pool.getCompletedTaskCount() != initialTasks, WaitForOptions.defaults().setTimeoutMs(10000)); }
private void removeAbsent(AlluxioURI path) throws Exception { final ThreadPoolExecutor pool = Whitebox.getInternalState(mUfsAbsentPathCache, "mPool"); final long initialTasks = pool.getCompletedTaskCount(); mUfsAbsentPathCache.process(path, Collections.emptyList()); // Wait until the async task is completed. CommonUtils.waitFor("path (" + path + ") to be removed from absent cache", () -> pool.getCompletedTaskCount() != initialTasks, WaitForOptions.defaults().setTimeoutMs(10000)); }
@Test public void testNoModuleFactory() throws Exception { final Checker checker = new Checker(); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); checker.setModuleClassLoader(classLoader); checker.finishLocalSetup(); final Context actualCtx = Whitebox.getInternalState(checker, "childContext"); assertNotNull("Default module factory should be created when it is not specified", actualCtx.get("moduleFactory")); assertEquals("Invalid classLoader", classLoader, actualCtx.get("classLoader")); }
@Test public void testSetClasspathRef() { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setClasspathRef(new Reference(new Project(), "id")); assertNotNull("Classpath should not be null", Whitebox.getInternalState(antTask, "classpath")); }