Displaying keyword search results 1 - 10
Created by Fang on January 04, 2013 14:16:58 Last update: January 04, 2013 14:16:58
Junit does not support specifying execution order of tests until 4.11. The methods were simply invoked in the order returned by the reflection API. So, the tests are executed in a unspecified but deterministic order, i.e., you have no control over the order of execution, but if you repeat the tests, they are run in the same sequence each time. For version 4.11, you can specify the order with the FixMethodOrder annotation:
import org.junit.runners.MethodSorters; imp...From the release notes : Test execution order By design, JUnit does not specify the execution order of test method invocations. Until now, the methods were simply invoked in the order returned by the reflection API. However, using the JVM order is unwise since the Java platform does not specify...
Created by Dr. Xi on June 06, 2009 18:31:44 Last update: June 25, 2012 12:37:35
You can use the system call from the os module to execute an external program:
>>> import os >>> os.system(the_command_line_st...However, the path to the executable contains a space character, the system call treats the strings after the first space as arguments, causing an error. Python doc recommends the use of the subprocess module: The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. For example, using wget to get the google home page:
>>> from subprocess import Popen, PIPE >>> (out...or
>>> import subprocess >>> subprocess.call(['cur...
Created by Dr. Xi on March 08, 2012 12:13:57 Last update: March 08, 2012 12:13:57
This example creates an instance of XMLGregorianCalendar and converts it to java.util.Date :
import java.util.Date; import javax.xml.datatyp...
Created by Dr. Xi on May 02, 2011 15:59:37 Last update: February 25, 2012 09:16:37
This code snippet gets the default keystore used by the Java keytool and displays the list of aliases along with the key type (certificate or private key).
import java.io.File; import java.io.FileInputSt...The default keystore used by the above code is: $HOME/.keystore .
Created by magnum on August 11, 2010 19:22:06 Last update: November 28, 2011 08:16:22
import java.text.DateFormat; import java.text.S...Output:
Date LONG format: November 28, 2011 Date MEDIUM...
Created by Dr. Xi on November 11, 2011 10:05:22 Last update: November 11, 2011 10:12:01
This is an HTML image tag filter using Java regex. It takes a string, finds the img tags, replaces the src attribute with one provided by the filter, then adds a class name to the class attribute.
import java.util.regex.*; import java.io.*; ...Test file:
<div id="HTML snippet"> <img src="img/big/txt-m...
Created by Dr. Xi on July 27, 2011 08:55:34 Last update: July 27, 2011 08:55:34
It is OK to remove elements from a list with Iterator , but you get UnsupportedOperationException if the list is created with Arrays.asList :
import java.util.*; public class IteratorRe...Prints:
ArrayList test: ================ List size: ...
Created by alfa on July 15, 2011 13:25:45 Last update: July 15, 2011 13:25:45
Read the whole contents of a file into a String. It's better to read the whole file as bytes and convert to String than to read the file line by line and concatenate the lines.
String getFileContents(String fileName) throws...Using java.nio :
import java.io.FileInputStream; import java...
Created by Dr. Xi on July 15, 2011 09:25:15 Last update: July 15, 2011 09:25:15
Some methods to search for a substring within a string: To know that a substring indeed exists within a string:
boolean found = wholeString.contains(substring);To find where the substring is contained:
int index = wholeString.indexOf(substring);If the substring is regex:
boolean match = wholeString.matches(".*" + substri...Case insensitive match: convert both whole string and substring to lowercase, then compare. Or, use case insensitive flag for regex. Test code:
import java.util.regex.*; public class Stri...
Created by Dr. Xi on July 14, 2011 09:28:57 Last update: July 14, 2011 09:28:57
Java arrays are fixed size, so you have to make a new array with smaller size and copy the data. For JDK6 and above:
// import java.util.Arrays; newArray = Arrays.c...Before that (using Object as example):
Object newArray = new Object [newSize] ; Syst...