* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.classloading;
import java.io.File;
import java.net.URLClassLoader;
/**
- * Utility for adding jars to the system class loader.
+ * Utility for adding jars to the system class loader.
*/
public class ClassLoaderUtils {
// No logging in this class to keep the required class libraries
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Various classloading utilities.
*/
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.collections;
import org.wamblee.conditions.Condition;
import java.util.Collection;
/**
- * Collection filter for filtering collections based on a certain condition.
+ * Collection filter for filtering collections based on a certain condition.
*
* @author Erik Brakkee
*/
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Collection utilities.
*/
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
import java.util.concurrent.locks.ReentrantLock;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
import java.util.HashSet;
* robustness and simplicity. Users of this class should not synchronize on
* objects of this class.
*
- * This class was originally developed for a Java developer certification.
- * It is deprecated now and {@link java.util.concurrent.locks.ReadWriteLock} should be used
- * instead.
+ * This class was originally developed for a Java developer certification. It is
+ * deprecated now and {@link java.util.concurrent.locks.ReadWriteLock} should be
+ * used instead.
*/
@Deprecated
public class ReadWriteLock {
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* This package provides utilities for dealing with concurrency.
*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import java.util.ArrayList;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import java.util.ArrayList;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import java.lang.reflect.InvocationTargetException;
import java.util.regex.Pattern;
/**
- * Condition to check whether a given property of an object matches a certain regular
- * expression. The method name to use of the object passed in to
- * {@link #matches(Object)} is obtained using the Javabean conventions.
+ * Condition to check whether a given property of an object matches a certain
+ * regular expression. The method name to use of the object passed in to
+ * {@link #matches(Object)} is obtained using the Javabean conventions.
*
* @author Erik Brakkee
*
*/
public boolean matches(T aObject) {
try {
- String readerName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1);
+ String readerName = "get" + property.substring(0, 1).toUpperCase() +
+ property.substring(1);
Method reader = aObject.getClass().getMethod(readerName);
String value = reader.invoke(aObject) + "";
throw new RuntimeException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getMessage(), e);
- }
+ }
}
}
* This package provides some basic support classes for checking boolean conditions on objects.
*/
package org.wamblee.conditions;
+
*
*/
public class LookupProxyFactory<T> {
-
+
/**
- * Interface to lookup the object to delegate to.
+ * Interface to lookup the object to delegate to.
*
* @author Erik Brakkee
*/
- public static interface Lookup extends Serializable {
- /**
- * Looks up the object.
- * @return Object (non-null)
- * @throws Any exception in case the object cannot be found.
- */
- Object lookup() throws Exception;
+ public static interface Lookup extends Serializable {
+ /**
+ * Looks up the object.
+ *
+ * @return Object (non-null)
+ * @throws Any
+ * exception in case the object cannot be found.
+ */
+ Object lookup() throws Exception;
}
-
+
/**
- * Exception thrown in case an object cannot be retrieved from JNDI.
+ * Exception thrown in case an object cannot be retrieved from JNDI.
*
* @author Erik Brakkee
*/
}
/**
- * Invocation handler that does a lookup in JNDI and invokes the method on the
- * object it found.
+ * Invocation handler that does a lookup in JNDI and invokes the method on
+ * the object it found.
*
* @author Erik Brakkee
*/
- private static class LookupInvocationHandler<T> implements InvocationHandler, Serializable {
-
- private Class clazz;
- private Lookup lookup;
-
+ private static class LookupInvocationHandler<T> implements
+ InvocationHandler, Serializable {
+
+ private Class clazz;
+ private Lookup lookup;
+
/**
- * Constructs the invocation handler.
- * @param aLookup Lookup class.
+ * Constructs the invocation handler.
+ *
+ * @param aLookup
+ * Lookup class.
*/
public LookupInvocationHandler(Class aClass, Lookup aLookup) {
clazz = aClass;
- lookup = aLookup;
+ lookup = aLookup;
}
@Override
try {
svcObj = lookup.lookup();
} catch (Exception e) {
- throw new LookupException(
- "Error looking up object", e);
+ throw new LookupException("Error looking up object", e);
}
if (svcObj == null) {
throw new LookupException("Object is null");
}
if (!clazz.isInstance(svcObj)) {
- throw new LookupException("Object '" + svcObj + "' is not of type " + clazz.getName() +
- " but of type " + svcObj.getClass().getName());
+ throw new LookupException("Object '" + svcObj +
+ "' is not of type " + clazz.getName() + " but of type " +
+ svcObj.getClass().getName());
}
T svc = (T) svcObj;
try {
*
* @param aClass
* Interface class of the service to proxy.
- * @param aJndi JNDI name of the object to lookup.
+ * @param aJndi
+ * JNDI name of the object to lookup.
*
*/
public LookupProxyFactory(Class<T> aClass, Lookup aLookup) {
" is not an interface");
}
clazz = aClass;
- lookup = aLookup;
+ lookup = aLookup;
}
/**
* Gets the proxy that delegates to the thread-specific instance set by
* {@link #set(Object)}
*
- * When at runtime the proxy cannot find lookup the object in JNDI, it
- * throws {@link LookupException}.
+ * When at runtime the proxy cannot find lookup the object in JNDI, it
+ * throws {@link LookupException}.
*
* @return Proxy.
*/
package org.wamblee.general;
/**
- * This class provided an equality operation based on the object reference
- * of the wrapped object. This is required because we cannto assume that the
- * equals operation has any meaning for different types of persistent
- * objects. This allows us to use the standard collection classes for
- * detecting cyclic dependences and avoiding recursion.
+ * This class provided an equality operation based on the object reference of
+ * the wrapped object. This is required because we cannto assume that the equals
+ * operation has any meaning for different types of persistent objects. This
+ * allows us to use the standard collection classes for detecting cyclic
+ * dependences and avoiding recursion.
*/
public class ObjectElem {
private Object object;
/**
* Constructs the wrapper.
- * @param aObject Object.
+ *
+ * @param aObject
+ * Object.
*/
public ObjectElem(Object aObject) {
object = aObject;
public class ObjectSerializationUtils {
/**
- * Serialize an object to a byte array.
- * @param aObject Object ot serialize.
+ * Serialize an object to a byte array.
+ *
+ * @param aObject
+ * Object ot serialize.
* @return Byte array.
* @throws IOException
*/
public static byte[] serialize(Object aObject) throws IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos);
os.writeObject(aObject);
os.flush();
return bos.toByteArray();
}
-
+
/**
- * Desrializes an object from a byte array.
- * @param <T> Type of the object.
- * @param aData Serialized data.
- * @param aType Type of the object.
- * @return Object.
+ * Desrializes an object from a byte array.
+ *
+ * @param <T>
+ * Type of the object.
+ * @param aData
+ * Serialized data.
+ * @param aType
+ * Type of the object.
+ * @return Object.
* @throws IOException
* @throws ClassNotFoundException
*/
- public static <T> T deserialize(byte[] aData, Class<T> aType) throws IOException, ClassNotFoundException {
- ByteArrayInputStream bis = new ByteArrayInputStream(aData);
- ObjectInputStream os = new ObjectInputStream(bis);
- return (T)os.readObject();
+ public static <T> T deserialize(byte[] aData, Class<T> aType)
+ throws IOException, ClassNotFoundException {
+ ByteArrayInputStream bis = new ByteArrayInputStream(aData);
+ ObjectInputStream os = new ObjectInputStream(bis);
+ return (T) os.readObject();
}
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.general;
/**
import java.util.concurrent.atomic.AtomicInteger;
/**
- * Invocation handler for thread-specific proxies.
+ * Invocation handler for thread-specific proxies.
*
* @author Erik Brakkee
- *
+ *
* @param <T>
*/
-class ThreadSpecificInvocationHandler<T> implements InvocationHandler, Serializable {
-
+class ThreadSpecificInvocationHandler<T> implements InvocationHandler,
+ Serializable {
+
/**
- * We store a map of unique ids of invocation handlers to thread local storage of the
- * service. In this way, serialiability of the generated proxy is obtained (required by
- * framweorks such as wicket). Also, different factories will still be separate and never
- * use the same threadlocal storage.
+ * We store a map of unique ids of invocation handlers to thread local
+ * storage of the service. In this way, serialiability of the generated
+ * proxy is obtained (required by framweorks such as wicket). Also,
+ * different factories will still be separate and never use the same
+ * threadlocal storage.
*/
- private static Map<Integer,ThreadLocal> STORAGE = initializeThreadLocal();
-
+ private static Map<Integer, ThreadLocal> STORAGE = initializeThreadLocal();
+
private static AtomicInteger COUNTER = new AtomicInteger();
-
+
private static Map<Integer, ThreadLocal> initializeThreadLocal() {
- Map<Integer,ThreadLocal> map = new ConcurrentHashMap<Integer,ThreadLocal>();
+ Map<Integer, ThreadLocal> map = new ConcurrentHashMap<Integer, ThreadLocal>();
return map;
}
-
- private int id;
- private Class clazz;
-
+ private int id;
+ private Class clazz;
+
/**
- * Constructs the handler.
- * @param aSvc Thread local for the service.
- * @param aClass Service interface class.
+ * Constructs the handler.
+ *
+ * @param aSvc
+ * Thread local for the service.
+ * @param aClass
+ * Service interface class.
*/
- public ThreadSpecificInvocationHandler(ThreadLocal aSvc, Class aClass) {
+ public ThreadSpecificInvocationHandler(ThreadLocal aSvc, Class aClass) {
id = COUNTER.incrementAndGet();
clazz = aClass;
STORAGE.put(id, aSvc);
ThreadLocal<T> local = STORAGE.get(id);
T actualSvc = local.get();
- if ( aMethod.getName().equals("toString") && actualSvc == null) {
- return "Thread-specific proxy for '" + clazz.getName() + "' id = " + id;
+ if (aMethod.getName().equals("toString") && actualSvc == null) {
+ return "Thread-specific proxy for '" + clazz.getName() + "' id = " +
+ id;
}
try {
return aMethod.invoke(actualSvc, aArgs);
* method can be passed at construction of an object that will be used by
* multiple threads.
* </p>
- *
+ *
* <p>
* This class is mostly used by infrastructure code (utilities) and test tools.
* </p>
}
/**
- * Constructs the factory with a callback to create thread-specific objects
- * automatically.
+ * Constructs the factory with a callback to create thread-specific objects
+ * automatically.
*
* @param aClass
* Interface class of the service to proxy.
svc = new ThreadLocal<T>() {
@Override
protected T initialValue() {
- if ( aCallback != null ) {
+ if (aCallback != null) {
return aCallback.create();
}
- return null;
+ return null;
}
};
clazz = aClass;
package org.wamblee.general;
/**
- * Object that holds a value of some type. This can be used where a mutable final value would
- * be preferred.
+ * Object that holds a value of some type. This can be used where a mutable
+ * final value would be preferred.
*
* @author Erik Brakkee
- *
+ *
*/
public class ValueHolder<T> {
- private T value;
-
+ private T value;
+
/**
- * Constructs with null value.
+ * Constructs with null value.
*/
- public ValueHolder() {
- value = null;
+ public ValueHolder() {
+ value = null;
}
-
+
/**
- * Constructs with given value.
- * @param aValue Value.
+ * Constructs with given value.
+ *
+ * @param aValue
+ * Value.
*/
- public ValueHolder(T aValue) {
- value = aValue;
+ public ValueHolder(T aValue) {
+ value = aValue;
}
-
+
/**
- * @return Current value.
+ * @return Current value.
*/
public T getValue() {
return value;
}
-
+
/**
- * Set the value.
- * @param aValue New value.
+ * Set the value.
+ *
+ * @param aValue
+ * New value.
*/
public void setValue(T aValue) {
value = aValue;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.IOException;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
-
import java.io.File;
import java.io.FileFilter;
import java.util.logging.Logger;
/**
- * Monitors a directory for changes.
- * The currernt implementation only checks files not directories and does not check for
- * modifications in subdirectories.
+ * Monitors a directory for changes. The currernt implementation only checks
+ * files not directories and does not check for modifications in subdirectories.
*
* @author Erik Brakkee
*/
public class DirectoryMonitor {
- private static final Logger LOG = Logger.getLogger(DirectoryMonitor.class.getName());
+ private static final Logger LOG = Logger.getLogger(DirectoryMonitor.class
+ .getName());
private File directory;
}
/**
- * Listener interface to be provided by users of the directory monitor to get notified of
- * changes.
+ * Listener interface to be provided by users of the directory monitor to
+ * get notified of changes.
*
* @author Erik Brakkee
*/
public static interface Listener {
/**
- * @param aFile File that has changed.
+ * @param aFile
+ * File that has changed.
*/
void fileChanged(File aFile);
/**
- * @param aFile File that was created.
+ * @param aFile
+ * File that was created.
*/
void fileCreated(File aFile);
/**
- * @param aFile File that was deleted.
+ * @param aFile
+ * File that was deleted.
*/
void fileDeleted(File aFile);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.BufferedInputStream;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.IOException;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.File;
import java.util.regex.Pattern;
/**
- * Filename filter based on regular expressions.
+ * Filename filter based on regular expressions.
+ *
* @author Erik Brakkee
*/
public class RegexFilenameFilter implements FileFilter {
-
- private Pattern pattern;
-
+
+ private Pattern pattern;
+
/**
- * Constructs the filter.
- * @param aRegex Regular expression to filter on.
+ * Constructs the filter.
+ *
+ * @param aRegex
+ * Regular expression to filter on.
*/
- public RegexFilenameFilter(String aRegex) {
+ public RegexFilenameFilter(String aRegex) {
pattern = Pattern.compile(aRegex);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.BufferedReader;
* @version $Revision$
*/
public class SimpleProcess {
- private static final Logger LOG = Logger.getLogger(SimpleProcess.class.getName());
+ private static final Logger LOG = Logger.getLogger(SimpleProcess.class
+ .getName());
private File directory;
aReaderThread.join();
} catch (InterruptedException e) {
LOG
- .log(Level.WARNING, this +
- ": error waiting for output stream reader of process to finish", e);
+ .log(
+ Level.WARNING,
+ this +
+ ": error waiting for output stream reader of process to finish",
+ e);
}
}
try {
br.close();
} catch (IOException e) {
- LOG.log(Level.WARNING, "Error closing stream " + aPrefix, e);
+ LOG.log(Level.WARNING, "Error closing stream " +
+ aPrefix, e);
}
}
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.IOException;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* This package provides several support utilities for IO related functionality.
* The main classes are:
* </ul>
*/
package org.wamblee.io;
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.ioc;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.ioc;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Several utilities for abstracting the IOC container which is used.
*/
package org.wamblee.ioc;
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.observer;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.observer;
import java.util.ArrayList;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.observer;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.observer;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Support for the observer pattern.
*/
package org.wamblee.observer;
+
*/
protected AbstractDetachable(T aObject) {
if (aObject == null) {
- throw new IllegalArgumentException("Object '" + aObject +
- "' is null");
+ throw new IllegalArgumentException("Object is null");
}
object = aObject;
reference = null;
package org.wamblee.persistence;
/**
- * Inmemory detachable that simply returns the object passed in. Typiocally used for testing.
- * It does nothing at detach.
+ * Inmemory detachable that simply returns the object passed in. Typiocally used
+ * for testing. It does nothing at detach.
*
* @param <T>
* Type of the detachable.
/**
* Constructs the detachable.
+ *
* @param aObject
*/
public InMemoryDetachable(T aObject) {
/*
* (non-Javadoc)
+ *
* @see org.wamblee.persistence.Detachable#detach()
*/
public void detach() {
/*
* (non-Javadoc)
+ *
* @see org.wamblee.persistence.Detachable#get()
*/
public T get() {
import javax.persistence.EntityManager;
/**
- * Detachable JPA entity.
+ * Detachable JPA entity.
*
* @author Erik Brakkee
- *
- * @param <T> Entity type.
+ *
+ * @param <T>
+ * Entity type.
*/
public class JpaDetachable<T> extends AbstractDetachable<T, Serializable> {
-
- private EntityManager entityManager;
- private Class<T> entityType;
-
+
+ private EntityManager entityManager;
+ private Class<T> entityType;
+
/**
- * Constructs the detachable.
- * @param aEntity Entity.
+ * Constructs the detachable.
+ *
+ * @param aEntity
+ * Entity.
*/
public JpaDetachable(EntityManager aEntityManager, T aEntity) {
super(aEntity);
entityManager = aEntityManager;
- entityType = (Class<T>)aEntity.getClass();
+ entityType = (Class<T>) aEntity.getClass();
}
-
+
/*
* (non-Javadoc)
- * @see org.wamblee.persistence.AbstractDetachable#getReference(java.lang.Object)
+ *
+ * @see
+ * org.wamblee.persistence.AbstractDetachable#getReference(java.lang.Object)
*/
protected Serializable getReference(T aObject) {
Persistent persistent = PersistentFactory.create(aObject);
- return persistent.getPrimaryKey();
+ return persistent.getPrimaryKey();
}
-
+
@Override
protected T load(Serializable aReference) {
return entityManager.find(entityType, aReference);
* @author Erik Brakkee
*/
public class JpaMergeSupport {
- private static final Logger LOG = Logger.getLogger(JpaMergeSupport.class.getName());
+ private static final Logger LOG = Logger.getLogger(JpaMergeSupport.class
+ .getName());
/**
* Constructs the object.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.persistence;
import java.io.Serializable;
/**
- * Interface for persistent objects. This defines a generic interface for accessing
- * primary key and version of entities.
+ * Interface for persistent objects. This defines a generic interface for
+ * accessing primary key and version of entities.
*/
public interface Persistent {
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Utilities for (JPA) persistence.
*/
package org.wamblee.persistence;
+
package org.wamblee.reflection;
/**
- * Abstraction for accessing fields or properties of an object.
+ * Abstraction for accessing fields or properties of an object.
*
* @author Erik Brakkee
- *
+ *
* @param <T>
*/
public interface Accessor<T> {
/**
- * Sets the value.
- * @param aObject Object.
- * @param aValue Value.
+ * Sets the value.
+ *
+ * @param aObject
+ * Object.
+ * @param aValue
+ * Value.
*/
void set(Object aObject, T aValue);
/**
* Gets the value.
- * @param aObject Object
+ *
+ * @param aObject
+ * Object
* @return Value
*/
T get(Object aObject);
-
+
/**
* Gets the type of the value.
+ *
* @return
*/
Class<T> getType();
}
-
import java.util.List;
/**
- * Utlities for working with annotations.
+ * Utlities for working with annotations.
*
* @author Erik Brakkee
- *
+ *
*/
public class AnnotationUtils {
* Class to analyse.
* @param aAnnotation
* Annotation that must be present.
- * @return List of accessors. Empty list is returned if no match is found.
+ * @return List of accessors. Empty list is returned if no match is found.
*/
public static List<Accessor> analyse(Class aClass,
Class<? extends Annotation> aAnnotation) {
- List<Accessor> result = new ArrayList<Accessor>();
-
+ List<Accessor> result = new ArrayList<Accessor>();
+
List<Field> fields = ReflectionUtils.getAllFields(aClass);
for (Field field : fields) {
if (field.isAnnotationPresent(aAnnotation)) {
import java.lang.reflect.Field;
-
/**
- * Utility for interfacing to a field of an object.
+ * Utility for interfacing to a field of an object.
*
* @author Erik Brakkee
- *
- * @param <T> Type of the field.
+ *
+ * @param <T>
+ * Type of the field.
*/
public class FieldAccessor<T> implements Accessor<T> {
private Field field;
/**
- * Constructs the accessor.
- * @param aField Field.
+ * Constructs the accessor.
+ *
+ * @param aField
+ * Field.
*/
public FieldAccessor(Field aField) {
field = aField;
}
/**
- * Gets the field.
- * @return Field.
+ * Gets the field.
+ *
+ * @return Field.
*/
public Field getField() {
return field;
}
-
+
@Override
public Class<T> getType() {
- return (Class<T>)field.getType();
+ return (Class<T>) field.getType();
}
-
+
@Override
public String toString() {
- return "fieldInjection(" + field + ")";
+ return "fieldInjection(" + field + ")";
}
}
\ No newline at end of file
* @author Erik Brakkee
*/
public class ObjectTraversal {
-
- public static final Logger LOGGER = Logger.getLogger(ObjectTraversal.class.getName());
+
+ public static final Logger LOGGER = Logger.getLogger(ObjectTraversal.class
+ .getName());
/**
* Visitor interface to be implemented for object traversal.
public void addExcludedObject(Object aObject) {
excluded.add(new ObjectElem(aObject));
}
-
- private String indent() {
+
+ private String indent() {
StringBuffer buf = new StringBuffer();
- for (int i = 1; i < level; i++) {
+ for (int i = 1; i < level; i++) {
buf.append(" ");
}
return buf.toString();
if (alreadyProcessed(aObject)) {
return;
}
- if ( LOGGER.isLoggable(Level.FINEST)) {
+ if (LOGGER.isLoggable(Level.FINEST)) {
level++;
LOGGER.finest(indent() + "obj: " + aObject);
}
getter.getReturnType() != Void.class) {
if (visitor.mustVisit(getter)) {
- if ( LOGGER.isLoggable(Level.FINEST)) {
- LOGGER.finest(indent() + "method: " + getter.getName());
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER
+ .finest(indent() + "method: " + getter.getName());
}
acceptMethod(aObject, getter);
}
if (!Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) {
field.setAccessible(true);
if (visitor.mustVisit(field)) {
- if ( LOGGER.isLoggable(Level.FINEST)) {
+ if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest(indent() + "field: " + field.getName());
}
acceptField(aObject, field);
}
}
- private void acceptPlainOrCollection(Object value) {
- if (value instanceof Set) {
- visitor.visitSet((Set) value);
- processSet((Set) value);
- } else if (value instanceof List) {
- processList((List) value);
- } else if (value instanceof Map) {
- processMap((Map<?, ?>) value);
- } else if (value.getClass().isArray()) {
- processArray(value);
+ private void acceptPlainOrCollection(Object aValue) {
+ if (aValue instanceof Set) {
+ visitor.visitSet((Set) aValue);
+ processSet((Set) aValue);
+ } else if (aValue instanceof List) {
+ processList((List) aValue);
+ } else if (aValue instanceof Map) {
+ processMap((Map<?, ?>) aValue);
+ } else if (aValue.getClass().isArray()) {
+ processArray(aValue);
} else {
- accept(value);
+ accept(aValue);
}
}
import java.lang.reflect.Method;
-
/**
- * Accessing a property of an object.
+ * Accessing a property of an object.
*
* @author Erik Brakkee
- *
- * @param <T> Type of the property.
+ *
+ * @param <T>
+ * Type of the property.
*/
public class PropertyAccessor<T> implements Accessor<T> {
private Method getter;
private Method setter;
/**
- * Constructs the accessor.
- * @param aGetter Getter method.
- * @param aSetter Setter method.
+ * Constructs the accessor.
+ *
+ * @param aGetter
+ * Getter method.
+ * @param aSetter
+ * Setter method.
*/
public PropertyAccessor(Method aGetter, Method aSetter) {
getter = aGetter;
}
/**
- * @return The getter.
+ * @return The getter.
*/
public Method getGetter() {
return getter;
}
/**
- * @return The setter.
+ * @return The setter.
*/
public Method getSetter() {
return setter;
}
-
+
@Override
public String toString() {
- return "propertyInjection(" + getter + ", " + setter + ")";
+ return "propertyInjection(" + getter + ", " + setter + ")";
}
-
+
@Override
public Class<T> getType() {
- return (Class<T>)getter.getReturnType();
+ return (Class<T>) getter.getReturnType();
}
}
\ No newline at end of file
import java.util.Map;
/**
- * Some utilities for reflection.
+ * Some utilities for reflection.
*
* @author Erik Brakkee
*/
public class ReflectionUtils {
-
- public static final List<Class> PRIMITIVE_WRAPPERS =
- createPrimitiveWrappers();
-
- private static final List<Class> createPrimitiveWrappers() {
- Class[] vals = {
- Boolean.class, Byte.class, Character.class, Short.class, Integer.class, Long.class,
- Float.class, Double.class };
+
+ public static final List<Class> PRIMITIVE_WRAPPERS = createPrimitiveWrappers();
+
+ private static final List<Class> createPrimitiveWrappers() {
+ Class[] vals = { Boolean.class, Byte.class, Character.class,
+ Short.class, Integer.class, Long.class, Float.class, Double.class };
return Arrays.asList(vals);
}
-
-
-
-
+
/**
* Wraps a type by the corresponding wrapper type if it is a primitive type.
*
getAllFields(superClass, aFound, aExcludedClasses);
}
}
-
+
/**
* Checks if a class is a primitive type or wrapper type.
+ *
* @param aClass
* @return
*/
- public static boolean isPrimitive(Class aClass) {
- if ( aClass.isPrimitive()) {
- return true;
+ public static boolean isPrimitive(Class aClass) {
+ if (aClass.isPrimitive()) {
+ return true;
}
return PRIMITIVE_WRAPPERS.contains(aClass);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Utilities for reflection.
*/
package org.wamblee.reflection;
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
import org.wamblee.io.ClassPathResource;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
import org.apache.xml.serialize.OutputFormat;
* @author Erik Brakkee
*/
public final class DomUtils {
- private static final Logger LOG = Logger.getLogger(DomUtils.class.getName());
+ private static final Logger LOG = Logger
+ .getLogger(DomUtils.class.getName());
/**
* Disabled default constructor.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
import org.w3c.dom.Document;
} catch (IOException e) {
throw new TransformerException(e.getMessage(), e);
}
- }
+ }
throw new TransformerException("Cannot read '" + aXslt + "'");
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
/**
* Utilities for XML processing.
*/
package org.wamblee.xml;
+
computation = mock(CachedObject.Computation.class);
when(computation.getObject(anyInt())).thenAnswer(new Answer<Integer>() {
public Integer answer(
- org.mockito.invocation.InvocationOnMock invocation)
+ org.mockito.invocation.InvocationOnMock aInvocation)
throws Throwable {
ncomputations++;
- return compute((Integer) invocation.getArguments()[0]);
+ return compute((Integer) aInvocation.getArguments()[0]);
}
});
ncomputations = 0;
assertEquals(101, getComputationCount());
}
- public void testPreviousValueWhileComputationBeingDone() throws Exception {
- final CachedObject<Integer,Integer> cached = createCached(new ZeroCache<Integer, Integer>());
+ public void testPreviousValueWhileComputationBeingDone() throws Exception {
+ final CachedObject<Integer, Integer> cached = createCached(new ZeroCache<Integer, Integer>());
reset(computation);
when(computation.getObject(anyInt())).thenReturn(1).thenAnswer(
new Answer<Integer>() {
TimingUtils.sleep(1000);
return 2;
}
- }
- ).thenReturn(3);
-
+ }).thenReturn(3);
+
assertEquals(1, cached.get().intValue());
Thread recompute = new Thread(new Runnable() {
-
+
@Override
public void run() {
- // will sleep for 1 second.
+ // will sleep for 1 second.
assertEquals(2, cached.get().intValue());
}
});
recompute.start();
- // Now asking the value should not recompute but should return the old value.
+ // Now asking the value should not recompute but should return the old
+ // value.
TimingUtils.sleep(500);
assertEquals(1, cached.get().intValue());
recompute.join();
}
-
- public void testNullValueWhenComputationReturnsNull() throws Exception {
- final CachedObject<Integer,Integer> cached = createCached(new ZeroCache<Integer, Integer>());
+
+ public void testNullValueWhenComputationReturnsNull() throws Exception {
+ final CachedObject<Integer, Integer> cached = createCached(new ZeroCache<Integer, Integer>());
reset(computation);
- when(computation.getObject(anyInt())).thenReturn(1).thenReturn(null).thenReturn(2);
-
+ when(computation.getObject(anyInt())).thenReturn(1).thenReturn(null)
+ .thenReturn(2);
+
assertEquals(1, cached.get().intValue());
assertNull(cached.get());
assertEquals(2, cached.get().intValue());
}
-
- public void testPreviousValueWhenComputationThrowsException() throws Exception {
- final CachedObject<Integer,Integer> cached = createCached(new ZeroCache<Integer, Integer>());
+
+ public void testPreviousValueWhenComputationThrowsException()
+ throws Exception {
+ final CachedObject<Integer, Integer> cached = createCached(new ZeroCache<Integer, Integer>());
reset(computation);
- when(computation.getObject(anyInt())).thenReturn(1).thenThrow(new RuntimeException()).thenReturn(2);
-
+ when(computation.getObject(anyInt())).thenReturn(1).thenThrow(
+ new RuntimeException()).thenReturn(2);
+
assertEquals(1, cached.get().intValue());
assertEquals(1, cached.get().intValue());
assertEquals(2, cached.get().intValue());
private Computation<Integer> computation;
private ComputedValue<Integer> guard;
-
@Override
protected void setUp() throws Exception {
guard = new ComputedValue<Integer>(this, computation);
assertNull(guard.getCached());
-
+
when(computation.isOutOfDate()).thenReturn(true);
when(computation.compute()).thenReturn(10);
-
+
int value = guard.get();
assertEquals(10, value);
verify(computation).compute();
reset(computation);
}
-
- public void testGetCached() {
+
+ public void testGetCached() {
initGuard();
- assertEquals(10, (int)guard.getCached());
+ assertEquals(10, (int) guard.getCached());
verifyNoMoreInteractions(computation);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.collections;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
import junit.framework.TestCase;
public void testLock() throws InterruptedException {
Thread t1 = runThread();
Thread t2 = runThread();
- TimingUtils.sleep(SLEEP_TIME/2); // give threads a chance to start
+ TimingUtils.sleep(SLEEP_TIME / 2); // give threads a chance to start
// up.
assertEquals(2, tracker.getEventCount(STARTED)); // both threads
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
import org.wamblee.test.TimingUtils;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.concurrency;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
import junit.framework.TestCase;
checkMatch("value", "all", false, bean, false);
checkMatch("value", ".a.*o", false, bean, true);
checkMatch("value", "hallo", false, bean, false); // no match when not
- // converting to lower
- // case.
+ // converting to lower
+ // case.
checkMatch("value", "hallo", true, bean, true); // match!
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.conditions;
/**
public void setUp() throws Exception {
intf = mock(MyInterface.class);
lookup = mock(Lookup.class);
-
+
LookupProxyFactory<MyInterface> factory = new LookupProxyFactory<MyInterface>(
- MyInterface.class, lookup);
+ MyInterface.class, lookup);
proxy = factory.getProxy();
}
@Test(expected = LookupException.class)
public void testNotFoundAtJndi() throws Exception {
- when(lookup.lookup()).thenThrow(new RuntimeException("Object not found"));
+ when(lookup.lookup()).thenThrow(
+ new RuntimeException("Object not found"));
proxy.execute();
}
assertEquals(NAA_NA_NA_NAA_NA, e.getMessage());
}
}
-
- private static final class MyLookup implements Lookup {
-
+
+ private static final class MyLookup implements Lookup {
+
@Override
public Object lookup() throws Exception {
return new MyInterface() {
-
+
@Override
public int execute() {
return 10;
};
}
}
-
- @Test
+
+ @Test
public void testProxyMustBerializable() throws Exception {
lookup = new MyLookup();
LookupProxyFactory<MyInterface> factory = new LookupProxyFactory<MyInterface>(
- MyInterface.class, lookup);
+ MyInterface.class, lookup);
proxy = factory.getProxy();
-
+
+ assertEquals(10, proxy.execute());
+
+ assertTrue(proxy instanceof Serializable);
+
+ proxy = ObjectSerializationUtils.deserialize(ObjectSerializationUtils
+ .serialize(proxy), MyInterface.class);
+
+ // and it should still work
assertEquals(10, proxy.execute());
-
- assertTrue(proxy instanceof Serializable);
-
- proxy = ObjectSerializationUtils.deserialize(ObjectSerializationUtils.serialize(proxy),
- MyInterface.class);
-
- // and it should still work
- assertEquals(10, proxy.execute());
}
-
}
public class ObjectElemTest {
@Test
- public void testSameObjectEqual() {
- String s = "x";
- ObjectElem s1 = new ObjectElem(s);
+ public void testSameObjectEqual() {
+ String s = "x";
+ ObjectElem s1 = new ObjectElem(s);
ObjectElem s2 = new ObjectElem(s);
assertEquals(s1, s2);
}
-
+
@Test
- public void testDifferentButEqualObjectsNotEqual() {
- String s = new String("x");
+ public void testDifferentButEqualObjectsNotEqual() {
+ String s = new String("x");
ObjectElem se = new ObjectElem(s);
String t = new String("x");
ObjectElem te = new ObjectElem(t);
assertEquals(s, t);
- assertNotSame(s,t);
+ assertNotSame(s, t);
assertFalse(se.equals(te));
}
-
+
@Test
- public void testNull() {
+ public void testNull() {
ObjectElem se = new ObjectElem("x");
assertFalse(se.equals(null));
}
-
+
@Test
- public void testWrongType(){
+ public void testWrongType() {
ObjectElem se = new ObjectElem("x");
assertFalse(se.equals("x"));
}
-
+
}
public class ObjectSerializationUtilsTest {
@Test
- public void testSerialize() throws Exception {
- String s = "hello world";
+ public void testSerialize() throws Exception {
+ String s = "hello world";
byte[] data = ObjectSerializationUtils.serialize(s);
assertNotNull(data);
String t = ObjectSerializationUtils.deserialize(data, String.class);
assertEquals(50, proxy.execute(10));
verify(svc).execute(10);
}
-
+
@Test
- public void testCreationCallback() throws Exception {
+ public void testCreationCallback() throws Exception {
CreationCallback callback = mock(CreationCallback.class);
- Service initialService = mock(Service.class);
+ Service initialService = mock(Service.class);
when(callback.create()).thenReturn(initialService);
-
- factory = new ThreadSpecificProxyFactory<Service>(Service.class, callback);
+
+ factory = new ThreadSpecificProxyFactory<Service>(Service.class,
+ callback);
proxy = factory.getProxy();
Service svc = factory.get();
-
- assertSame(initialService, svc);
+
+ assertSame(initialService, svc);
verify(callback).create();
}
@Test(expected = IllegalArgumentException.class)
public void testNotAnInterface() {
- ThreadSpecificProxyFactory f = new ThreadSpecificProxyFactory(String.class);
+ ThreadSpecificProxyFactory f = new ThreadSpecificProxyFactory(
+ String.class);
}
-
+
@Test
- public void testProxyToStringWhileUninitialized() {
+ public void testProxyToStringWhileUninitialized() {
String val = proxy.toString();
}
}
public class ValueHolderTest extends TestCase {
- public void testDefault() {
- ValueHolder<Integer> val = new ValueHolder<Integer>();
+ public void testDefault() {
+ ValueHolder<Integer> val = new ValueHolder<Integer>();
assertNull(val.getValue());
}
-
- public void testNonDefault() {
- ValueHolder<Integer> val = new ValueHolder<Integer>(10);
- assertEquals(10, (int)val.getValue());
+
+ public void testNonDefault() {
+ ValueHolder<Integer> val = new ValueHolder<Integer>(10);
+ assertEquals(10, (int) val.getValue());
}
-
- public void testSetGet() {
- ValueHolder<Integer> val = new ValueHolder<Integer>(10);
- val.setValue(100);
- assertEquals(100, (int)val.getValue());
+
+ public void testSetGet() {
+ ValueHolder<Integer> val = new ValueHolder<Integer>(10);
+ val.setValue(100);
+ assertEquals(100, (int) val.getValue());
}
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import static org.mockito.Mockito.*;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.File;
public class DirectoryMonitorTestProgram {
public static void main(String[] aArgs) throws Exception {
DirectoryMonitor monitor = new DirectoryMonitor(new File("."),
- new RegexFilenameFilter(".*\\.txt"), new DirectoryMonitor.Listener() {
+ new RegexFilenameFilter(".*\\.txt"),
+ new DirectoryMonitor.Listener() {
public void fileChanged(File aFile) {
System.out.println("changed " + aFile);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.File;
* @author Erik Brakkee
*/
public final class FileSystemUtils {
- private static final Logger LOG = Logger.getLogger(FileSystemUtils.class.getName());
+ private static final Logger LOG = Logger.getLogger(FileSystemUtils.class
+ .getName());
/**
* Test output directory relative to the sub project.
path = URLDecoder.decode(location.getPath(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// ignore it.. just don't decode
- LOG.log(Level.WARNING, "Decoding path failed: '" + location.getPath() + "'", e);
+ LOG.log(Level.WARNING, "Decoding path failed: '" +
+ location.getPath() + "'", e);
}
return new File(new File(path).getParentFile(), aRelativePath);
Assert.assertTrue(aSrc.isDirectory());
Assert.assertTrue(!aTarget.exists());
- if (!aTarget.mkdirs()) {
+ if (!aTarget.mkdirs()) {
Assert.fail("Could not create target directory '" + aTarget + "'");
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.ByteArrayInputStream;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import java.io.File;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.ioc;
-
import junit.framework.TestCase;
/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.ioc;
import org.wamblee.general.Pair;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.ioc;
-
public class TestBeanFactory implements BeanFactory {
@Override
public Object find(String aId) {
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.observer;
import junit.framework.TestCase;
private DetachableMethods methods;
private AbstractDetachable<X, Integer> detachable;
- private X x;
+ private X x;
@Before
public void setUp() {
assertNull(detachable.getObject());
assertEquals(ref, detachable.getReference());
}
-
+
@Test
- public void testDetachTwice() {
- reset(methods);
- testDetach();
- detachable.detach();
- detachable.detach();
+ public void testDetachTwice() {
+ reset(methods);
+ testDetach();
+ detachable.detach();
+ detachable.detach();
verifyNoMoreInteractions(methods);
}
-
- @Test(expected = IllegalStateException.class)
- public void testDetachWithNullReference() {
+
+ @Test(expected = IllegalStateException.class)
+ public void testDetachWithNullReference() {
x = new X();
Integer ref = 100;
when(methods.getReference(any(X.class))).thenReturn(null);
verifyNoMoreInteractions(methods);
detachable.detach();
}
-
+
@Test
public void testReattach() {
- testDetach();
+ testDetach();
reset(methods);
-
+
X x2 = new X(); // the new X loaded from persistent storage.
- when(methods.load(detachable.getReference())).thenReturn(x2);
-
+ when(methods.load(detachable.getReference())).thenReturn(x2);
+
X x3 = detachable.get();
- verify(methods).load(100);
- assertSame(x2, x3);
-
+ verify(methods).load(100);
+ assertSame(x2, x3);
+
assertSame(x2, detachable.getObject());
}
-
+
@Test
- public void testGetInvokedTwiceNoLoads() {
- testReattach();
- reset(methods);
- detachable.get();
- detachable.get();
+ public void testGetInvokedTwiceNoLoads() {
+ testReattach();
+ reset(methods);
+ detachable.get();
+ detachable.get();
verifyNoMoreInteractions(methods);
}
-
}
import static junit.framework.TestCase.*;
public class JpaDetachableTest {
-
- public class X {
+
+ public class X {
@Id
- private int id;
-
+ private int id;
+
}
-
- private EntityManager em;
-
- @Before
- public void setUp() {
+
+ private EntityManager em;
+
+ @Before
+ public void setUp() {
em = mock(EntityManager.class);
}
-
+
@Test
- public void testDetachAttach() {
- X x = new X();
- x.id = 100;
-
+ public void testDetachAttach() {
+ X x = new X();
+ x.id = 100;
+
JpaDetachable<X> d = new JpaDetachable<X>(em, x);
assertNull(d.getReference());
d.detach();
assertEquals(100, d.getReference());
-
+
X x2 = new X();
x2.id = 100;
when(em.find(X.class, 100)).thenReturn(x2);
X x3 = d.get();
- assertSame(x2, x3);
+ assertSame(x2, x3);
verify(em).find(X.class, 100);
-
+
}
}
private static class X1 {
@Id
- int id;
+ private int id;
@Version
- int version;
+ private int version;
private String value;
}
return value.equals(((X1) aObj).getValue());
}
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
}
private static class X2 {
@Id
- int id;
+ private int id;
private List<X1> list;
private static class X3 {
@Id
- int id;
+ private int id;
private Set<X1> set;
private static class X4 {
@Id
- int id;
+ private int id;
private Map<String, X1> map;
private static class X5 {
@Id
- int id;
+ private int id;
private X1[] array;
return array;
}
}
-
- private static class X6 {
+
+ private static class X6 {
@Id
- int id;
-
- public X1 getNotaGetter(String aMessage) {
- return null;
+ private int id;
+
+ public X1 getNotaGetter(String aMessage) {
+ return null;
}
-
- public void getNotaGetter2() {
-
+
+ public void getNotaGetter2() {
+
}
}
-
- private static class X7 {
+
+ private static class X7 {
@Id
- int id;
-
- private void getX() {
+ private int id;
+
+ private void getX() {
fail("Private getters should not be used");
}
}
}
@Test
- public void testNotAGetter() {
- X6 x = new X6();
- x.id = 100;
- X6 y = new X6();
-
- JpaMergeSupport.merge(x,y);
+ public void testNotAGetter() {
+ X6 x = new X6();
+ x.id = 100;
+ X6 y = new X6();
+
+ JpaMergeSupport.merge(x, y);
assertEquals(x.id, y.id);
}
-
- @Test
- public void testPrivateGetter() {
- X7 x = new X7();
+
+ @Test
+ public void testPrivateGetter() {
+ X7 x = new X7();
x.id = 100;
- X7 y = new X7();
- JpaMergeSupport.merge(x,y);
+ X7 y = new X7();
+ JpaMergeSupport.merge(x, y);
assertEquals(x.id, y.id);
}
}
public void setPk(int aPk) {
pk = aPk;
}
-
- private void privateSetter(int aPk) {
+
+ private void privateSetter(int aPk) {
pk = aPk;
}
-
- private int privateGetter() {
- return pk;
+
+ private int privateGetter() {
+ return pk;
}
}
pk = aPk;
}
}
-
+
public static class X3 {
private int pk;
public void setVersion(int aVersion) {
version = aVersion;
}
-
- private void privateSetter(int aVersion) {
+
+ private void privateSetter(int aVersion) {
version = aVersion;
}
-
- private int privateGetter() {
- return version;
+
+ private int privateGetter() {
+ return version;
}
}
version = aVersion;
}
}
-
+
public static class X6 {
private int version;
version = aVersion;
}
}
-
- public static class X7 {
+
+ public static class X7 {
@Id
- public int id;
-
+ public int id;
+
@Version
- public int version;
+ public int version;
}
// FieldAccessor test
accessor.set(x1, 10);
assertEquals(10, x1.getPk());
}
-
+
@Test
- public void testPropertyAccessorPrivate() throws Exception {
+ public void testPropertyAccessorPrivate() throws Exception {
Accessor<Integer> accessor = new PropertyAccessor<Integer>(X1.class
- .getDeclaredMethod("privateGetter"), X1.class.getDeclaredMethod("privateSetter",
- int.class));
+ .getDeclaredMethod("privateGetter"), X1.class.getDeclaredMethod(
+ "privateSetter", int.class));
X1 x1 = new X1();
assertEquals(0, x1.getPk());
accessor.set(x1, 10);
- assertEquals((Integer)10, accessor.get(x1));
-
+ assertEquals((Integer) 10, accessor.get(x1));
+
}
// EntityAccessor test
@Test
public void testEntityAccessorPkField() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X1.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X1.class);
assertNotNull(accessor);
assertTrue(accessor.getPk() instanceof FieldAccessor);
assertNull(accessor.getVersion());
@Test
public void testEntityAccessorPkProperty() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X2.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X2.class);
assertNotNull(accessor);
assertNotNull(accessor.getPk());
assertTrue(accessor.getPk() instanceof PropertyAccessor);
assertEquals("getPk", property.getGetter().getName());
assertEquals("setPk", property.getSetter().getName());
}
-
+
@Test
public void testEntityAccessorPkPropertyPrivate() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X3.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X3.class);
assertNotNull(accessor);
assertNotNull(accessor.getPk());
assertTrue(accessor.getPk() instanceof PropertyAccessor);
@Test
public void testEntityAccessorVersionField() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X4.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X4.class);
assertNotNull(accessor);
assertTrue(accessor.getVersion() instanceof FieldAccessor);
assertNull(accessor.getPk());
- assertEquals("version", ((FieldAccessor) accessor.getVersion()).getField()
- .getName());
+ assertEquals("version", ((FieldAccessor) accessor.getVersion())
+ .getField().getName());
}
@Test
public void testEntityAccessorVersionProperty() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X5.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X5.class);
assertNotNull(accessor);
assertNotNull(accessor.getVersion());
assertTrue(accessor.getVersion() instanceof PropertyAccessor);
assertEquals("getVersion", property.getGetter().getName());
assertEquals("setVersion", property.getSetter().getName());
}
-
+
@Test
public void testEntityAccessorVersionPropertyPrivate() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X6.class);
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X6.class);
assertNotNull(accessor);
assertNotNull(accessor.getVersion());
assertTrue(accessor.getVersion() instanceof PropertyAccessor);
assertEquals("getVersion", property.getGetter().getName());
assertEquals("setVersion", property.getSetter().getName());
}
-
+
@Test
- public void testNoVersionAndNoPk() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(String.class);
+ public void testNoVersionAndNoPk() {
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(String.class);
assertNull(accessor);
}
@Test
- public void testPkAndVersion() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X7.class);
+ public void testPkAndVersion() {
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X7.class);
assertNotNull(accessor.getPk());
assertNotNull(accessor.getVersion());
-
+
X7 x = new X7();
assertEquals(0, x.id);
assertEquals(0, x.version);
-
- accessor.getPk().set(x, 10);
+
+ accessor.getPk().set(x, 10);
accessor.getVersion().set(x, 20);
-
+
assertEquals(10, x.id);
assertEquals(20, x.version);
}
-
- @Test
- public void testEntityAccessorCache() {
- EntityAccessor accessor = PersistentFactory.createEntityAccessor(X1.class);
- EntityAccessor accessor2 = PersistentFactory.createEntityAccessor(X1.class);
-
+
+ @Test
+ public void testEntityAccessorCache() {
+ EntityAccessor accessor = PersistentFactory
+ .createEntityAccessor(X1.class);
+ EntityAccessor accessor2 = PersistentFactory
+ .createEntityAccessor(X1.class);
+
assertSame(accessor, accessor2);
}
-
- // EntityObjectAccessor test for undefined pk and/or version.
+
+ // EntityObjectAccessor test for undefined pk and/or version.
@Test
- public void testEntityObjectAccessorRobustness() {
- EntityObjectAccessor accessor = new EntityObjectAccessor("hello world",
+ public void testEntityObjectAccessorRobustness() {
+ EntityObjectAccessor accessor = new EntityObjectAccessor("hello world",
new EntityAccessor(null, null));
assertNull(accessor.getPrimaryKey());
assertNull(accessor.getPersistedVersion());
accessor.setPrimaryKey("bla");
accessor.setPersistedVersion(100);
-
+
}
}
import org.junit.Test;
-import static junit.framework.TestCase.*;
+import static junit.framework.TestCase.*;
public class AnnotationUtilsTest {
-
+
@Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.FIELD, ElementType.METHOD})
- public static @interface MyAnnotation {
-
+ @Target( { ElementType.FIELD, ElementType.METHOD })
+ public static @interface MyAnnotation {
+
}
-
- public static class X1 {
+
+ public static class X1 {
@MyAnnotation
- public int x;
+ public int x;
}
-
- public static class X2 {
+
+ public static class X2 {
@MyAnnotation
private int x;
-
+
}
- public static class X3 {
+ public static class X3 {
private int x;
-
+
public void setX(int aX) {
x = aX;
}
-
+
@MyAnnotation
public int getX() {
return x;
}
}
-
- public static class X4 {
+
+ public static class X4 {
private int x;
-
+
private void setX(int aX) {
x = aX;
}
-
+
@MyAnnotation
private int getX() {
return x;
}
}
- public static class X5 {
+ public static class X5 {
private int x;
-
+
@MyAnnotation
- private int y;
-
+ private int y;
+
private void setX(int aX) {
x = aX;
}
-
+
@MyAnnotation
private int getX() {
return x;
}
}
-
-
@Test
public void testPublicField() {
- List<Accessor> accessors = AnnotationUtils.analyse(X1.class, MyAnnotation.class);
+ List<Accessor> accessors = AnnotationUtils.analyse(X1.class,
+ MyAnnotation.class);
assertEquals(1, accessors.size());
assertTrue(accessors.get(0) instanceof FieldAccessor);
assertEquals(int.class, accessors.get(0).getType());
X1 obj = new X1();
assertEquals(0, obj.x);
accessors.get(0).set(obj, 100);
- assertEquals(100,obj.x);
+ assertEquals(100, obj.x);
}
-
+
@Test
- public void testPrivateField() {
- List<Accessor> accessors = AnnotationUtils.analyse(X2.class, MyAnnotation.class);
+ public void testPrivateField() {
+ List<Accessor> accessors = AnnotationUtils.analyse(X2.class,
+ MyAnnotation.class);
assertEquals(1, accessors.size());
assertTrue(accessors.get(0) instanceof FieldAccessor);
X2 obj = new X2();
accessors.get(0).set(obj, 100);
assertEquals(100, obj.x);
}
-
+
@Test
- public void testPublicProperty() {
- List<Accessor> accessors = AnnotationUtils.analyse(X3.class, MyAnnotation.class);
+ public void testPublicProperty() {
+ List<Accessor> accessors = AnnotationUtils.analyse(X3.class,
+ MyAnnotation.class);
assertEquals(1, accessors.size());
assertTrue(accessors.get(0) instanceof PropertyAccessor);
assertEquals(int.class, accessors.get(0).getType());
accessors.get(0).set(obj, 100);
assertEquals(100, obj.x);
}
-
+
@Test
- public void testPrivateProperty() {
- List<Accessor> accessors = AnnotationUtils.analyse(X4.class, MyAnnotation.class);
+ public void testPrivateProperty() {
+ List<Accessor> accessors = AnnotationUtils.analyse(X4.class,
+ MyAnnotation.class);
assertEquals(1, accessors.size());
assertTrue(accessors.get(0) instanceof PropertyAccessor);
X4 obj = new X4();
accessors.get(0).set(obj, 100);
assertEquals(100, obj.x);
}
-
+
@Test
- public void testMultipleMatches() {
- List<Accessor> accessors = AnnotationUtils.analyse(X5.class, MyAnnotation.class);
+ public void testMultipleMatches() {
+ List<Accessor> accessors = AnnotationUtils.analyse(X5.class,
+ MyAnnotation.class);
assertEquals(2, accessors.size());
X5 obj = new X5();
assertEquals(0, obj.x);
assertEquals(0, obj.y);
- for (Accessor accessor: accessors) {
+ for (Accessor accessor : accessors) {
accessor.set(obj, 100);
}
assertEquals(100, obj.x);
when(visitor.mustVisit(any(Class.class))).thenReturn(true);
when(visitor.mustVisit(any(Field.class))).thenReturn(true);
when(visitor.mustVisit(any(Method.class))).thenReturn(true);
-
+
when(visitor.visitPlainObject(any())).thenReturn(true);
when(visitor.visitArray(any())).thenReturn(true);
when(visitor.visitList(any(List.class))).thenReturn(true);
when(visitor.visitMap(any(Map.class))).thenReturn(true);
when(visitor.visitSet(any(Set.class))).thenReturn(true);
-
+
ObjectTraversal.LOGGER.setLevel(Level.FINEST);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
ObjectTraversal.LOGGER.addHandler(handler);
}
-
- public static class X1 {
-
+
+ public static class X1 {
+
}
- public static class X2 {
- private X1 x;
+ public static class X2 {
+ private X1 x;
}
-
-
+
@Test
public void testTraverseFields() throws Exception {
X2 x2 = new X2();
- X1 x1 = new X1();
+ X1 x1 = new X1();
x2.x = x1;
traversal.accept(x2);
verify(visitor).mustVisit(X2.class);
verify(visitor).visitPlainObject(same(x1));
verifyNoMoreInteractions(visitor);
}
-
+
public static class TraversalNonTraversedFields {
private int x;
private Object y = new Object();
@Test
public void testNonTraversedFields() throws Exception {
- TraversalNonTraversedFields obj =new TraversalNonTraversedFields();
+ TraversalNonTraversedFields obj = new TraversalNonTraversedFields();
traversal.accept(obj);
verify(visitor).mustVisit(TraversalNonTraversedFields.class);
- verify(visitor).mustVisit(eq(TraversalNonTraversedFields.class.getDeclaredField("x")));
- verify(visitor).mustVisit(eq(TraversalNonTraversedFields.class.getDeclaredField("y")));
+ verify(visitor).mustVisit(
+ eq(TraversalNonTraversedFields.class.getDeclaredField("x")));
+ verify(visitor).mustVisit(
+ eq(TraversalNonTraversedFields.class.getDeclaredField("y")));
verify(visitor).visitPlainObject(same(obj));
}
-
- public static class X3 {
-
+
+ public static class X3 {
+
}
-
- public static class X4 {
- public X3 getX3() {
+
+ public static class X4 {
+ public X3 getX3() {
return new X3();
}
}
-
@Test
public void testTraverseMethods() throws Exception {
@Test
public void testTraverseList() {
- List list = new ArrayList();
+ List list = new ArrayList();
list.add(new X1());
list.add(new X3());
traversal.accept(list);
@Test
public void testTraverseMap() {
- Map<String,Object> map = new HashMap<String,Object>();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("x1", new X1());
map.put("x3", new X3());
traversal.accept(map);
@Test
public void testTraverseSet() {
- Set set = new HashSet();
+ Set set = new HashSet();
set.add(new X1());
set.add(new X3());
traversal.accept(set);
@Test
public void testTraverseArray() {
- Object[] obj = new Object[2];
+ Object[] obj = new Object[2];
obj[0] = new X1();
obj[1] = new X3();
traversal.accept(obj);
@Test
public void testExcludeClasses() {
- X2 x2 = new X2();
+ X2 x2 = new X2();
x2.x = new X1();
when(visitor.mustVisit(X1.class)).thenReturn(false);
traversal.accept(x2);
@Test
public void testExcludeFields() {
- X2 x2 = new X2();
+ X2 x2 = new X2();
x2.x = new X1();
when(visitor.mustVisit(any(Field.class))).thenReturn(false);
traversal.accept(x2);
@Test
public void testExcludeMethods() {
- X4 x4 = new X4();
+ X4 x4 = new X4();
when(visitor.mustVisit(any(Method.class))).thenReturn(false);
traversal.accept(x4);
verify(visitor).visitPlainObject(same(x4));
verify(visitor, never()).visitPlainObject(isA(X3.class));
}
-
- public static class X5 {
+
+ public static class X5 {
private X6 x6;
}
-
- public static class X6 {
+
+ public static class X6 {
private X5 x5;
}
-
+
@Test
public void testCyclic() {
X6 x6 = new X6();
- X5 x5 = new X5();
+ X5 x5 = new X5();
x6.x5 = x5;
x5.x6 = x6;
traversal.accept(x6);
@Test
public void testCyclicList() {
- List list = new ArrayList();
- list.add(list);
- traversal.accept(list);
+ List list = new ArrayList();
+ list.add(list);
+ traversal.accept(list);
verify(visitor, times(1)).visitList(same(list));
}
@Test
public void testCyclicMap() {
- Map map = new HashMap();
- map.put("x", map);
- traversal.accept(map);
+ Map map = new HashMap();
+ map.put("x", map);
+ traversal.accept(map);
verify(visitor, times(1)).visitMap(same(map));
}
@Test
public void testCyclicSet() {
- Set set = new HashSet();
- set.add(set);
- traversal.accept(set);
+ Set set = new HashSet();
+ set.add(set);
+ traversal.accept(set);
verify(visitor, times(1)).visitSet(same(set));
}
@Test
public void testCyclicArray() {
- Object[] obj = new Object[1];
- obj[0] = obj;
- traversal.accept(obj);
+ Object[] obj = new Object[1];
+ obj[0] = obj;
+ traversal.accept(obj);
verify(visitor, times(1)).visitArray(same(obj));
}
public void testVisitNull() {
traversal.accept(null);
}
-
+
@Test
public void testExcludeFieldByReturningFalseInVisit() {
- X2 x2 = new X2();
+ X2 x2 = new X2();
x2.x = new X1();
when(visitor.visitPlainObject(any())).thenReturn(false);
traversal.accept(x2);
verify(visitor).visitPlainObject(same(x2));
verify(visitor, never()).visitPlainObject(same(x2.x));
}
-
+
@Test
public void testTraverseListExcludeElements() {
- List list = new ArrayList();
+ List list = new ArrayList();
list.add(new X1());
list.add(new X3());
when(visitor.visitList(any(List.class))).thenReturn(false);
@Test
public void testTraverseMapExcludeElements() {
- Map<String,Object> map = new HashMap<String,Object>();
+ Map<String, Object> map = new HashMap<String, Object>();
map.put("x1", new X1());
map.put("x3", new X3());
when(visitor.visitMap(any(Map.class))).thenReturn(false);
@Test
public void testTraverseSetExcludeElements() {
- Set set = new HashSet();
+ Set set = new HashSet();
set.add(new X1());
set.add(new X3());
when(visitor.visitSet(any(Set.class))).thenReturn(false);
@Test
public void testTraverseArrayExcludeElements() {
- Object[] obj = new Object[2];
+ Object[] obj = new Object[2];
obj[0] = new X1();
obj[1] = new X3();
when(visitor.visitArray(any())).thenReturn(false);
}
}
-
- public static class X5 extends X2 {
- private String field;
- private int g;
+
+ public static class X5 extends X2 {
+ private String field;
+ private int g;
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testBasicClass() {
- List<Method> res = ReflectionUtils.getAllMethods(X2.class, Object.class);
+ List<Method> res = ReflectionUtils
+ .getAllMethods(X2.class, Object.class);
assertEquals(2, res.size());
}
@Test
public void testInheritanceAdditionalMethod() {
- List<Method> res = ReflectionUtils.getAllMethods(X3.class, Object.class);
+ List<Method> res = ReflectionUtils
+ .getAllMethods(X3.class, Object.class);
assertEquals(3, res.size());
}
@Test
public void testInheritanceOverriddenMethod() {
- List<Method> res = ReflectionUtils.getAllMethods(X4.class, Object.class);
+ List<Method> res = ReflectionUtils
+ .getAllMethods(X4.class, Object.class);
assertEquals(2, res.size());
for (Method method : res) {
if (method.getName().equals("x")) {
}
}
}
-
+
@Test(expected = IllegalArgumentException.class)
public void testGetAllFieldsInterface() {
ReflectionUtils.getAllFields(X.class);
}
@Test
- public void testFieldsFromBasicClass() {
+ public void testFieldsFromBasicClass() {
List<Field> fields = ReflectionUtils.getAllFields(X2.class);
assertEquals(1, fields.size());
assertEquals("bla", fields.get(0).getName());
}
-
- public void testFieldsWithInheritance() {
+
+ public void testFieldsWithInheritance() {
List<Field> fields = ReflectionUtils.getAllFields(X5.class);
assertEquals(3, fields.size());
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.test;
import java.util.Arrays;
* @author Erik Brakkee
*/
public final class AssertionUtils {
- private static final Logger LOG = Logger.getLogger(AssertionUtils.class.getName());
+ private static final Logger LOG = Logger.getLogger(AssertionUtils.class
+ .getName());
/**
* Disabled constructor.
TestCase.assertEquals("Map sizes differ", aExpectedMap.size(), aActual
.size());
- Set<Entry<Key,Value>> expectedEntries = aExpectedMap.entrySet();
+ Set<Entry<Key, Value>> expectedEntries = aExpectedMap.entrySet();
- for (Entry<Key,Value> entry: expectedEntries) {
+ for (Entry<Key, Value> entry : expectedEntries) {
Key key = entry.getKey();
TestCase.assertTrue("Map does not containg entry for key:" + key,
aActual.containsKey(key));
LOG.info("Expected exception occured " + t.getMessage());
return; // ok
- }
+ }
throw new RuntimeException(t);
}
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.test;
import java.util.ArrayList;
* @author Erik Brakkee
*/
public class EventTracker<Event> {
- private static final Logger LOG = Logger.getLogger(EventTracker.class.getName());
+ private static final Logger LOG = Logger.getLogger(EventTracker.class
+ .getName());
/**
* Map of Thread object to a list of events.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.test;
import junit.framework.TestCase;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
import junit.framework.TestCase;
*/
public void testResolveNonExistingFile() {
try {
- resolver.resolve(
- "org/wamblee/xml/reportToHtml-nonexisting.xsl", "");
+ resolver
+ .resolve("org/wamblee/xml/reportToHtml-nonexisting.xsl", "");
} catch (TransformerException e) {
return; // ok
}
*/
private static final class AttributeComparator implements
Comparator<Attribute>, Serializable {
-
+
private static final long serialVersionUID = 7897287273519886301L;
/*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xml;
import java.io.ByteArrayOutputStream;
XslTransformer transformer = new XslTransformer();
try {
- transformer
- .resolve("org/wamblee/xml/utilities-nonexistent.xsl");
+ transformer.resolve("org/wamblee/xml/utilities-nonexistent.xsl");
} catch (TransformerException e) {
return; // ok
}