Migrate JUnit 3 tests to JUnit 4
This commit migrates all remaining tests from JUnit 3 to JUnit 4, with the exception of Spring's legacy JUnit 3.8 based testing framework that is still in use in the spring-orm module. Issue: SPR-13514
This commit is contained in:
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -27,9 +29,10 @@ import junit.framework.TestCase;
|
||||
* @author Rick Evans
|
||||
* @since 28.04.2003
|
||||
*/
|
||||
public class ConstantsTests extends TestCase {
|
||||
public class ConstantsTests {
|
||||
|
||||
public void testConstants() {
|
||||
@Test
|
||||
public void constants() {
|
||||
Constants c = new Constants(A.class);
|
||||
assertEquals(A.class.getName(), c.getClassName());
|
||||
assertEquals(9, c.getSize());
|
||||
@@ -54,7 +57,8 @@ public class ConstantsTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetNames() {
|
||||
@Test
|
||||
public void getNames() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set<?> names = c.getNames("");
|
||||
@@ -72,7 +76,8 @@ public class ConstantsTests extends TestCase {
|
||||
assertTrue(names.contains("DOG"));
|
||||
}
|
||||
|
||||
public void testGetValues() {
|
||||
@Test
|
||||
public void getValues() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set<?> values = c.getValues("");
|
||||
@@ -96,7 +101,8 @@ public class ConstantsTests extends TestCase {
|
||||
assertTrue(values.contains(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testGetValuesInTurkey() {
|
||||
@Test
|
||||
public void getValuesInTurkey() {
|
||||
Locale oldLocale = Locale.getDefault();
|
||||
Locale.setDefault(new Locale("tr", ""));
|
||||
try {
|
||||
@@ -127,7 +133,8 @@ public class ConstantsTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testSuffixAccess() {
|
||||
@Test
|
||||
public void suffixAccess() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set<?> names = c.getNamesForSuffix("_PROPERTY");
|
||||
@@ -141,7 +148,8 @@ public class ConstantsTests extends TestCase {
|
||||
assertTrue(values.contains(new Integer(4)));
|
||||
}
|
||||
|
||||
public void testToCode() {
|
||||
@Test
|
||||
public void toCode() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
assertEquals(c.toCode(new Integer(0), ""), "DOG");
|
||||
@@ -208,25 +216,29 @@ public class ConstantsTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetValuesWithNullPrefix() throws Exception {
|
||||
@Test
|
||||
public void getValuesWithNullPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<?> values = c.getValues(null);
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testGetValuesWithEmptyStringPrefix() throws Exception {
|
||||
@Test
|
||||
public void getValuesWithEmptyStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<Object> values = c.getValues("");
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testGetValuesWithWhitespacedStringPrefix() throws Exception {
|
||||
@Test
|
||||
public void getValuesWithWhitespacedStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<?> values = c.getValues(" ");
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testWithClassThatExposesNoConstants() throws Exception {
|
||||
@Test
|
||||
public void withClassThatExposesNoConstants() throws Exception {
|
||||
Constants c = new Constants(NoConstants.class);
|
||||
assertEquals(0, c.getSize());
|
||||
final Set<?> values = c.getValues("");
|
||||
@@ -234,7 +246,8 @@ public class ConstantsTests extends TestCase {
|
||||
assertEquals(0, values.size());
|
||||
}
|
||||
|
||||
public void testCtorWithNullClass() throws Exception {
|
||||
@Test
|
||||
public void ctorWithNullClass() throws Exception {
|
||||
try {
|
||||
new Constants(null);
|
||||
fail("Must have thrown IllegalArgumentException");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,58 +17,68 @@
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.tests.sample.objects.TestObject;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ConventionsTests extends TestCase {
|
||||
public class ConventionsTests {
|
||||
|
||||
public void testSimpleObject() {
|
||||
TestObject testObject = new TestObject();
|
||||
assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(testObject));
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void simpleObject() {
|
||||
assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(new TestObject()));
|
||||
}
|
||||
|
||||
public void testArray() {
|
||||
TestObject[] testObjects = new TestObject[0];
|
||||
assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(testObjects));
|
||||
@Test
|
||||
public void array() {
|
||||
assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(new TestObject[0]));
|
||||
}
|
||||
|
||||
public void testCollections() {
|
||||
List<TestObject> list = new ArrayList<TestObject>();
|
||||
list.add(new TestObject());
|
||||
@Test
|
||||
public void list() {
|
||||
List<TestObject> list = Arrays.asList(new TestObject());
|
||||
assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(list));
|
||||
|
||||
Set<TestObject> set = new HashSet<TestObject>();
|
||||
set.add(new TestObject());
|
||||
assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(set));
|
||||
|
||||
List<?> emptyList = new ArrayList<Object>();
|
||||
try {
|
||||
Conventions.getVariableName(emptyList);
|
||||
fail("Should not be able to generate name for empty collection");
|
||||
}
|
||||
catch(IllegalArgumentException ex) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
public void testAttributeNameToPropertyName() throws Exception {
|
||||
@Test
|
||||
public void emptyList() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
Conventions.getVariableName(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void set() {
|
||||
assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(Collections.singleton(new TestObject())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributeNameToPropertyName() throws Exception {
|
||||
assertEquals("transactionManager", Conventions.attributeNameToPropertyName("transaction-manager"));
|
||||
assertEquals("pointcutRef", Conventions.attributeNameToPropertyName("pointcut-ref"));
|
||||
assertEquals("lookupOnStartup", Conventions.attributeNameToPropertyName("lookup-on-startup"));
|
||||
}
|
||||
|
||||
public void testGetQualifiedAttributeName() throws Exception {
|
||||
@Test
|
||||
public void getQualifiedAttributeName() throws Exception {
|
||||
String baseName = "foo";
|
||||
Class<String> cls = String.class;
|
||||
String desiredResult = "java.lang.String.foo";
|
||||
assertEquals(desiredResult, Conventions.getQualifiedAttributeName(cls, baseName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,16 +19,19 @@ package org.springframework.core;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class NestedExceptionTests extends TestCase {
|
||||
@SuppressWarnings("serial")
|
||||
public class NestedExceptionTests {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void testNestedRuntimeExceptionWithNoRootCause() {
|
||||
@Test
|
||||
public void nestedRuntimeExceptionWithNoRootCause() {
|
||||
String mesg = "mesg of mine";
|
||||
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
||||
NestedRuntimeException nex = new NestedRuntimeException(mesg) {};
|
||||
@@ -44,8 +47,8 @@ public class NestedExceptionTests extends TestCase {
|
||||
assertFalse(stackTrace.indexOf(mesg) == -1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void testNestedRuntimeExceptionWithRootCause() {
|
||||
@Test
|
||||
public void nestedRuntimeExceptionWithRootCause() {
|
||||
String myMessage = "mesg for this exception";
|
||||
String rootCauseMesg = "this is the obscure message of the root cause";
|
||||
Exception rootCause = new Exception(rootCauseMesg);
|
||||
@@ -65,8 +68,8 @@ public class NestedExceptionTests extends TestCase {
|
||||
assertFalse(stackTrace.indexOf(rootCauseMesg) == -1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void testNestedCheckedExceptionWithNoRootCause() {
|
||||
@Test
|
||||
public void nestedCheckedExceptionWithNoRootCause() {
|
||||
String mesg = "mesg of mine";
|
||||
// Making a class abstract doesn't _really_ prevent instantiation :-)
|
||||
NestedCheckedException nex = new NestedCheckedException(mesg) {};
|
||||
@@ -82,8 +85,8 @@ public class NestedExceptionTests extends TestCase {
|
||||
assertFalse(stackTrace.indexOf(mesg) == -1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void testNestedCheckedExceptionWithRootCause() {
|
||||
@Test
|
||||
public void nestedCheckedExceptionWithRootCause() {
|
||||
String myMessage = "mesg for this exception";
|
||||
String rootCauseMesg = "this is the obscure message of the root cause";
|
||||
Exception rootCause = new Exception(rootCauseMesg);
|
||||
|
||||
@@ -23,20 +23,24 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ToStringCreatorTests extends TestCase {
|
||||
public class ToStringCreatorTests {
|
||||
|
||||
private SomeObject s1, s2, s3;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
s1 = new SomeObject() {
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -57,7 +61,8 @@ public class ToStringCreatorTests extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
public void testDefaultStyleMap() {
|
||||
@Test
|
||||
public void defaultStyleMap() {
|
||||
final Map map = getMap();
|
||||
Object stringy = new Object() {
|
||||
@Override
|
||||
@@ -78,20 +83,23 @@ public class ToStringCreatorTests extends TestCase {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void testDefaultStyleArray() {
|
||||
@Test
|
||||
public void defaultStyleArray() {
|
||||
SomeObject[] array = new SomeObject[] { s1, s2, s3 };
|
||||
String str = new ToStringCreator(array).toString();
|
||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(array)
|
||||
+ " array<ToStringCreatorTests.SomeObject>[A, B, C]]", str);
|
||||
}
|
||||
|
||||
public void testPrimitiveArrays() {
|
||||
@Test
|
||||
public void primitiveArrays() {
|
||||
int[] integers = new int[] { 0, 1, 2, 3, 4 };
|
||||
String str = new ToStringCreator(integers).toString();
|
||||
assertEquals("[@" + ObjectUtils.getIdentityHexString(integers) + " array<Integer>[0, 1, 2, 3, 4]]", str);
|
||||
}
|
||||
|
||||
public void testList() {
|
||||
@Test
|
||||
public void appendList() {
|
||||
List list = new ArrayList();
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
@@ -101,7 +109,8 @@ public class ToStringCreatorTests extends TestCase {
|
||||
str);
|
||||
}
|
||||
|
||||
public void testSet() {
|
||||
@Test
|
||||
public void appendSet() {
|
||||
Set set = new LinkedHashSet<>(3);
|
||||
set.add(s1);
|
||||
set.add(s2);
|
||||
@@ -111,22 +120,23 @@ public class ToStringCreatorTests extends TestCase {
|
||||
str);
|
||||
}
|
||||
|
||||
public void testClass() {
|
||||
@Test
|
||||
public void appendClass() {
|
||||
String str = new ToStringCreator(this).append("myClass", this.getClass()).toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||
+ " myClass = ToStringCreatorTests]", str);
|
||||
}
|
||||
|
||||
public void testMethod() throws Exception {
|
||||
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("testMethod"))
|
||||
@Test
|
||||
public void appendMethod() throws Exception {
|
||||
String str = new ToStringCreator(this).append("myMethod", this.getClass().getMethod("appendMethod"))
|
||||
.toString();
|
||||
assertEquals("[ToStringCreatorTests@" + ObjectUtils.getIdentityHexString(this)
|
||||
+ " myMethod = testMethod@ToStringCreatorTests]", str);
|
||||
+ " myMethod = appendMethod@ToStringCreatorTests]", str);
|
||||
}
|
||||
|
||||
|
||||
public static class SomeObject {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,42 +18,56 @@ package org.springframework.core.task;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.util.ConcurrencyThrottleSupport;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public final class SimpleAsyncTaskExecutorTests extends TestCase {
|
||||
public final class SimpleAsyncTaskExecutorTests {
|
||||
|
||||
public void testCannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
// TODO Determine why task is executed when concurrency is switched off.
|
||||
@Ignore("Disabled because task is still executed when concurrency is switched off")
|
||||
@Test
|
||||
public void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
||||
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
|
||||
assertFalse(executor.isThrottleActive());
|
||||
try {
|
||||
executor.execute(new NoOpRunnable());
|
||||
}
|
||||
catch (IllegalStateException expected) {
|
||||
}
|
||||
exception.expect(IllegalStateException.class);
|
||||
executor.execute(new NoOpRunnable());
|
||||
}
|
||||
|
||||
public void testThrottleIsNotActiveByDefault() throws Exception {
|
||||
@Test
|
||||
public void throttleIsNotActiveByDefault() throws Exception {
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
|
||||
assertFalse("Concurrency throttle must not default to being active (on)", executor.isThrottleActive());
|
||||
}
|
||||
|
||||
public void testThreadNameGetsSetCorrectly() throws Exception {
|
||||
@Test
|
||||
public void threadNameGetsSetCorrectly() throws Exception {
|
||||
final String customPrefix = "chankPop#";
|
||||
final Object monitor = new Object();
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix);
|
||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||
executeAndWait(executor, task, monitor);
|
||||
assertTrue(task.getThreadName().startsWith(customPrefix));
|
||||
assertThat(task.getThreadName(), startsWith(customPrefix));
|
||||
}
|
||||
|
||||
public void testThreadFactoryOverridesDefaults() throws Exception {
|
||||
@Test
|
||||
public void threadFactoryOverridesDefaults() throws Exception {
|
||||
final Object monitor = new Object();
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
@@ -63,16 +77,13 @@ public final class SimpleAsyncTaskExecutorTests extends TestCase {
|
||||
});
|
||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||
executeAndWait(executor, task, monitor);
|
||||
assertTrue(task.getThreadName().equals("test"));
|
||||
assertEquals("test", task.getThreadName());
|
||||
}
|
||||
|
||||
public void testThrowsExceptionWhenSuppliedWithNullRunnable() throws Exception {
|
||||
try {
|
||||
new SimpleAsyncTaskExecutor().execute(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
@Test
|
||||
public void throwsExceptionWhenSuppliedWithNullRunnable() throws Exception {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new SimpleAsyncTaskExecutor().execute(null);
|
||||
}
|
||||
|
||||
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
@@ -24,12 +24,15 @@ import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AspectJTypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
*/
|
||||
public class AspectJTypeFilterTests extends TestCase {
|
||||
public class AspectJTypeFilterTests {
|
||||
|
||||
public void testNamePatternMatches() throws Exception {
|
||||
@Test
|
||||
public void namePatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
@@ -40,12 +43,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||
"org..SomeClass");
|
||||
}
|
||||
|
||||
public void testNamePatternNoMatches() throws Exception {
|
||||
@Test
|
||||
public void namePatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClassX");
|
||||
}
|
||||
|
||||
public void testSubclassPatternMatches() throws Exception {
|
||||
@Test
|
||||
public void subclassPatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
@@ -72,12 +77,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||
"java.lang.Object+");
|
||||
}
|
||||
|
||||
public void testSubclassPatternNoMatches() throws Exception {
|
||||
@Test
|
||||
public void subclassPatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"java.lang.String+");
|
||||
}
|
||||
|
||||
public void testAnnotationPatternMatches() throws Exception {
|
||||
@Test
|
||||
public void annotationPatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *..*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
@@ -92,12 +99,14 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||
"@org.springframework.stereotype.Component *");
|
||||
}
|
||||
|
||||
public void testAnnotationPatternNoMathces() throws Exception {
|
||||
@Test
|
||||
public void annotationPatternNoMathces() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Repository *..*");
|
||||
}
|
||||
|
||||
public void testCompositionPatternMatches() throws Exception {
|
||||
@Test
|
||||
public void compositionPatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"!*..SomeOtherClass");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
@@ -110,7 +119,8 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||
"|| org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
||||
}
|
||||
|
||||
public void testCompositionPatternNoMatches() throws Exception {
|
||||
@Test
|
||||
public void compositionPatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"*..Bogus && org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||
}
|
||||
@@ -136,27 +146,22 @@ public class AspectJTypeFilterTests extends TestCase {
|
||||
|
||||
// We must use a standalone set of types to ensure that no one else is loading them
|
||||
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
|
||||
static interface SomeInterface {
|
||||
interface SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClass {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassExtendingSomeClass extends SomeClass {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassImplementingSomeInterface implements SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface
|
||||
extends SomeClassExtendingSomeClass implements SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class SomeClassAnnotatedWithComponent {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,20 +16,23 @@
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AssignableTypeFilterTests extends TestCase {
|
||||
public class AssignableTypeFilterTests {
|
||||
|
||||
public void testDirectMatch() throws Exception {
|
||||
@Test
|
||||
public void directMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
@@ -40,7 +43,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||
assertTrue(matchingFilter.match(metadataReader, metadataReaderFactory));
|
||||
}
|
||||
|
||||
public void testInterfaceMatch() throws Exception {
|
||||
@Test
|
||||
public void interfaceMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestInterfaceImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
@@ -50,7 +54,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testSuperClassMatch() throws Exception {
|
||||
@Test
|
||||
public void superClassMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
@@ -60,7 +65,8 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testInterfaceThroughSuperClassMatch() throws Exception {
|
||||
@Test
|
||||
public void interfaceThroughSuperClassMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
@@ -76,30 +82,24 @@ public class AssignableTypeFilterTests extends TestCase {
|
||||
private static class TestNonInheritingClass {
|
||||
}
|
||||
|
||||
|
||||
private static interface TestInterface {
|
||||
private interface TestInterface {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestInterfaceImpl implements TestInterface {
|
||||
}
|
||||
|
||||
|
||||
private static interface SomeDaoLikeInterface {
|
||||
private interface SomeDaoLikeInterface {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class SomeDaoLikeImpl extends SimpleJdbcDaoSupport implements SomeDaoLikeInterface {
|
||||
}
|
||||
|
||||
private static interface JdbcDaoSupport {
|
||||
|
||||
private interface JdbcDaoSupport {
|
||||
}
|
||||
|
||||
private static class SimpleJdbcDaoSupport implements JdbcDaoSupport {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,9 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the FileCopyUtils class.
|
||||
@@ -31,9 +33,10 @@ import junit.framework.TestCase;
|
||||
* @author Juergen Hoeller
|
||||
* @since 12.03.2005
|
||||
*/
|
||||
public class FileCopyUtilsTests extends TestCase {
|
||||
public class FileCopyUtilsTests {
|
||||
|
||||
public void testCopyFromInputStream() throws IOException {
|
||||
@Test
|
||||
public void copyFromInputStream() throws IOException {
|
||||
byte[] content = "content".getBytes();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
||||
@@ -42,21 +45,24 @@ public class FileCopyUtilsTests extends TestCase {
|
||||
assertTrue(Arrays.equals(content, out.toByteArray()));
|
||||
}
|
||||
|
||||
public void testCopyFromByteArray() throws IOException {
|
||||
@Test
|
||||
public void copyFromByteArray() throws IOException {
|
||||
byte[] content = "content".getBytes();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
|
||||
FileCopyUtils.copy(content, out);
|
||||
assertTrue(Arrays.equals(content, out.toByteArray()));
|
||||
}
|
||||
|
||||
public void testCopyToByteArray() throws IOException {
|
||||
@Test
|
||||
public void copyToByteArray() throws IOException {
|
||||
byte[] content = "content".getBytes();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(content);
|
||||
byte[] result = FileCopyUtils.copyToByteArray(in);
|
||||
assertTrue(Arrays.equals(content, result));
|
||||
}
|
||||
|
||||
public void testCopyFromReader() throws IOException {
|
||||
@Test
|
||||
public void copyFromReader() throws IOException {
|
||||
String content = "content";
|
||||
StringReader in = new StringReader(content);
|
||||
StringWriter out = new StringWriter();
|
||||
@@ -65,14 +71,16 @@ public class FileCopyUtilsTests extends TestCase {
|
||||
assertEquals(content, out.toString());
|
||||
}
|
||||
|
||||
public void testCopyFromString() throws IOException {
|
||||
@Test
|
||||
public void copyFromString() throws IOException {
|
||||
String content = "content";
|
||||
StringWriter out = new StringWriter();
|
||||
FileCopyUtils.copy(content, out);
|
||||
assertEquals(content, out.toString());
|
||||
}
|
||||
|
||||
public void testCopyToString() throws IOException {
|
||||
@Test
|
||||
public void copyToString() throws IOException {
|
||||
String content = "content";
|
||||
StringReader in = new StringReader(content);
|
||||
String result = FileCopyUtils.copyToString(in);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,14 +18,18 @@ package org.springframework.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class FileSystemUtilsTests extends TestCase {
|
||||
public class FileSystemUtilsTests {
|
||||
|
||||
public void testDeleteRecursively() throws Exception {
|
||||
@Test
|
||||
public void deleteRecursively() throws Exception {
|
||||
File root = new File("./tmp/root");
|
||||
File child = new File(root, "child");
|
||||
File grandchild = new File(child, "grandchild");
|
||||
@@ -48,7 +52,8 @@ public class FileSystemUtilsTests extends TestCase {
|
||||
assertFalse(bar.exists());
|
||||
}
|
||||
|
||||
public void testCopyRecursively() throws Exception {
|
||||
@Test
|
||||
public void copyRecursively() throws Exception {
|
||||
File src = new File("./tmp/src");
|
||||
File child = new File(src, "child");
|
||||
File grandchild = new File(child, "grandchild");
|
||||
@@ -70,11 +75,12 @@ public class FileSystemUtilsTests extends TestCase {
|
||||
assertTrue(new File(dest, child.getName()).exists());
|
||||
|
||||
FileSystemUtils.deleteRecursively(src);
|
||||
assertTrue(!src.exists());
|
||||
assertFalse(src.exists());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
File tmp = new File("./tmp");
|
||||
if (tmp.exists()) {
|
||||
FileSystemUtils.deleteRecursively(tmp);
|
||||
@@ -83,7 +89,6 @@ public class FileSystemUtilsTests extends TestCase {
|
||||
if (dest.exists()) {
|
||||
FileSystemUtils.deleteRecursively(dest);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,16 +20,26 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Colin Sampaleanu
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 21.11.2003
|
||||
*/
|
||||
public class MethodInvokerTests extends TestCase {
|
||||
public class MethodInvokerTests {
|
||||
|
||||
public void testPlainMethodInvoker() throws Exception {
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void plainMethodInvoker() throws Exception {
|
||||
// sanity check: singleton, non-static should work
|
||||
TestClass1 tc1 = new TestClass1();
|
||||
MethodInvoker mi = new MethodInvoker();
|
||||
@@ -59,30 +69,24 @@ public class MethodInvokerTests extends TestCase {
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes2");
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
|
||||
try {
|
||||
mi.prepare();
|
||||
fail("Shouldn't have matched without argument conversion");
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
exception.expect(NoSuchMethodException.class);
|
||||
mi.prepare();
|
||||
}
|
||||
|
||||
public void testStringWithMethodInvoker() throws Exception {
|
||||
try {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
methodInvoker.setArguments(new Object[] {new String("no match")});
|
||||
methodInvoker.prepare();
|
||||
fail("Should have thrown a NoSuchMethodException");
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
// expected
|
||||
}
|
||||
@Test
|
||||
public void stringWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
methodInvoker.setArguments(new Object[] { new String("no match") });
|
||||
|
||||
exception.expect(NoSuchMethodException.class);
|
||||
methodInvoker.prepare();
|
||||
}
|
||||
|
||||
public void testPurchaserWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void purchaserWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -92,7 +96,8 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals("purchaser: hello", greeting);
|
||||
}
|
||||
|
||||
public void testShopperWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void shopperWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -102,7 +107,8 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals("purchaser: may I help you?", greeting);
|
||||
}
|
||||
|
||||
public void testSalesmanWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void salesmanWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -112,7 +118,8 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals("greetable: how are sales?", greeting);
|
||||
}
|
||||
|
||||
public void testCustomerWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void customerWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -122,7 +129,8 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals("customer: good day", greeting);
|
||||
}
|
||||
|
||||
public void testRegularWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void regularWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -132,7 +140,8 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals("regular: welcome back Kotter", greeting);
|
||||
}
|
||||
|
||||
public void testVIPWithMethodInvoker() throws Exception {
|
||||
@Test
|
||||
public void vipWithMethodInvoker() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetObject(new Greeter());
|
||||
methodInvoker.setTargetMethod("greet");
|
||||
@@ -190,7 +199,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Greeter {
|
||||
|
||||
@@ -215,17 +223,13 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static interface Greetable {
|
||||
|
||||
private interface Greetable {
|
||||
String getGreeting();
|
||||
}
|
||||
|
||||
|
||||
private static interface Person extends Greetable {
|
||||
private interface Person extends Greetable {
|
||||
}
|
||||
|
||||
|
||||
private static class Purchaser implements Greetable {
|
||||
|
||||
@Override
|
||||
@@ -234,7 +238,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Shopper extends Purchaser implements Person {
|
||||
|
||||
@Override
|
||||
@@ -243,7 +246,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Salesman implements Person {
|
||||
|
||||
@Override
|
||||
@@ -252,7 +254,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Customer extends Shopper {
|
||||
|
||||
@Override
|
||||
@@ -261,7 +262,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Regular extends Customer {
|
||||
|
||||
private String name;
|
||||
@@ -276,7 +276,6 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class VIP extends Regular {
|
||||
|
||||
public VIP(String name) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,64 +23,74 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 11.01.2005
|
||||
*/
|
||||
public class PropertiesPersisterTests extends TestCase {
|
||||
public class PropertiesPersisterTests {
|
||||
|
||||
public void testPropertiesPersister() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersister() throws IOException {
|
||||
String propString = "code1=message1\ncode2:message2";
|
||||
Properties props = loadProperties(propString, false);
|
||||
String propCopy = storeProperties(props, null, false);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithWhitespace() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithWhitespace() throws IOException {
|
||||
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
||||
Properties props = loadProperties(propString, false);
|
||||
String propCopy = storeProperties(props, null, false);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithHeader() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithHeader() throws IOException {
|
||||
String propString = "code1=message1\ncode2:message2";
|
||||
Properties props = loadProperties(propString, false);
|
||||
String propCopy = storeProperties(props, "myHeader", false);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithEmptyValue() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithEmptyValue() throws IOException {
|
||||
String propString = "code1=message1\ncode2:message2\ncode3=";
|
||||
Properties props = loadProperties(propString, false);
|
||||
String propCopy = storeProperties(props, null, false);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithReader() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithReader() throws IOException {
|
||||
String propString = "code1=message1\ncode2:message2";
|
||||
Properties props = loadProperties(propString, true);
|
||||
String propCopy = storeProperties(props, null, true);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithReaderAndWhitespace() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithReaderAndWhitespace() throws IOException {
|
||||
String propString = " code1\t= \tmessage1\n code2 \t :\t mess\\\n \t age2";
|
||||
Properties props = loadProperties(propString, true);
|
||||
String propCopy = storeProperties(props, null, true);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithReaderAndHeader() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithReaderAndHeader() throws IOException {
|
||||
String propString = "code1\t=\tmessage1\n code2 \t : \t message2";
|
||||
Properties props = loadProperties(propString, true);
|
||||
String propCopy = storeProperties(props, "myHeader", true);
|
||||
loadProperties(propCopy, false);
|
||||
}
|
||||
|
||||
public void testPropertiesPersisterWithReaderAndEmptyValue() throws IOException {
|
||||
@Test
|
||||
public void propertiesPersisterWithReaderAndEmptyValue() throws IOException {
|
||||
String propString = "code1=message1\ncode2:message2\ncode3=";
|
||||
Properties props = loadProperties(propString, true);
|
||||
String propCopy = storeProperties(props, null, true);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,14 +21,17 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ResourceUtilsTests extends TestCase {
|
||||
public class ResourceUtilsTests {
|
||||
|
||||
public void testIsJarURL() throws Exception {
|
||||
@Test
|
||||
public void isJarURL() throws Exception {
|
||||
assertTrue(ResourceUtils.isJarURL(new URL("jar:file:myjar.jar!/mypath")));
|
||||
assertTrue(ResourceUtils.isJarURL(new URL(null, "zip:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
||||
assertTrue(ResourceUtils.isJarURL(new URL(null, "wsjar:file:myjar.jar!/mypath", new DummyURLStreamHandler())));
|
||||
@@ -36,7 +39,8 @@ public class ResourceUtilsTests extends TestCase {
|
||||
assertFalse(ResourceUtils.isJarURL(new URL("http:myserver/myjar.jar")));
|
||||
}
|
||||
|
||||
public void testExtractJarFileURL() throws Exception {
|
||||
@Test
|
||||
public void extractJarFileURL() throws Exception {
|
||||
assertEquals(new URL("file:myjar.jar"),
|
||||
ResourceUtils.extractJarFileURL(new URL("jar:file:myjar.jar!/mypath")));
|
||||
assertEquals(new URL("file:/myjar.jar"),
|
||||
|
||||
@@ -16,18 +16,26 @@
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class StopWatchTests extends TestCase {
|
||||
public class StopWatchTests {
|
||||
|
||||
/**
|
||||
* Are timings off in JUnit?
|
||||
*/
|
||||
public void testValidUsage() throws Exception {
|
||||
private final StopWatch sw = new StopWatch();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void validUsage() throws Exception {
|
||||
String id = "myId";
|
||||
StopWatch sw = new StopWatch(id);
|
||||
long int1 = 166L;
|
||||
@@ -45,14 +53,18 @@ public class StopWatchTests extends TestCase {
|
||||
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
||||
// under both Ant and Eclipse?
|
||||
|
||||
//long fudgeFactor = 5L;
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1);
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + fudgeFactor);
|
||||
// long fudgeFactor = 5L;
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >=
|
||||
// int1);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||
// + fudgeFactor);
|
||||
sw.start(name2);
|
||||
Thread.sleep(int2);
|
||||
sw.stop();
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1 + int2);
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + int2 + fudgeFactor);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1
|
||||
// + int2);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||
// + int2 + fudgeFactor);
|
||||
|
||||
assertTrue(sw.getTaskCount() == 2);
|
||||
String pp = sw.prettyPrint();
|
||||
@@ -72,8 +84,8 @@ public class StopWatchTests extends TestCase {
|
||||
assertEquals(id, sw.getId());
|
||||
}
|
||||
|
||||
public void testValidUsageNotKeepingTaskList() throws Exception {
|
||||
StopWatch sw = new StopWatch();
|
||||
@Test
|
||||
public void validUsageNotKeepingTaskList() throws Exception {
|
||||
sw.setKeepTaskList(false);
|
||||
long int1 = 166L;
|
||||
long int2 = 45L;
|
||||
@@ -89,14 +101,18 @@ public class StopWatchTests extends TestCase {
|
||||
// TODO are timings off in JUnit? Why do these assertions sometimes fail
|
||||
// under both Ant and Eclipse?
|
||||
|
||||
//long fudgeFactor = 5L;
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1);
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + fudgeFactor);
|
||||
// long fudgeFactor = 5L;
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >=
|
||||
// int1);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||
// + fudgeFactor);
|
||||
sw.start(name2);
|
||||
Thread.sleep(int2);
|
||||
sw.stop();
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1 + int2);
|
||||
//assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1 + int2 + fudgeFactor);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() >= int1
|
||||
// + int2);
|
||||
// assertTrue("Unexpected timing " + sw.getTotalTime(), sw.getTotalTime() <= int1
|
||||
// + int2 + fudgeFactor);
|
||||
|
||||
assertTrue(sw.getTaskCount() == 2);
|
||||
String pp = sw.prettyPrint();
|
||||
@@ -106,50 +122,30 @@ public class StopWatchTests extends TestCase {
|
||||
assertFalse(toString.contains(name1));
|
||||
assertFalse(toString.contains(name2));
|
||||
|
||||
try {
|
||||
sw.getTaskInfo();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Ok
|
||||
}
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
sw.getTaskInfo();
|
||||
}
|
||||
|
||||
public void testFailureToStartBeforeGettingTimings() {
|
||||
StopWatch sw = new StopWatch();
|
||||
try {
|
||||
sw.getLastTaskTimeMillis();
|
||||
fail("Can't get last interval if no tests run");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ok
|
||||
}
|
||||
@Test
|
||||
public void failureToStartBeforeGettingTimings() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
public void testFailureToStartBeforeStop() {
|
||||
StopWatch sw = new StopWatch();
|
||||
try {
|
||||
sw.stop();
|
||||
fail("Can't stop without starting");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ok
|
||||
}
|
||||
@Test
|
||||
public void failureToStartBeforeStop() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
sw.stop();
|
||||
}
|
||||
|
||||
public void testRejectsStartTwice() {
|
||||
StopWatch sw = new StopWatch();
|
||||
try {
|
||||
sw.start("");
|
||||
sw.stop();
|
||||
sw.start("");
|
||||
assertTrue(sw.isRunning());
|
||||
sw.start("");
|
||||
fail("Can't start twice");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ok
|
||||
}
|
||||
@Test
|
||||
public void rejectsStartTwice() {
|
||||
sw.start("");
|
||||
sw.stop();
|
||||
sw.start("");
|
||||
assertTrue(sw.isRunning());
|
||||
exception.expect(IllegalStateException.class);
|
||||
sw.start("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.util.xml;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.transform.Transformer;
|
||||
@@ -27,8 +28,15 @@ import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.MockitoUtils;
|
||||
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
@@ -39,11 +47,6 @@ import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.MockitoUtils;
|
||||
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,15 +18,19 @@ package org.springframework.util.xml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||
|
||||
@@ -37,7 +41,8 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||
return new StaxEventXMLReader(inputFactory.createXMLEventReader(inputStream));
|
||||
}
|
||||
|
||||
public void testPartial() throws Exception {
|
||||
@Test
|
||||
public void partial() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
|
||||
eventReader.nextTag(); // skip to root
|
||||
@@ -46,7 +51,7 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||
xmlReader.setContentHandler(contentHandler);
|
||||
xmlReader.parse(new InputSource());
|
||||
verify(contentHandler).startDocument();
|
||||
verify(contentHandler).startElement("http://springframework.org/spring-ws", "child", "child", new AttributesImpl());
|
||||
verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
|
||||
verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
|
||||
verify(contentHandler).endDocument();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,19 +18,22 @@ package org.springframework.util.xml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||
|
||||
@@ -42,7 +45,7 @@ public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartial() throws Exception {
|
||||
public void partial() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
|
||||
streamReader.nextTag(); // skip to root
|
||||
|
||||
Reference in New Issue
Block a user