/** * test passed * * @throws Exception is a rubbish */ @Test @TestOnly public void insert() throws Exception { // MySqlAdapter.getSharedInstance().insert( // "article", // "1,20170101,0,'Tech, Startalk','Tech','How to mo the older?','Tech you how to mo the older'," + // "'Mo is the best way to increase your knowledge.',10000,0,1000", // "2,20170101,0,'Tech, Startalk','Tech','How to mo the older?'," + // "'Tech you how to mo the older','Mo is the best way to increase your knowledge.',10000,0,10000" // ); // System.out.println("INSERT INTO `article` VALUES (" + // "1,20170101,0,'Tech, Startalk','Tech','How to mo the older?','Tech you how to mo the older'," + // "'Mo is the best way to increase your knowledge.',10000,0,1000" + // "),(" + // "2,20170101,0,'Tech, Startalk','Tech','How to mo the older?'," + // "'Tech you how to mo the older','Mo is the best way to increase your knowledge.',10000,0,10000);" // ); }
/** * test passed * * @throws Exception is a rubbish */ @Test @TestOnly public void update() throws Exception { MySqlAdapter.getInstance().update( "article", new Pair[]{new Pair("click", "=23333")}, new Pair("Id", ">=1") ); /* * the above operation will generate query string as below * this is a simple example * but I think you can understand it */ String testStr = "UPDATE article SET click=23333 WHERE Id>=1"; }
/** @see #dispatchAllInvocationEvents() */ @TestOnly public static void pump() { assert !SwingUtilities.isEventDispatchThread(); final BlockingQueue<Object> queue = new LinkedBlockingQueue<Object>(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { queue.offer(queue); } }); try { queue.take(); } catch (InterruptedException e) { LOG.error(e); } }
@TestOnly public void testPrepare(PsiType returnType, boolean makeStatic) throws PrepareFailedException{ if (makeStatic) { if (!isCanBeStatic()) { throw new PrepareFailedException("Failed to make static", myElements[0]); } myInputVariables.setPassFields(true); myStatic = true; } if (PsiType.VOID.equals(myReturnType)) { myArtificialOutputVariable = getArtificialOutputVariable(); } testPrepare(); if (returnType != null) { myReturnType = returnType; } }
@TestOnly public void waitUntilRefreshed() { while (true) { final Semaphore semaphore = new Semaphore(); synchronized (myLock) { if (!myRequestSubmitted && !myRequestRunning) { return; } if (!myRequestRunning) { myExecutor.get().schedule(new MyRunnable(), 0, TimeUnit.MILLISECONDS); } semaphore.down(); myWaitingUpdateCompletionSemaphores.add(semaphore); } if (!semaphore.waitFor(100*1000)) { LOG.error("Too long VCS update"); return; } } }
@Test @TestOnly public void testToString() { Assert.assertEquals( "Van", new Tag("Van").getName() ); Random random = new Random(System.currentTimeMillis()); run(1000, () -> { String s = Integer.toString(random.nextInt()); assertEquals(s, new Tag(s).toString()); }); }
@Test @TestOnly public void test() throws IOException { Connection con = Jsoup.connect("http://strictfp.duapp.com/timeline") .data("start", "2017-01-01") .data("end", "2017-01-02").timeout(8000); Document doc = con.get(); System.out.println(doc.text()); }
@Test @TestOnly public void test() throws IOException { Connection con = Jsoup.connect("http://localhost:40000/api/v0/user").data("name", "\"Eldath\"").timeout(80000); Document doc = con.get(); System.out.println(doc.text()); }
@Test @TestOnly public void testJson() { JSONObject object = new JSONObject(); object.put("look", "quite"); object.put("age", 16); object.put("haveDick", true); object.put("boyNextDoor", new Pair("233", "666")); object.put("assWeCan", new JSONObject()); System.out.println(object.toString()); }
@Test @TestOnly public void delete() throws Exception { MySqlAdapter.getInstance().delete( "article", new Pair("Id", "=1") ); /* * the above code shows how to delete elements from * a table. * I think you guys can understand that. * LOL */ }
@TestOnly public int getPointersNumber(@NotNull PsiFile containingFile) { synchronized (lock) { VirtualFile file = containingFile.getViewProvider().getVirtualFile(); FilePointersList pointers = getPointers(file); return pointers == null ? 0 : pointers.size; } }
@TestOnly private void cleanPersistedContentsRecursively(int id) { if (isDirectory(getFileAttributes(id))) { for (int child : FSRecords.list(id)) { cleanPersistedContentsRecursively(child); } } else { setFlag(id, MUST_RELOAD_CONTENT, true); } }
@TestOnly public void setDumb(boolean dumb) { if (dumb) { myDumb = true; myPublisher.enteredDumbMode(); } else { updateFinished(); } }
@TestOnly public void checkConsistency() { HashMap<VirtualFile, FileViewProvider> fileToViewProvider = new HashMap<VirtualFile, FileViewProvider>(myVFileToViewProviderMap); myVFileToViewProviderMap.clear(); for (VirtualFile vFile : fileToViewProvider.keySet()) { final FileViewProvider fileViewProvider = fileToViewProvider.get(vFile); LOG.assertTrue(vFile.isValid()); PsiFile psiFile1 = findFile(vFile); if (psiFile1 != null && fileViewProvider != null && fileViewProvider.isPhysical()) { // might get collected PsiFile psi = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage()); assert psi != null : fileViewProvider +"; "+fileViewProvider.getBaseLanguage()+"; "+psiFile1; assert psiFile1.getClass().equals(psi.getClass()) : psiFile1 +"; "+psi + "; "+psiFile1.getClass() +"; "+psi.getClass(); } } HashMap<VirtualFile, PsiDirectory> fileToPsiDirMap = new HashMap<VirtualFile, PsiDirectory>(myVFileToPsiDirMap); myVFileToPsiDirMap.clear(); for (VirtualFile vFile : fileToPsiDirMap.keySet()) { LOG.assertTrue(vFile.isValid()); PsiDirectory psiDir1 = findDirectory(vFile); LOG.assertTrue(psiDir1 != null); VirtualFile parent = vFile.getParent(); if (parent != null) { LOG.assertTrue(myVFileToPsiDirMap.containsKey(parent)); } } }
@TestOnly public synchronized void printInfo() { doIndexTask(new IndexTask<Set<String>>() { public Set<String> doTask() throws Exception { System.out.println("BaseFile: " + myData.groupToArtifactMap.getBaseFile()); System.out.println("All data objects: " + myData.groupToArtifactMap.getAllDataObjects(null)); return Collections.<String>emptySet(); } }, Collections.<String>emptySet()); }
@TestOnly public ExecutionEnvironment() { myProject = null; myContentToReuse = null; myRunnerAndConfigurationSettings = null; myExecutor = null; myRunner = null; }
@TestOnly public void testPrepare() { myInputVariables.setFoldingAvailable(myInputVariables.isFoldingSelectedByDefault()); myMethodName = myInitialMethodName; myVariableDatum = new VariableData[myInputVariables.getInputVariables().size()]; for (int i = 0; i < myInputVariables.getInputVariables().size(); i++) { myVariableDatum[i] = myInputVariables.getInputVariables().get(i); } }
@TestOnly public static void allowRootAccessTemporarily(@NotNull Disposable disposable, @NotNull final String... roots) { for (String root : roots) { ourAdditionalRoots.add(FileUtil.toSystemIndependentName(root)); } Disposer.register(disposable, new Disposable() { @Override public void dispose() { disallowRootAccess(roots); } }); }
@TestOnly public void startup(@Nullable Runnable notifier) throws IOException { myTestNotifier = notifier; for (PluggableFileWatcher watcher : myWatchers) { watcher.startup(); } }
@TestOnly public void disableEventsUntil(@NotNull Disposable disposable) { final List<ApplicationListener> listeners = new ArrayList<ApplicationListener>(myDispatcher.getListeners()); myDispatcher.getListeners().removeAll(listeners); Disposer.register(disposable, new Disposable() { @Override public void dispose() { myDispatcher.getListeners().addAll(listeners); } }); }
@TestOnly public void waitForInitialized() { try { myFuture.get(); myFuture = null; } catch (Exception e) { throw new RuntimeException(e); } }
@NotNull @TestOnly public List<HighlightInfo> runPasses(@NotNull PsiFile file, @NotNull Document document, @NotNull TextEditor textEditor, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable Runnable callbackWhileWaiting) throws ProcessCanceledException { return runPasses(file, document, Collections.singletonList(textEditor), toIgnore, canChangeDocument, callbackWhileWaiting); }
@TestOnly public void checkAllTreesEqual() { Collection<PsiFileImpl> roots = myRoots.values(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getManager().getProject()); documentManager.commitAllDocuments(); for (PsiFile root : roots) { Document document = documentManager.getDocument(root); PsiDocumentManagerBase.checkConsistency(root, document); assert root.getText().equals(document.getText()); } }
@TestOnly public static void pushInjectors(@NotNull Project project) { InjectedLanguageManagerImpl cachedManager = (InjectedLanguageManagerImpl)project.getUserData(INSTANCE_CACHE); if (cachedManager == null) return; try { assert cachedManager.myInjectorsClone.isEmpty() : cachedManager.myInjectorsClone; } finally { cachedManager.myInjectorsClone.clear(); } cachedManager.myInjectorsClone.putAll(cachedManager.getInjectorMap().getBackingMap()); }
@TestOnly public static void setShowTemplatesInTests(boolean show, @NotNull Disposable parentDisposable) { ourShowTemplatesInTests = show; Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { //noinspection AssignmentToStaticFieldFromInstanceMethod ourShowTemplatesInTests = false; } }); }
@TestOnly int numberOfPointers() { int number = 0; for (FilePointerPartNode root : myPointers.values()) { number = root.getPointersUnder(); } return number; }
@NotNull @TestOnly public static List<HighlightInfo> getHighlights(@NotNull Document document, HighlightSeverity minSeverity, @NotNull Project project) { List<HighlightInfo> infos = new ArrayList<HighlightInfo>(); processHighlights(document, project, minSeverity, 0, document.getTextLength(), new CommonProcessors.CollectProcessor<HighlightInfo>(infos)); return infos; }
@TestOnly public void clearLookup() { if (myActiveLookup != null) { myActiveLookup.hide(); myActiveLookup = null; } }
@TestOnly public synchronized void releaseInTests() { if (!myEmbeddersInUse.isEmpty()) { MavenLog.LOG.warn("embedders should be release first"); } releasePooledEmbedders(false); }
@TestOnly public void enableStatistics(@NotNull Disposable parentDisposable) { myTestingStatistics = true; Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { synchronized (LOCK) { Arrays.fill(myUnits, null); } myTestingStatistics = false; } }); }
@TestOnly public void releaseInTests() { MavenServerIndexer w = getWrappee(); if (w == null) return; try { w.release(); } catch (RemoteException e) { handleRemoteError(e); } }
@TestOnly public static void assertOnRecursionPrevention(@NotNull Disposable parentDisposable) { ourAssertOnPrevention = true; Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { //noinspection AssignmentToStaticFieldFromInstanceMethod ourAssertOnPrevention = false; } }); }
/** * <pre>command --available-option=available_argument --option-no-argument positional_argument</pre> * * @return list cosists of fake command with opts and arguments */ @TestOnly @NotNull static List<Command> createCommands() { //command positional_argument --available-option=available_argument final Command command = EasyMock.createMock(Command.class); EasyMock.expect(command.getName()).andReturn("command").anyTimes(); EasyMock.expect(command.getHelp(true)).andReturn(new Help("some_text")).anyTimes(); EasyMock.expect(command.getHelp(false)).andReturn(new Help("some_text")).anyTimes(); final List<Option> options = new ArrayList<Option>(); final Pair<List<String>, Boolean> argument = Pair.create(Collections.singletonList("available_argument"), true); options.add(new Option(Pair.create(1, new Argument(new Help("option argument"), argument)), new Help(""), Collections.<String>emptyList(), Collections.singletonList("--available-option"))); options.add(new Option(null, new Help(""), Collections.<String>emptyList(), Collections.singletonList("--option-no-argument"))); EasyMock.expect(command.getOptions()).andReturn(options).anyTimes(); final ArgumentsInfo argumentInfo = new KnownArgumentsInfo(Collections.singletonList( new Argument(new Help("positional_argument"), Pair.create(Collections.singletonList("positional_argument"), true))), 1, 1); EasyMock.expect(command.getArgumentsInfo()).andReturn(argumentInfo) .anyTimes(); EasyMock.replay(command); return Collections.singletonList(command); }
@TestOnly private static VirtualFile[] getAllRoots(@NotNull Project project) { insideGettingRoots = true; final Set<VirtualFile> roots = new THashSet<VirtualFile>(); final OrderEnumerator enumerator = ProjectRootManager.getInstance(project).orderEntries(); ContainerUtil.addAll(roots, enumerator.getClassesRoots()); ContainerUtil.addAll(roots, enumerator.getSourceRoots()); insideGettingRoots = false; return VfsUtilCore.toVirtualFileArray(roots); }
@TestOnly public static void cleanRootArea(@NotNull Disposable parentDisposable) { final ExtensionsAreaImpl oldRootArea = (ExtensionsAreaImpl)getRootArea(); final ExtensionsAreaImpl newArea = createRootArea(); ourRootArea = newArea; oldRootArea.notifyAreaReplaced(); Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { ourRootArea = oldRootArea; newArea.notifyAreaReplaced(); } }); }
@TestOnly final synchronized void notifyAreaReplaced(final ExtensionsArea area) { for (final ExtensionPointListener<T> listener : myEPListeners) { if (listener instanceof ExtensionPointAndAreaListener) { ((ExtensionPointAndAreaListener)listener).areaReplaced(area); } } }
@TestOnly public void prepareForTest() { myAdditionalFeaturesLoaded = false; myFeatures.clear(); myApplicabilityFilters.clear(); myGroups.clear(); reloadFromXml(); }
/** * Configures given editor to wrap at given character count. * * @return whether any actual wraps of editor contents were created as a result of turning on soft wraps */ @TestOnly public static boolean configureSoftWraps(Editor editor, final int charCountToWrapAt) { int charWidthInPixels = 10; // we're adding 1 to charCountToWrapAt, to account for wrap character width, and 1 to overall width to overcome wrapping logic subtleties return configureSoftWraps(editor, (charCountToWrapAt + 1) * charWidthInPixels + 1, charWidthInPixels); }
/** * @throws MalformedURLException fuck it * @see URL#toString() */ @Test @TestOnly public void testUrlToString() throws MalformedURLException { DangerousWebsiteList.getInstance(); }
@Test @TestOnly public void select() throws Exception { }