mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 03:25:28 -04:00
Major test-case cleanup.
- Removed JMock dependency, tests rewritten to use Mockito for stub/mock - All test should now be using JUnit annotation-style tests - All modules should now depend on same JUnit version - Rewrote a few tests to better utilize JUnit annotations - Fixed a few broken tests - Code style changes
This commit is contained in:
parent
52a97cfb2f
commit
0c4fc454b9
@ -20,20 +20,20 @@ import java.util.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link java.util.Map} methods and contracts.
|
* Abstract test class for {@link java.util.Map} methods and contracts.
|
||||||
* <p>
|
* <p/>
|
||||||
* The forces at work here are similar to those in {@link CollectionAbstractTestCase}.
|
* The forces at work here are similar to those in {@link CollectionAbstractTestCase}.
|
||||||
* If your class implements the full Map interface, including optional
|
* If your class implements the full Map interface, including optional
|
||||||
* operations, simply extend this class, and implement the
|
* operations, simply extend this class, and implement the
|
||||||
* {@link #makeEmptyMap()} method.
|
* {@link #makeEmptyMap()} method.
|
||||||
* <p>
|
* <p/>
|
||||||
* On the other hand, if your map implementation is weird, you may have to
|
* On the other hand, if your map implementation is weird, you may have to
|
||||||
* override one or more of the other protected methods. They're described
|
* override one or more of the other protected methods. They're described
|
||||||
* below.
|
* below.
|
||||||
* <p>
|
* <p/>
|
||||||
* <b>Entry Population Methods</b>
|
* <b>Entry Population Methods</b>
|
||||||
* <p>
|
* <p/>
|
||||||
* Override these methods if your map requires special entries:
|
* Override these methods if your map requires special entries:
|
||||||
*
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #getSampleKeys()}
|
* <li>{@link #getSampleKeys()}
|
||||||
* <li>{@link #getSampleValues()}
|
* <li>{@link #getSampleValues()}
|
||||||
@ -41,11 +41,11 @@ import java.util.*;
|
|||||||
* <li>{@link #getOtherKeys()}
|
* <li>{@link #getOtherKeys()}
|
||||||
* <li>{@link #getOtherValues()}
|
* <li>{@link #getOtherValues()}
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
* <p/>
|
||||||
* <b>Supported Operation Methods</b>
|
* <b>Supported Operation Methods</b>
|
||||||
* <p>
|
* <p/>
|
||||||
* Override these methods if your map doesn't support certain operations:
|
* Override these methods if your map doesn't support certain operations:
|
||||||
*
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> {@link #isPutAddSupported()}
|
* <li> {@link #isPutAddSupported()}
|
||||||
* <li> {@link #isPutChangeSupported()}
|
* <li> {@link #isPutChangeSupported()}
|
||||||
@ -56,9 +56,9 @@ import java.util.*;
|
|||||||
* <li> {@link #isAllowNullKey()}
|
* <li> {@link #isAllowNullKey()}
|
||||||
* <li> {@link #isAllowNullValue()}
|
* <li> {@link #isAllowNullValue()}
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
* <p/>
|
||||||
* <b>Fixture Methods</b>
|
* <b>Fixture Methods</b>
|
||||||
* <p>
|
* <p/>
|
||||||
* For tests on modification operations (puts and removes), fixtures are used
|
* For tests on modification operations (puts and removes), fixtures are used
|
||||||
* to verify that that operation results in correct state for the map and its
|
* to verify that that operation results in correct state for the map and its
|
||||||
* collection views. Basically, the modification is performed against your
|
* collection views. Basically, the modification is performed against your
|
||||||
@ -69,20 +69,20 @@ import java.util.*;
|
|||||||
* on both your map implementation and the confirmed map implementation, the
|
* on both your map implementation and the confirmed map implementation, the
|
||||||
* two maps are compared to see if their state is identical. The comparison
|
* two maps are compared to see if their state is identical. The comparison
|
||||||
* also compares the collection views to make sure they're still the same.<P>
|
* also compares the collection views to make sure they're still the same.<P>
|
||||||
*
|
* <p/>
|
||||||
* The upshot of all that is that <I>any</I> test that modifies the map in
|
* The upshot of all that is that <I>any</I> test that modifies the map in
|
||||||
* <I>any</I> way will verify that <I>all</I> of the map's state is still
|
* <I>any</I> way will verify that <I>all</I> of the map's state is still
|
||||||
* correct, including the state of its collection views. So for instance
|
* correct, including the state of its collection views. So for instance
|
||||||
* if a key is removed by the map's key set's iterator, then the entry set
|
* if a key is removed by the map's key set's iterator, then the entry set
|
||||||
* is checked to make sure the key/value pair no longer appears.<P>
|
* is checked to make sure the key/value pair no longer appears.<P>
|
||||||
*
|
* <p/>
|
||||||
* The {@link #map} field holds an instance of your collection implementation.
|
* The {@link #map} field holds an instance of your collection implementation.
|
||||||
* The {@link #entrySet}, {@link #keySet} and {@link #values} fields hold
|
* The {@link #entrySet}, {@link #keySet} and {@link #values} fields hold
|
||||||
* that map's collection views. And the {@link #confirmed} field holds
|
* that map's collection views. And the {@link #confirmed} field holds
|
||||||
* an instance of the confirmed collection implementation. The
|
* an instance of the confirmed collection implementation. The
|
||||||
* {@link #resetEmpty()} and {@link #resetFull()} methods set these fields to
|
* {@link #resetEmpty()} and {@link #resetFull()} methods set these fields to
|
||||||
* empty or full maps, so that tests can proceed from a known state.<P>
|
* empty or full maps, so that tests can proceed from a known state.<P>
|
||||||
*
|
* <p/>
|
||||||
* After a modification operation to both {@link #map} and {@link #confirmed},
|
* After a modification operation to both {@link #map} and {@link #confirmed},
|
||||||
* the {@link #verifyAll()} method is invoked to compare the results. The
|
* the {@link #verifyAll()} method is invoked to compare the results. The
|
||||||
* {@link # verify0} method calls separate methods to verify the map and its three
|
* {@link # verify0} method calls separate methods to verify the map and its three
|
||||||
@ -92,9 +92,9 @@ import java.util.*;
|
|||||||
* instance, TestDoubleOrderedMap would want override its
|
* instance, TestDoubleOrderedMap would want override its
|
||||||
* {@link #verifyValues()} method to verify that the values are unique and in
|
* {@link #verifyValues()} method to verify that the values are unique and in
|
||||||
* ascending order.<P>
|
* ascending order.<P>
|
||||||
*
|
* <p/>
|
||||||
* <b>Other Notes</b>
|
* <b>Other Notes</b>
|
||||||
* <p>
|
* <p/>
|
||||||
* If your {@link Map} fails one of these tests by design, you may still use
|
* If your {@link Map} fails one of these tests by design, you may still use
|
||||||
* this base set of cases. Simply override the test case (method) your map
|
* this base set of cases. Simply override the test case (method) your map
|
||||||
* fails and/or the methods that define the assumptions used by the test
|
* fails and/or the methods that define the assumptions used by the test
|
||||||
@ -153,7 +153,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* support the {@code put} and {@code putAll} operations
|
* support the {@code put} and {@code putAll} operations
|
||||||
* adding new mappings.
|
* adding new mappings.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support put adding.
|
* Override if your collection class does not support put adding.
|
||||||
*/
|
*/
|
||||||
@ -166,7 +166,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* support the {@code put} and {@code putAll} operations
|
* support the {@code put} and {@code putAll} operations
|
||||||
* changing existing mappings.
|
* changing existing mappings.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support put changing.
|
* Override if your collection class does not support put changing.
|
||||||
*/
|
*/
|
||||||
@ -178,7 +178,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* support the {@code setValue} operation on entrySet entries.
|
* support the {@code setValue} operation on entrySet entries.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns isPutChangeSupported().
|
* Default implementation returns isPutChangeSupported().
|
||||||
* Override if your collection class does not support setValue but does
|
* Override if your collection class does not support setValue but does
|
||||||
* support put changing.
|
* support put changing.
|
||||||
@ -191,7 +191,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* support the {@code remove} and {@code clear} operations.
|
* support the {@code remove} and {@code clear} operations.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support removal operations.
|
* Override if your collection class does not support removal operations.
|
||||||
*/
|
*/
|
||||||
@ -203,7 +203,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* can cause structural modification on a get(). The example is LRUMap.
|
* can cause structural modification on a get(). The example is LRUMap.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns false.
|
* Default implementation returns false.
|
||||||
* Override if your map class structurally modifies on get.
|
* Override if your map class structurally modifies on get.
|
||||||
*/
|
*/
|
||||||
@ -226,7 +226,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* supports null keys.
|
* supports null keys.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support null keys.
|
* Override if your collection class does not support null keys.
|
||||||
*/
|
*/
|
||||||
@ -238,7 +238,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* supports null values.
|
* supports null values.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support null values.
|
* Override if your collection class does not support null values.
|
||||||
*/
|
*/
|
||||||
@ -250,7 +250,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* Returns true if the maps produced by
|
* Returns true if the maps produced by
|
||||||
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
* {@link #makeEmptyMap()} and {@link #makeFullMap()}
|
||||||
* supports duplicate values.
|
* supports duplicate values.
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns true.
|
* Default implementation returns true.
|
||||||
* Override if your collection class does not support duplicate values.
|
* Override if your collection class does not support duplicate values.
|
||||||
*/
|
*/
|
||||||
@ -276,7 +276,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object[] getOtherKeys() {
|
public Object[] getOtherKeys() {
|
||||||
return getOtherNonNullStringElements();
|
return getOtherNonNullStringElements();
|
||||||
}
|
}
|
||||||
@ -288,7 +287,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
/**
|
/**
|
||||||
* Returns a list of string elements suitable for return by
|
* Returns a list of string elements suitable for return by
|
||||||
* {@link #getOtherKeys()} or {@link #getOtherValues}.
|
* {@link #getOtherKeys()} or {@link #getOtherValues}.
|
||||||
*
|
* <p/>
|
||||||
* <p>Override getOtherElements to returnthe results of this method if your
|
* <p>Override getOtherElements to returnthe results of this method if your
|
||||||
* collection does not support heterogenous elements or the null element.
|
* collection does not support heterogenous elements or the null element.
|
||||||
* </p>
|
* </p>
|
||||||
@ -355,27 +354,25 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
try {
|
try {
|
||||||
m.put(keys[i], values[i]);
|
m.put(keys[i], values[i]);
|
||||||
} catch (NullPointerException exception) {
|
}
|
||||||
assertTrue("NullPointerException only allowed to be thrown " +
|
catch (NullPointerException exception) {
|
||||||
"if either the key or value is null.",
|
assertTrue("NullPointerException only allowed to be thrown if either the key or value is null.",
|
||||||
keys[i] == null || values[i] == null);
|
keys[i] == null || values[i] == null);
|
||||||
|
|
||||||
assertTrue("NullPointerException on null key, but " +
|
assertTrue("NullPointerException on null key, but isAllowNullKey is not overridden to return false.",
|
||||||
"isAllowNullKey is not overridden to return false.",
|
|
||||||
keys[i] == null || !isAllowNullKey());
|
keys[i] == null || !isAllowNullKey());
|
||||||
|
|
||||||
assertTrue("NullPointerException on null value, but " +
|
assertTrue("NullPointerException on null value, but isAllowNullValue is not overridden to return false.",
|
||||||
"isAllowNullValue is not overridden to return false.",
|
|
||||||
values[i] == null || !isAllowNullValue());
|
values[i] == null || !isAllowNullValue());
|
||||||
|
|
||||||
assertTrue("Unknown reason for NullPointer.", false);
|
assertTrue("Unknown reason for NullPointer.", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("size must reflect number of mappings added.",
|
assertEquals("size must reflect number of mappings added.", keys.length, m.size());
|
||||||
keys.length, m.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new, empty {@link Map} to be used for testing.
|
* Return a new, empty {@link Map} to be used for testing.
|
||||||
*
|
*
|
||||||
@ -431,7 +428,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
public String getCompatibilityVersion() {
|
public String getCompatibilityVersion() {
|
||||||
return super.getCompatibilityVersion();
|
return super.getCompatibilityVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to ensure the test setup is working properly. This method checks
|
* Test to ensure the test setup is working properly. This method checks
|
||||||
* to ensure that the getSampleKeys and getSampleValues methods are
|
* to ensure that the getSampleKeys and getSampleValues methods are
|
||||||
@ -447,40 +446,27 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Object[] values = getSampleValues();
|
Object[] values = getSampleValues();
|
||||||
Object[] newValues = getNewSampleValues();
|
Object[] newValues = getNewSampleValues();
|
||||||
|
|
||||||
assertTrue("failure in test: Must have keys returned from " +
|
assertTrue("failure in test: Must have keys returned from getSampleKeys.", keys != null);
|
||||||
"getSampleKeys.", keys != null);
|
assertTrue("failure in test: Must have values returned from getSampleValues.", values != null);
|
||||||
|
|
||||||
assertTrue("failure in test: Must have values returned from " +
|
|
||||||
"getSampleValues.", values != null);
|
|
||||||
|
|
||||||
// verify keys and values have equivalent lengths (in case getSampleX are
|
// verify keys and values have equivalent lengths (in case getSampleX are
|
||||||
// overridden)
|
// overridden)
|
||||||
assertEquals("failure in test: not the same number of sample " +
|
assertEquals("failure in test: not the same number of sample keys and values.", keys.length, values.length);
|
||||||
"keys and values.", keys.length, values.length);
|
assertEquals("failure in test: not the same number of values and new values.", values.length, newValues.length);
|
||||||
|
|
||||||
|
|
||||||
assertEquals("failure in test: not the same number of values and new values.",
|
|
||||||
values.length, newValues.length);
|
|
||||||
|
|
||||||
// verify there aren't duplicate keys, and check values
|
// verify there aren't duplicate keys, and check values
|
||||||
for (int i = 0; i < keys.length - 1; i++) {
|
for (int i = 0; i < keys.length - 1; i++) {
|
||||||
for (int j = i + 1; j < keys.length; j++) {
|
for (int j = i + 1; j < keys.length; j++) {
|
||||||
assertTrue("failure in test: duplicate null keys.",
|
assertTrue("failure in test: duplicate null keys.", (keys[i] != null || keys[j] != null));
|
||||||
(keys[i] != null || keys[j] != null));
|
|
||||||
assertTrue("failure in test: duplicate non-null key.",
|
assertTrue("failure in test: duplicate non-null key.",
|
||||||
(keys[i] == null || keys[j] == null ||
|
(keys[i] == null || keys[j] == null || (!keys[i].equals(keys[j]) && !keys[j].equals(keys[i]))));
|
||||||
(!keys[i].equals(keys[j]) &&
|
|
||||||
!keys[j].equals(keys[i]))));
|
|
||||||
}
|
}
|
||||||
assertTrue("failure in test: found null key, but isNullKeySupported " +
|
|
||||||
"is false.", keys[i] != null || isAllowNullKey());
|
assertTrue("failure in test: found null key, but isNullKeySupported is false.", keys[i] != null || isAllowNullKey());
|
||||||
assertTrue("failure in test: found null value, but isNullValueSupported " +
|
assertTrue("failure in test: found null value, but isNullValueSupported is false.", values[i] != null || isAllowNullValue());
|
||||||
"is false.", values[i] != null || isAllowNullValue());
|
assertTrue("failure in test: found null new value, but isNullValueSupported is false.", newValues[i] != null || isAllowNullValue());
|
||||||
assertTrue("failure in test: found null new value, but isNullValueSupported " +
|
|
||||||
"is false.", newValues[i] != null || isAllowNullValue());
|
|
||||||
assertTrue("failure in test: values should not be the same as new value",
|
assertTrue("failure in test: values should not be the same as new value",
|
||||||
values[i] != newValues[i] &&
|
values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])));
|
||||||
(values[i] == null || !values[i].equals(newValues[i])));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,26 +481,18 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testMakeMap() {
|
public void testMakeMap() {
|
||||||
Map em = makeEmptyMap();
|
Map em = makeEmptyMap();
|
||||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.",
|
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em != null);
|
||||||
em != null);
|
|
||||||
|
|
||||||
Map em2 = makeEmptyMap();
|
Map em2 = makeEmptyMap();
|
||||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.",
|
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em2 != null);
|
||||||
em != null);
|
assertTrue("failure in test: makeEmptyMap must return a new map with each invocation.", em != em2);
|
||||||
|
|
||||||
assertTrue("failure in test: makeEmptyMap must return a new map " +
|
|
||||||
"with each invocation.", em != em2);
|
|
||||||
|
|
||||||
Map fm = makeFullMap();
|
Map fm = makeFullMap();
|
||||||
assertTrue("failure in test: makeFullMap must return a non-null map.",
|
assertTrue("failure in test: makeFullMap must return a non-null map.", fm != null);
|
||||||
fm != null);
|
|
||||||
|
|
||||||
Map fm2 = makeFullMap();
|
Map fm2 = makeFullMap();
|
||||||
assertTrue("failure in test: makeFullMap must return a non-null map.",
|
assertTrue("failure in test: makeFullMap must return a non-null map.", fm2 != null);
|
||||||
fm != null);
|
assertTrue("failure in test: makeFullMap must return a new map with each invocation.", fm != fm2);
|
||||||
|
|
||||||
assertTrue("failure in test: makeFullMap must return a new map " +
|
|
||||||
"with each invocation.", fm != fm2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -522,13 +500,11 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testMapIsEmpty() {
|
public void testMapIsEmpty() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertEquals("Map.isEmpty() should return true with an empty map",
|
assertEquals("Map.isEmpty() should return true with an empty map", true, map.isEmpty());
|
||||||
true, map.isEmpty());
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertEquals("Map.isEmpty() should return false with a non-empty map",
|
assertEquals("Map.isEmpty() should return false with a non-empty map", false, map.isEmpty());
|
||||||
false, map.isEmpty());
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,13 +513,11 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testMapSize() {
|
public void testMapSize() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertEquals("Map.size() should be 0 with an empty map",
|
assertEquals("Map.size() should be 0 with an empty map", 0, map.size());
|
||||||
0, map.size());
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertEquals("Map.size() should equal the number of entries " +
|
assertEquals("Map.size() should equal the number of entries in the map", getSampleKeys().length, map.size());
|
||||||
"in the map", getSampleKeys().length, map.size());
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,7 +535,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
resetFull();
|
resetFull();
|
||||||
map.clear();
|
map.clear();
|
||||||
fail("Expected UnsupportedOperationException on clear");
|
fail("Expected UnsupportedOperationException on clear");
|
||||||
} catch (UnsupportedOperationException ex) {}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +552,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Map.containsKey(Object) by verifying it returns false for all
|
* Tests Map.containsKey(Object) by verifying it returns false for all
|
||||||
* sample keys on a map created using an empty map and returns true for
|
* sample keys on a map created using an empty map and returns true for
|
||||||
@ -586,16 +561,14 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Object[] keys = getSampleKeys();
|
Object[] keys = getSampleKeys();
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for (Object key : keys) {
|
||||||
assertTrue("Map must not contain key when map is empty",
|
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||||
!map.containsKey(keys[i]));
|
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for (Object key : keys) {
|
||||||
assertTrue("Map must contain key for a mapping in the map. " +
|
assertTrue("Map must contain key for a mapping in the map. Missing: " + key, map.containsKey(key));
|
||||||
"Missing: " + keys[i], map.containsKey(keys[i]));
|
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
@ -609,21 +582,18 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Object[] values = getSampleValues();
|
Object[] values = getSampleValues();
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
for(int i = 0; i < values.length; i++) {
|
for (Object value : values) {
|
||||||
assertTrue("Empty map must not contain value",
|
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||||
!map.containsValue(values[i]));
|
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for(int i = 0; i < values.length; i++) {
|
for (Object value : values) {
|
||||||
assertTrue("Map must contain value for a mapping in the map.",
|
assertTrue("Map must contain value for a mapping in the map.", map.containsValue(value));
|
||||||
map.containsValue(values[i]));
|
|
||||||
}
|
}
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Map.equals(Object)
|
* Tests Map.equals(Object)
|
||||||
*/
|
*/
|
||||||
@ -646,12 +616,10 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("equals(null) returned true.", !map.equals(null));
|
assertTrue("equals(null) returned true.", !map.equals(null));
|
||||||
assertTrue("equals(new Object()) returned true.",
|
assertTrue("equals(new Object()) returned true.", !map.equals(new Object()));
|
||||||
!map.equals(new Object()));
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests Map.get(Object)
|
* Tests Map.get(Object)
|
||||||
*/
|
*/
|
||||||
@ -661,16 +629,15 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Object[] keys = getSampleKeys();
|
Object[] keys = getSampleKeys();
|
||||||
Object[] values = getSampleValues();
|
Object[] values = getSampleValues();
|
||||||
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (Object key : keys) {
|
||||||
assertTrue("Empty map.get() should return null.",
|
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||||
map.get(keys[i]) == null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
assertEquals("Full map.get() should return value from mapping.",
|
assertEquals("Full map.get() should return value from mapping.", values[i], map.get(keys[i]));
|
||||||
values[i], map.get(keys[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,12 +646,10 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testMapHashCode() {
|
public void testMapHashCode() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertTrue("Empty maps have different hashCodes.",
|
assertTrue("Empty maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||||
map.hashCode() == confirmed.hashCode());
|
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("Equal maps have different hashCodes.",
|
assertTrue("Equal maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||||
map.hashCode() == confirmed.hashCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -698,17 +663,14 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testMapToString() {
|
public void testMapToString() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
assertTrue("Empty map toString() should not return null",
|
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||||
map.toString() != null);
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
assertTrue("Empty map toString() should not return null",
|
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||||
map.toString() != null);
|
|
||||||
verifyAll();
|
verifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the current serialized form of the Map
|
* Compare the current serialized form of the Map
|
||||||
* against the canonical version in CVS.
|
* against the canonical version in CVS.
|
||||||
@ -792,22 +754,28 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
!map.containsValue(values[i]));
|
!map.containsValue(values[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
// two possible exception here, either valid
|
// two possible exception here, either valid
|
||||||
map.put(keys[0], newValues[0]);
|
map.put(keys[0], newValues[0]);
|
||||||
fail("Expected IllegalArgumentException or UnsupportedOperationException on put (change)");
|
fail("Expected IllegalArgumentException or UnsupportedOperationException on put (change)");
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
} catch (UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
} else if (isPutChangeSupported()) {
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isPutChangeSupported()) {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
try {
|
try {
|
||||||
map.put(keys[0], values[0]);
|
map.put(keys[0], values[0]);
|
||||||
fail("Expected UnsupportedOperationException or IllegalArgumentException on put (add) when fixed size");
|
fail("Expected UnsupportedOperationException or IllegalArgumentException on put (add) when fixed size");
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
} catch (UnsupportedOperationException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -831,11 +799,14 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
!map.containsValue(values[i]));
|
!map.containsValue(values[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
map.put(keys[0], values[0]);
|
map.put(keys[0], values[0]);
|
||||||
fail("Expected UnsupportedOperationException on put (add)");
|
fail("Expected UnsupportedOperationException on put (add)");
|
||||||
} catch (UnsupportedOperationException ex) {}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,12 +820,16 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
if (isPutAddSupported()) {
|
if (isPutAddSupported()) {
|
||||||
if (isAllowNullKey()) {
|
if (isAllowNullKey()) {
|
||||||
map.put(null, values[0]);
|
map.put(null, values[0]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
map.put(null, values[0]);
|
map.put(null, values[0]);
|
||||||
fail("put(null, value) should throw NPE/IAE");
|
fail("put(null, value) should throw NPE/IAE");
|
||||||
} catch (NullPointerException ex) {
|
}
|
||||||
} catch (IllegalArgumentException ex) {}
|
catch (NullPointerException ex) {
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -869,12 +844,16 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
if (isPutAddSupported()) {
|
if (isPutAddSupported()) {
|
||||||
if (isAllowNullValue()) {
|
if (isAllowNullValue()) {
|
||||||
map.put(keys[0], null);
|
map.put(keys[0], null);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
try {
|
try {
|
||||||
map.put(keys[0], null);
|
map.put(keys[0], null);
|
||||||
fail("put(key, null) should throw NPE/IAE");
|
fail("put(key, null) should throw NPE/IAE");
|
||||||
} catch (NullPointerException ex) {
|
}
|
||||||
} catch (IllegalArgumentException ex) {}
|
catch (NullPointerException ex) {
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -890,7 +869,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
try {
|
try {
|
||||||
map.putAll(temp);
|
map.putAll(temp);
|
||||||
fail("Expected UnsupportedOperationException on putAll");
|
fail("Expected UnsupportedOperationException on putAll");
|
||||||
} catch (UnsupportedOperationException ex) {}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -926,7 +907,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
resetFull();
|
resetFull();
|
||||||
map.remove(map.keySet().iterator().next());
|
map.remove(map.keySet().iterator().next());
|
||||||
fail("Expected UnsupportedOperationException on remove");
|
fail("Expected UnsupportedOperationException on remove");
|
||||||
} catch (UnsupportedOperationException ex) {}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -966,12 +949,15 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the {@link Map#values} collection is backed by
|
* Tests that the {@link Map#values} collection is backed by
|
||||||
* the underlying map for clear().
|
* the underlying map for clear().
|
||||||
*/
|
*/
|
||||||
public void testValuesClearChangesMap() {
|
public void testValuesClearChangesMap() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// clear values, reflected in map
|
// clear values, reflected in map
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -997,7 +983,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* the underlying map for clear().
|
* the underlying map for clear().
|
||||||
*/
|
*/
|
||||||
public void testKeySetClearChangesMap() {
|
public void testKeySetClearChangesMap() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// clear values, reflected in map
|
// clear values, reflected in map
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -1023,7 +1011,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
* the underlying map for clear().
|
* the underlying map for clear().
|
||||||
*/
|
*/
|
||||||
public void testEntrySetClearChangesMap() {
|
public void testEntrySetClearChangesMap() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// clear values, reflected in map
|
// clear values, reflected in map
|
||||||
resetFull();
|
resetFull();
|
||||||
@ -1051,6 +1041,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Map.Entry entry = (Map.Entry) entrySet.iterator().next();
|
Map.Entry entry = (Map.Entry) entrySet.iterator().next();
|
||||||
assertEquals(true, entrySet.contains(entry));
|
assertEquals(true, entrySet.contains(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySetContains2() {
|
public void testEntrySetContains2() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Set entrySet = map.entrySet();
|
Set entrySet = map.entrySet();
|
||||||
@ -1058,6 +1049,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
Map.Entry test = cloneMapEntry(entry);
|
Map.Entry test = cloneMapEntry(entry);
|
||||||
assertEquals(true, entrySet.contains(test));
|
assertEquals(true, entrySet.contains(test));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySetContains3() {
|
public void testEntrySetContains3() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Set entrySet = map.entrySet();
|
Set entrySet = map.entrySet();
|
||||||
@ -1069,7 +1061,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySetRemove1() {
|
public void testEntrySetRemove1() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
int size = map.size();
|
int size = map.size();
|
||||||
Set entrySet = map.entrySet();
|
Set entrySet = map.entrySet();
|
||||||
@ -1080,8 +1074,11 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
assertEquals(false, map.containsKey(key));
|
assertEquals(false, map.containsKey(key));
|
||||||
assertEquals(size - 1, map.size());
|
assertEquals(size - 1, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySetRemove2() {
|
public void testEntrySetRemove2() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
int size = map.size();
|
int size = map.size();
|
||||||
Set entrySet = map.entrySet();
|
Set entrySet = map.entrySet();
|
||||||
@ -1093,8 +1090,11 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
assertEquals(false, map.containsKey(key));
|
assertEquals(false, map.containsKey(key));
|
||||||
assertEquals(size - 1, map.size());
|
assertEquals(size - 1, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntrySetRemove3() {
|
public void testEntrySetRemove3() {
|
||||||
if (!isRemoveSupported()) return;
|
if (!isRemoveSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
int size = map.size();
|
int size = map.size();
|
||||||
Set entrySet = map.entrySet();
|
Set entrySet = map.entrySet();
|
||||||
@ -1110,6 +1110,7 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the {@link Map#values} collection is backed by
|
* Tests that the {@link Map#values} collection is backed by
|
||||||
* the underlying map by removing from the values collection
|
* the underlying map by removing from the values collection
|
||||||
@ -1135,7 +1136,8 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
while (values.contains(sampleValues[i]) && j < 10000) {
|
while (values.contains(sampleValues[i]) && j < 10000) {
|
||||||
try {
|
try {
|
||||||
values.remove(sampleValues[i]);
|
values.remove(sampleValues[i]);
|
||||||
} catch (UnsupportedOperationException e) {
|
}
|
||||||
|
catch (UnsupportedOperationException e) {
|
||||||
// if values.remove is unsupported, just skip this test
|
// if values.remove is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1161,7 +1163,8 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
for (int i = 0; i < sampleKeys.length; i++) {
|
for (int i = 0; i < sampleKeys.length; i++) {
|
||||||
try {
|
try {
|
||||||
keys.remove(sampleKeys[i]);
|
keys.remove(sampleKeys[i]);
|
||||||
} catch (UnsupportedOperationException e) {
|
}
|
||||||
|
catch (UnsupportedOperationException e) {
|
||||||
// if key.remove is unsupported, just skip this test
|
// if key.remove is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1176,7 +1179,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
// same for EntrySet/KeySet/values's
|
// same for EntrySet/KeySet/values's
|
||||||
// Iterator.remove, removeAll, retainAll
|
// Iterator.remove, removeAll, retainAll
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods to create an array of Map.Entry objects
|
* Utility methods to create an array of Map.Entry objects
|
||||||
* out of the given key and value arrays.<P>
|
* out of the given key and value arrays.<P>
|
||||||
@ -1195,7 +1197,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk test {@link Map#entrySet()}. This method runs through all of
|
* Bulk test {@link Map#entrySet()}. This method runs through all of
|
||||||
* the tests in {@link SetAbstractTestCase}.
|
* the tests in {@link SetAbstractTestCase}.
|
||||||
@ -1238,13 +1239,16 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
// Collection views don't support add operations.
|
// Collection views don't support add operations.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoveSupported() {
|
public boolean isRemoveSupported() {
|
||||||
// Entry set should only support remove if map does
|
// Entry set should only support remove if map does
|
||||||
return MapAbstractTestCase.this.isRemoveSupported();
|
return MapAbstractTestCase.this.isRemoveSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGetStructuralModify() {
|
public boolean isGetStructuralModify() {
|
||||||
return MapAbstractTestCase.this.isGetStructuralModify();
|
return MapAbstractTestCase.this.isGetStructuralModify();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestSerialization() {
|
public boolean isTestSerialization() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1299,7 +1303,8 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
if (isSetValueSupported() == false) {
|
if (isSetValueSupported() == false) {
|
||||||
try {
|
try {
|
||||||
entry1.setValue(newValue1);
|
entry1.setValue(newValue1);
|
||||||
} catch (UnsupportedOperationException ex) {
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1338,7 +1343,8 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
entry = temp;
|
entry = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (temp.getKey().equals(key)) {
|
}
|
||||||
|
else if (temp.getKey().equals(key)) {
|
||||||
entry = temp;
|
entry = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1348,7 +1354,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testMapEntrySetRemoveNonMapEntry() {
|
public void testMapEntrySetRemoveNonMapEntry() {
|
||||||
if (isRemoveSupported() == false) return;
|
if (isRemoveSupported() == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
assertEquals(false, getSet().remove(null));
|
assertEquals(false, getSet().remove(null));
|
||||||
assertEquals(false, getSet().remove(new Object()));
|
assertEquals(false, getSet().remove(new Object()));
|
||||||
@ -1360,7 +1368,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk test {@link Map#keySet()}. This method runs through all of
|
* Bulk test {@link Map#keySet()}. This method runs through all of
|
||||||
* the tests in {@link SetAbstractTestCase}.
|
* the tests in {@link SetAbstractTestCase}.
|
||||||
@ -1395,12 +1402,15 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
public boolean isNullSupported() {
|
public boolean isNullSupported() {
|
||||||
return MapAbstractTestCase.this.isAllowNullKey();
|
return MapAbstractTestCase.this.isAllowNullKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAddSupported() {
|
public boolean isAddSupported() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoveSupported() {
|
public boolean isRemoveSupported() {
|
||||||
return MapAbstractTestCase.this.isRemoveSupported();
|
return MapAbstractTestCase.this.isRemoveSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestSerialization() {
|
public boolean isTestSerialization() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1423,7 +1433,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk test {@link Map#values()}. This method runs through all of
|
* Bulk test {@link Map#values()}. This method runs through all of
|
||||||
* the tests in {@link CollectionAbstractTestCase}.
|
* the tests in {@link CollectionAbstractTestCase}.
|
||||||
@ -1459,12 +1468,15 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
public boolean isNullSupported() {
|
public boolean isNullSupported() {
|
||||||
return MapAbstractTestCase.this.isAllowNullKey();
|
return MapAbstractTestCase.this.isAllowNullKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAddSupported() {
|
public boolean isAddSupported() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoveSupported() {
|
public boolean isRemoveSupported() {
|
||||||
return MapAbstractTestCase.this.isRemoveSupported();
|
return MapAbstractTestCase.this.isRemoveSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestSerialization() {
|
public boolean isTestSerialization() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1507,7 +1519,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
// the value equal to the value returned from the values iterator.
|
// the value equal to the value returned from the values iterator.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the {@link #map}, {@link #entrySet}, {@link #keySet},
|
* Resets the {@link #map}, {@link #entrySet}, {@link #keySet},
|
||||||
* {@link #values} and {@link #confirmed} fields to empty.
|
* {@link #values} and {@link #confirmed} fields to empty.
|
||||||
@ -1533,7 +1544,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the collection view fields.
|
* Resets the collection view fields.
|
||||||
*/
|
*/
|
||||||
@ -1543,7 +1553,6 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
this.entrySet = map.entrySet();
|
this.entrySet = map.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that {@link #map} is still equal to {@link #confirmed}.
|
* Verifies that {@link #map} is still equal to {@link #confirmed}.
|
||||||
* This method checks that the map is equal to the HashMap,
|
* This method checks that the map is equal to the HashMap,
|
||||||
@ -1564,12 +1573,9 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
public void verifyMap() {
|
public void verifyMap() {
|
||||||
int size = confirmed.size();
|
int size = confirmed.size();
|
||||||
boolean empty = confirmed.isEmpty();
|
boolean empty = confirmed.isEmpty();
|
||||||
assertEquals("Map should be same size as HashMap",
|
assertEquals("Map should be same size as HashMap", size, map.size());
|
||||||
size, map.size());
|
assertEquals("Map should be empty if HashMap is", empty, map.isEmpty());
|
||||||
assertEquals("Map should be empty if HashMap is",
|
assertEquals("hashCodes should be the same", confirmed.hashCode(), map.hashCode());
|
||||||
empty, map.isEmpty());
|
|
||||||
assertEquals("hashCodes should be the same",
|
|
||||||
confirmed.hashCode(), map.hashCode());
|
|
||||||
// this fails for LRUMap because confirmed.equals() somehow modifies
|
// this fails for LRUMap because confirmed.equals() somehow modifies
|
||||||
// map, causing concurrent modification exceptions.
|
// map, causing concurrent modification exceptions.
|
||||||
//assertEquals("Map should still equal HashMap", confirmed, map);
|
//assertEquals("Map should still equal HashMap", confirmed, map);
|
||||||
@ -1584,39 +1590,29 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
public void verifyEntrySet() {
|
public void verifyEntrySet() {
|
||||||
int size = confirmed.size();
|
int size = confirmed.size();
|
||||||
boolean empty = confirmed.isEmpty();
|
boolean empty = confirmed.isEmpty();
|
||||||
assertEquals("entrySet should be same size as HashMap's" +
|
assertEquals("entrySet should be same size as HashMap's\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||||
"\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
|
||||||
size, entrySet.size());
|
size, entrySet.size());
|
||||||
assertEquals("entrySet should be empty if HashMap is" +
|
assertEquals("entrySet should be empty if HashMap is\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||||
"\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
|
||||||
empty, entrySet.isEmpty());
|
empty, entrySet.isEmpty());
|
||||||
assertTrue("entrySet should contain all HashMap's elements" +
|
assertTrue("entrySet should contain all HashMap's elements\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||||
"\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
|
||||||
entrySet.containsAll(confirmed.entrySet()));
|
entrySet.containsAll(confirmed.entrySet()));
|
||||||
assertEquals("entrySet hashCodes should be the same" +
|
assertEquals("entrySet hashCodes should be the same\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||||
"\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
|
||||||
confirmed.entrySet().hashCode(), entrySet.hashCode());
|
confirmed.entrySet().hashCode(), entrySet.hashCode());
|
||||||
assertEquals("Map's entry set should still equal HashMap's",
|
assertEquals("Map's entry set should still equal HashMap's", confirmed.entrySet(), entrySet);
|
||||||
confirmed.entrySet(), entrySet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifyKeySet() {
|
public void verifyKeySet() {
|
||||||
int size = confirmed.size();
|
int size = confirmed.size();
|
||||||
boolean empty = confirmed.isEmpty();
|
boolean empty = confirmed.isEmpty();
|
||||||
assertEquals("keySet should be same size as HashMap's" +
|
assertEquals("keySet should be same size as HashMap's\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||||
"\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
|
||||||
size, keySet.size());
|
size, keySet.size());
|
||||||
assertEquals("keySet should be empty if HashMap is" +
|
assertEquals("keySet should be empty if HashMap is\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||||
"\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
|
||||||
empty, keySet.isEmpty());
|
empty, keySet.isEmpty());
|
||||||
assertTrue("keySet should contain all HashMap's elements" +
|
assertTrue("keySet should contain all HashMap's elements\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||||
"\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
|
||||||
keySet.containsAll(confirmed.keySet()));
|
keySet.containsAll(confirmed.keySet()));
|
||||||
assertEquals("keySet hashCodes should be the same" +
|
assertEquals("keySet hashCodes should be the same\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||||
"\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
|
||||||
confirmed.keySet().hashCode(), keySet.hashCode());
|
confirmed.keySet().hashCode(), keySet.hashCode());
|
||||||
assertEquals("Map's key set should still equal HashMap's",
|
assertEquals("Map's key set should still equal HashMap's", confirmed.keySet(), keySet);
|
||||||
confirmed.keySet(), keySet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifyValues() {
|
public void verifyValues() {
|
||||||
@ -1625,27 +1621,20 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
|
|
||||||
int size = confirmed.size();
|
int size = confirmed.size();
|
||||||
boolean empty = confirmed.isEmpty();
|
boolean empty = confirmed.isEmpty();
|
||||||
assertEquals("values should be same size as HashMap's" +
|
|
||||||
"\nTest: " + test + "\nReal: " + known,
|
assertEquals("values should be same size as HashMap's\nTest: " + test + "\nReal: " + known, size, values.size());
|
||||||
size, values.size());
|
assertEquals("values should be empty if HashMap is\nTest: " + test + "\nReal: " + known, empty, values.isEmpty());
|
||||||
assertEquals("values should be empty if HashMap is" +
|
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, test.containsAll(known));
|
||||||
"\nTest: " + test + "\nReal: " + known,
|
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, known.containsAll(test));
|
||||||
empty, values.isEmpty());
|
|
||||||
assertTrue("values should contain all HashMap's elements" +
|
for (Object aKnown : known) {
|
||||||
"\nTest: " + test + "\nReal: " + known,
|
boolean removed = test.remove(aKnown);
|
||||||
test.containsAll(known));
|
|
||||||
assertTrue("values should contain all HashMap's elements" +
|
|
||||||
"\nTest: " + test + "\nReal: " + known,
|
|
||||||
known.containsAll(test));
|
|
||||||
// originally coded to use a HashBag, but now separate jar so...
|
|
||||||
for (Iterator it = known.iterator(); it.hasNext();) {
|
|
||||||
boolean removed = test.remove(it.next());
|
|
||||||
assertTrue("Map's values should still equal HashMap's", removed);
|
assertTrue("Map's values should still equal HashMap's", removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue("Map's values should still equal HashMap's", test.isEmpty());
|
assertTrue("Map's values should still equal HashMap's", test.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erases any leftover instance variables by setting them to null.
|
* Erases any leftover instance variables by setting them to null.
|
||||||
*/
|
*/
|
||||||
@ -1656,5 +1645,4 @@ public abstract class MapAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
values = null;
|
values = null;
|
||||||
confirmed = null;
|
confirmed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.twelvemonkeys.util;
|
package com.twelvemonkeys.util;
|
||||||
|
|
||||||
import org.jmock.cglib.MockObjectTestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ import java.io.*;
|
|||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @author Anonymous
|
* @author Anonymous
|
||||||
*/
|
*/
|
||||||
public abstract class ObjectAbstractTestCase extends MockObjectTestCase {
|
public abstract class ObjectAbstractTestCase extends TestCase {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this method to return the object to test.
|
* Implement this method to return the object to test.
|
||||||
*
|
*
|
||||||
|
@ -52,12 +52,5 @@
|
|||||||
<version>4.7</version>
|
<version>4.7</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>jmock</groupId>
|
|
||||||
<artifactId>jmock-cglib</artifactId>
|
|
||||||
<version>1.0.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -81,6 +81,7 @@ public class WMFImageReader extends ImageReaderBase {
|
|||||||
processReadAborted();
|
processReadAborted();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
processImageProgress(100f);
|
||||||
|
|
||||||
processImageComplete();
|
processImageComplete();
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import java.util.List;
|
|||||||
* @version $Id: SVGImageReaderTestCase.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: SVGImageReaderTestCase.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class SVGImageReaderTestCase extends ImageReaderAbstractTestCase<SVGImageReader> {
|
public class SVGImageReaderTestCase extends ImageReaderAbstractTestCase<SVGImageReader> {
|
||||||
private SVGImageReaderSpi mSVGImageReaderSpi = new SVGImageReaderSpi();
|
private SVGImageReaderSpi provider = new SVGImageReaderSpi();
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
@ -52,7 +52,7 @@ public class SVGImageReaderTestCase extends ImageReaderAbstractTestCase<SVGImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ImageReaderSpi createProvider() {
|
protected ImageReaderSpi createProvider() {
|
||||||
return mSVGImageReaderSpi;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,7 +43,7 @@ import java.util.List;
|
|||||||
* @version $Id: SVGImageReaderTestCase.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
* @version $Id: SVGImageReaderTestCase.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public class WMFImageReaderTestCase extends ImageReaderAbstractTestCase<WMFImageReader> {
|
public class WMFImageReaderTestCase extends ImageReaderAbstractTestCase<WMFImageReader> {
|
||||||
private WMFImageReaderSpi mSVGImageReaderSpi = new WMFImageReaderSpi();
|
private WMFImageReaderSpi provider = new WMFImageReaderSpi();
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
@ -53,7 +53,7 @@ public class WMFImageReaderTestCase extends ImageReaderAbstractTestCase<WMFImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ImageReaderSpi createProvider() {
|
protected ImageReaderSpi createProvider() {
|
||||||
return mSVGImageReaderSpi;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,12 +29,11 @@
|
|||||||
package com.twelvemonkeys.imageio.util;
|
package com.twelvemonkeys.imageio.util;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||||
import org.jmock.Mock;
|
|
||||||
import org.jmock.cglib.MockObjectTestCase;
|
|
||||||
import org.jmock.core.Invocation;
|
|
||||||
import org.jmock.core.Stub;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.InOrder;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import javax.imageio.*;
|
import javax.imageio.*;
|
||||||
import javax.imageio.event.IIOReadProgressListener;
|
import javax.imageio.event.IIOReadProgressListener;
|
||||||
@ -55,6 +54,9 @@ import java.util.Arrays;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageReaderAbstractTestCase
|
* ImageReaderAbstractTestCase
|
||||||
*
|
*
|
||||||
@ -62,7 +64,7 @@ import java.util.List;
|
|||||||
* @author last modified by $Author: haraldk$
|
* @author last modified by $Author: haraldk$
|
||||||
* @version $Id: ImageReaderAbstractTestCase.java,v 1.0 Apr 1, 2008 10:36:46 PM haraldk Exp$
|
* @version $Id: ImageReaderAbstractTestCase.java,v 1.0 Apr 1, 2008 10:36:46 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends MockObjectTestCase {
|
public abstract class ImageReaderAbstractTestCase<T extends ImageReader> {
|
||||||
// TODO: Should we really test if he provider is installed?
|
// TODO: Should we really test if he provider is installed?
|
||||||
// - Pro: Tests the META-INF/services config
|
// - Pro: Tests the META-INF/services config
|
||||||
// - Con: Not all providers should be installed at runtime...
|
// - Con: Not all providers should be installed at runtime...
|
||||||
@ -948,8 +950,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
@Test
|
@Test
|
||||||
public void testAddIIOReadProgressListener() {
|
public void testAddIIOReadProgressListener() {
|
||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
reader.addIIOReadProgressListener(mock(IIOReadProgressListener.class));
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -964,13 +965,8 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class);
|
||||||
String started = "Started";
|
reader.addIIOReadProgressListener(listener);
|
||||||
mockListener.expects(once()).method("imageStarted").withAnyArguments().id(started);
|
|
||||||
mockListener.stubs().method("imageProgress").withAnyArguments().after(started);
|
|
||||||
mockListener.expects(once()).method("imageComplete").withAnyArguments().after(started);
|
|
||||||
|
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.read(0);
|
reader.read(0);
|
||||||
@ -980,7 +976,10 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
mockListener.verify();
|
InOrder ordered = inOrder(listener);
|
||||||
|
ordered.verify(listener).imageStarted(reader, 0);
|
||||||
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
|
ordered.verify(listener).imageComplete(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -989,28 +988,13 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class);
|
||||||
String started = "Started";
|
IIOReadProgressListener listenerToo = mock(IIOReadProgressListener.class);
|
||||||
mockListener.expects(once()).method("imageStarted").withAnyArguments().id(started);
|
IIOReadProgressListener listenerThree = mock(IIOReadProgressListener.class);
|
||||||
mockListener.stubs().method("imageProgress").withAnyArguments().after(started);
|
|
||||||
mockListener.expects(once()).method("imageComplete").withAnyArguments().after(started);
|
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOReadProgressListener.class);
|
reader.addIIOReadProgressListener(listener);
|
||||||
String startedToo = "Started Two";
|
reader.addIIOReadProgressListener(listenerToo);
|
||||||
mockListenerToo.expects(once()).method("imageStarted").withAnyArguments().id(startedToo);
|
reader.addIIOReadProgressListener(listenerThree);
|
||||||
mockListenerToo.stubs().method("imageProgress").withAnyArguments().after(startedToo);
|
|
||||||
mockListenerToo.expects(once()).method("imageComplete").withAnyArguments().after(startedToo);
|
|
||||||
|
|
||||||
Mock mockListenerThree = new Mock(IIOReadProgressListener.class);
|
|
||||||
String startedThree = "Started Three";
|
|
||||||
mockListenerThree.expects(once()).method("imageStarted").withAnyArguments().id(startedThree);
|
|
||||||
mockListenerThree.stubs().method("imageProgress").withAnyArguments().after(startedThree);
|
|
||||||
mockListenerThree.expects(once()).method("imageComplete").withAnyArguments().after(startedThree);
|
|
||||||
|
|
||||||
|
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListenerToo.proxy());
|
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListenerThree.proxy());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.read(0);
|
reader.read(0);
|
||||||
@ -1020,9 +1004,19 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
mockListener.verify();
|
InOrder ordered = inOrder(listener, listenerToo, listenerThree);
|
||||||
mockListenerToo.verify();
|
|
||||||
mockListenerThree.verify();
|
ordered.verify(listener).imageStarted(reader, 0);
|
||||||
|
ordered.verify(listenerToo).imageStarted(reader, 0);
|
||||||
|
ordered.verify(listenerThree).imageStarted(reader, 0);
|
||||||
|
|
||||||
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
|
ordered.verify(listenerToo, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
|
ordered.verify(listenerThree, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
|
|
||||||
|
ordered.verify(listener).imageComplete(reader);
|
||||||
|
ordered.verify(listenerToo).imageComplete(reader);
|
||||||
|
ordered.verify(listenerThree).imageComplete(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1034,8 +1028,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveIIOReadProgressListenerNone() {
|
public void testRemoveIIOReadProgressListenerNone() {
|
||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
reader.removeIIOReadProgressListener(mock(IIOReadProgressListener.class));
|
||||||
reader.removeIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1043,8 +1036,8 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
|
||||||
IIOReadProgressListener listener = (IIOReadProgressListener) mockListener.proxy();
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class);
|
||||||
reader.addIIOReadProgressListener(listener);
|
reader.addIIOReadProgressListener(listener);
|
||||||
reader.removeIIOReadProgressListener(listener);
|
reader.removeIIOReadProgressListener(listener);
|
||||||
|
|
||||||
@ -1056,7 +1049,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1065,15 +1058,11 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class, "Listener1");
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class, "Listener1");
|
||||||
IIOReadProgressListener listener = (IIOReadProgressListener) mockListener.proxy();
|
|
||||||
reader.addIIOReadProgressListener(listener);
|
reader.addIIOReadProgressListener(listener);
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOReadProgressListener.class, "Listener2");
|
|
||||||
mockListenerToo.expects(once()).method("imageStarted").with(eq(reader), eq(0));
|
IIOReadProgressListener listenerToo = mock(IIOReadProgressListener.class, "Listener2");
|
||||||
mockListenerToo.stubs().method("imageProgress").withAnyArguments();
|
|
||||||
mockListenerToo.expects(once()).method("imageComplete").with(eq(reader));
|
|
||||||
IIOReadProgressListener listenerToo = (IIOReadProgressListener) mockListenerToo.proxy();
|
|
||||||
reader.addIIOReadProgressListener(listenerToo);
|
reader.addIIOReadProgressListener(listenerToo);
|
||||||
|
|
||||||
reader.removeIIOReadProgressListener(listener);
|
reader.removeIIOReadProgressListener(listener);
|
||||||
@ -1085,9 +1074,13 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
fail("Could not read image");
|
fail("Could not read image");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods on listener1...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
mockListenerToo.verify();
|
|
||||||
|
InOrder ordered = inOrder(listenerToo);
|
||||||
|
ordered.verify(listenerToo).imageStarted(reader, 0);
|
||||||
|
ordered.verify(listenerToo, atLeastOnce()).imageProgress(eq(reader), anyInt());
|
||||||
|
ordered.verify(listenerToo).imageComplete(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1096,8 +1089,8 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class);
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
reader.addIIOReadProgressListener(listener);
|
||||||
|
|
||||||
reader.removeAllIIOReadProgressListeners();
|
reader.removeAllIIOReadProgressListeners();
|
||||||
|
|
||||||
@ -1109,7 +1102,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1118,11 +1111,11 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class);
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class);
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListener.proxy());
|
reader.addIIOReadProgressListener(listener);
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOReadProgressListener.class);
|
IIOReadProgressListener listenerToo = mock(IIOReadProgressListener.class);
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) mockListenerToo.proxy());
|
reader.addIIOReadProgressListener(listenerToo);
|
||||||
|
|
||||||
reader.removeAllIIOReadProgressListeners();
|
reader.removeAllIIOReadProgressListeners();
|
||||||
|
|
||||||
@ -1134,8 +1127,8 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
mockListenerToo.verify();
|
verifyZeroInteractions(listenerToo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1144,41 +1137,24 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOReadProgressListener.class, "Progress1");
|
IIOReadProgressListener listener = mock(IIOReadProgressListener.class, "Progress1");
|
||||||
mockListener.stubs().method("imageStarted").withAnyArguments();
|
|
||||||
mockListener.stubs().method("imageProgress").withAnyArguments();
|
|
||||||
mockListener.expects(once()).method("readAborted").with(eq(reader));
|
|
||||||
mockListener.stubs().method("imageComplete").withAnyArguments();
|
|
||||||
IIOReadProgressListener listener = (IIOReadProgressListener) mockListener.proxy();
|
|
||||||
reader.addIIOReadProgressListener(listener);
|
reader.addIIOReadProgressListener(listener);
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOReadProgressListener.class, "Progress2");
|
IIOReadProgressListener listenerToo = mock(IIOReadProgressListener.class, "Progress2");
|
||||||
mockListenerToo.stubs().method("imageStarted").withAnyArguments();
|
|
||||||
mockListenerToo.stubs().method("imageProgress").withAnyArguments();
|
|
||||||
mockListenerToo.expects(once()).method("readAborted").with(eq(reader));
|
|
||||||
mockListenerToo.stubs().method("imageComplete").withAnyArguments();
|
|
||||||
IIOReadProgressListener listenerToo = (IIOReadProgressListener) mockListenerToo.proxy();
|
|
||||||
reader.addIIOReadProgressListener(listenerToo);
|
reader.addIIOReadProgressListener(listenerToo);
|
||||||
|
|
||||||
// Create a listener that just makes the reader abort immediately...
|
// Create a listener that just makes the reader abort immediately...
|
||||||
Mock abortingListener = new Mock(IIOReadProgressListener.class, "Aborter");
|
IIOReadProgressListener abortingListener = mock(IIOReadProgressListener.class, "Aborter");
|
||||||
abortingListener.stubs().method("readAborted").withAnyArguments();
|
Answer<Void> abort = new Answer<Void>() {
|
||||||
abortingListener.stubs().method("imageComplete").withAnyArguments();
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Stub abort = new Stub() {
|
|
||||||
public Object invoke(Invocation pInvocation) throws Throwable {
|
|
||||||
reader.abort();
|
reader.abort();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringBuffer describeTo(StringBuffer pStringBuffer) {
|
|
||||||
pStringBuffer.append("aborting");
|
|
||||||
return pStringBuffer;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
abortingListener.stubs().method("imageProgress").will(abort);
|
doAnswer(abort).when(abortingListener).imageStarted(any(ImageReader.class), anyInt());
|
||||||
abortingListener.stubs().method("imageStarted").will(abort);
|
doAnswer(abort).when(abortingListener).imageProgress(any(ImageReader.class), anyInt());
|
||||||
|
|
||||||
reader.addIIOReadProgressListener((IIOReadProgressListener) abortingListener.proxy());
|
reader.addIIOReadProgressListener(abortingListener);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.read(0);
|
reader.read(0);
|
||||||
@ -1187,8 +1163,8 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
|||||||
failBecause("Image could not be read", e);
|
failBecause("Image could not be read", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
mockListener.verify();
|
verify(listener).readAborted(reader);
|
||||||
mockListenerToo.verify();
|
verify(listenerToo).readAborted(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.imageio.util;
|
package com.twelvemonkeys.imageio.util;
|
||||||
|
|
||||||
import org.jmock.Mock;
|
import org.junit.Test;
|
||||||
import org.jmock.cglib.MockObjectTestCase;
|
import org.mockito.InOrder;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.ImageWriteParam;
|
import javax.imageio.ImageWriteParam;
|
||||||
@ -39,6 +39,10 @@ import java.awt.image.RenderedImage;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageReaderAbstractTestCase class description.
|
* ImageReaderAbstractTestCase class description.
|
||||||
*
|
*
|
||||||
@ -46,12 +50,13 @@ import java.io.IOException;
|
|||||||
* @author last modified by $Author: haku $
|
* @author last modified by $Author: haku $
|
||||||
* @version $Id: ImageReaderAbstractTestCase.java,v 1.0 18.nov.2004 17:38:33 haku Exp $
|
* @version $Id: ImageReaderAbstractTestCase.java,v 1.0 18.nov.2004 17:38:33 haku Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
public abstract class ImageWriterAbstractTestCase {
|
||||||
|
|
||||||
protected abstract ImageWriter createImageWriter();
|
protected abstract ImageWriter createImageWriter();
|
||||||
|
|
||||||
protected abstract RenderedImage getTestData();
|
protected abstract RenderedImage getTestData();
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetOutput() throws IOException {
|
public void testSetOutput() throws IOException {
|
||||||
// Should just pass with no exceptions
|
// Should just pass with no exceptions
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
@ -59,6 +64,7 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
writer.setOutput(ImageIO.createImageOutputStream(new ByteArrayOutputStream()));
|
writer.setOutput(ImageIO.createImageOutputStream(new ByteArrayOutputStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetOutputNull() {
|
public void testSetOutputNull() {
|
||||||
// Should just pass with no exceptions
|
// Should just pass with no exceptions
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
@ -66,25 +72,30 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
writer.setOutput(null);
|
writer.setOutput(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWrite() throws IOException {
|
public void testWrite() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue("No image data written", buffer.size() > 0);
|
assertTrue("No image data written", buffer.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWrite2() {
|
public void testWrite2() {
|
||||||
// Note: There's a difference between new ImageOutputStreamImpl and
|
// Note: There's a difference between new ImageOutputStreamImpl and
|
||||||
// ImageIO.createImageOutputStream... Make sure writers handle both
|
// ImageIO.createImageOutputStream... Make sure writers handle both
|
||||||
// cases
|
// cases
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
@ -96,10 +107,12 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
assertTrue("No image data written", buffer.size() > 0);
|
assertTrue("No image data written", buffer.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWriteNull() throws IOException {
|
public void testWriteNull() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write((RenderedImage) null);
|
writer.write((RenderedImage) null);
|
||||||
}
|
}
|
||||||
@ -108,11 +121,14 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue("Image data written", buffer.size() == 0);
|
assertTrue("Image data written", buffer.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWriteNoOutput() {
|
public void testWriteNoOutput() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
}
|
}
|
||||||
@ -123,6 +139,7 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetDefaultWriteParam() {
|
public void testGetDefaultWriteParam() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
@ -132,29 +149,26 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
// TODO: Test writing with params
|
// TODO: Test writing with params
|
||||||
// TODO: Source region and subsampling at least
|
// TODO: Source region and subsampling at least
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddIIOWriteProgressListener() {
|
public void testAddIIOWriteProgressListener() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
writer.addIIOWriteProgressListener(mock(IIOWriteProgressListener.class));
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddIIOWriteProgressListenerNull() {
|
public void testAddIIOWriteProgressListenerNull() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
writer.addIIOWriteProgressListener(null);
|
writer.addIIOWriteProgressListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddIIOWriteProgressListenerCallbacks() throws IOException {
|
public void testAddIIOWriteProgressListenerCallbacks() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
String started = "Started";
|
writer.addIIOWriteProgressListener(listener);
|
||||||
mockListener.expects(once()).method("imageStarted").withAnyArguments().id(started);
|
|
||||||
mockListener.stubs().method("imageProgress").withAnyArguments().after(started);
|
|
||||||
mockListener.expects(once()).method("imageComplete").withAnyArguments().after(started);
|
|
||||||
|
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
@ -164,36 +178,25 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
mockListener.verify();
|
InOrder ordered = inOrder(listener);
|
||||||
|
ordered.verify(listener).imageStarted(writer, 0);
|
||||||
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(writer), anyInt());
|
||||||
|
ordered.verify(listener).imageComplete(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleAddIIOWriteProgressListenerCallbacks() throws IOException {
|
public void testMultipleAddIIOWriteProgressListenerCallbacks() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
String started = "Started";
|
IIOWriteProgressListener listenerToo = mock(IIOWriteProgressListener.class);
|
||||||
mockListener.expects(once()).method("imageStarted").withAnyArguments().id(started);
|
IIOWriteProgressListener listenerThree = mock(IIOWriteProgressListener.class);
|
||||||
mockListener.stubs().method("imageProgress").withAnyArguments().after(started);
|
|
||||||
mockListener.expects(once()).method("imageComplete").withAnyArguments().after(started);
|
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOWriteProgressListener.class);
|
writer.addIIOWriteProgressListener(listener);
|
||||||
String startedToo = "Started Two";
|
writer.addIIOWriteProgressListener(listenerToo);
|
||||||
mockListenerToo.expects(once()).method("imageStarted").withAnyArguments().id(startedToo);
|
writer.addIIOWriteProgressListener(listenerThree);
|
||||||
mockListenerToo.stubs().method("imageProgress").withAnyArguments().after(startedToo);
|
|
||||||
mockListenerToo.expects(once()).method("imageComplete").withAnyArguments().after(startedToo);
|
|
||||||
|
|
||||||
Mock mockListenerThree = new Mock(IIOWriteProgressListener.class);
|
|
||||||
String startedThree = "Started Three";
|
|
||||||
mockListenerThree.expects(once()).method("imageStarted").withAnyArguments().id(startedThree);
|
|
||||||
mockListenerThree.stubs().method("imageProgress").withAnyArguments().after(startedThree);
|
|
||||||
mockListenerThree.expects(once()).method("imageComplete").withAnyArguments().after(startedThree);
|
|
||||||
|
|
||||||
|
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListenerToo.proxy());
|
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListenerThree.proxy());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
@ -203,30 +206,40 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// At least imageStarted and imageComplete, plus any number of imageProgress
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
mockListener.verify();
|
InOrder ordered = inOrder(listener, listenerToo, listenerThree);
|
||||||
mockListenerToo.verify();
|
|
||||||
mockListenerThree.verify();
|
ordered.verify(listener).imageStarted(writer, 0);
|
||||||
|
ordered.verify(listenerToo).imageStarted(writer, 0);
|
||||||
|
ordered.verify(listenerThree).imageStarted(writer, 0);
|
||||||
|
|
||||||
|
ordered.verify(listener, atLeastOnce()).imageProgress(eq(writer), anyInt());
|
||||||
|
ordered.verify(listenerToo, atLeastOnce()).imageProgress(eq(writer), anyInt());
|
||||||
|
ordered.verify(listenerThree, atLeastOnce()).imageProgress(eq(writer), anyInt());
|
||||||
|
|
||||||
|
ordered.verify(listener).imageComplete(writer);
|
||||||
|
ordered.verify(listenerToo).imageComplete(writer);
|
||||||
|
ordered.verify(listenerThree).imageComplete(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveIIOWriteProgressListenerNull() {
|
public void testRemoveIIOWriteProgressListenerNull() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
writer.removeIIOWriteProgressListener(null);
|
writer.removeIIOWriteProgressListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveIIOWriteProgressListenerNone() {
|
public void testRemoveIIOWriteProgressListenerNone() {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
writer.removeIIOWriteProgressListener(mock(IIOWriteProgressListener.class));
|
||||||
writer.removeIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveIIOWriteProgressListener() throws IOException {
|
public void testRemoveIIOWriteProgressListener() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
IIOWriteProgressListener listener = (IIOWriteProgressListener) mockListener.proxy();
|
|
||||||
writer.addIIOWriteProgressListener(listener);
|
writer.addIIOWriteProgressListener(listener);
|
||||||
writer.removeIIOWriteProgressListener(listener);
|
writer.removeIIOWriteProgressListener(listener);
|
||||||
|
|
||||||
@ -238,25 +251,22 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveIIOWriteProgressListenerMultiple() throws IOException {
|
public void testRemoveIIOWriteProgressListenerMultiple() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
|
writer.addIIOWriteProgressListener(listener);
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listenerToo = mock(IIOWriteProgressListener.class);
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
writer.addIIOWriteProgressListener(listenerToo);
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOWriteProgressListener.class);
|
writer.removeIIOWriteProgressListener(listener);
|
||||||
mockListenerToo.stubs().method("imageStarted").withAnyArguments();
|
|
||||||
mockListenerToo.stubs().method("imageProgress").withAnyArguments();
|
|
||||||
mockListenerToo.stubs().method("imageComplete").withAnyArguments();
|
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListenerToo.proxy());
|
|
||||||
|
|
||||||
writer.removeIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.write(getTestData());
|
writer.write(getTestData());
|
||||||
@ -266,19 +276,25 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
mockListenerToo.verify();
|
|
||||||
|
// At least imageStarted and imageComplete, plus any number of imageProgress
|
||||||
|
InOrder ordered = inOrder(listenerToo);
|
||||||
|
ordered.verify(listenerToo).imageStarted(writer, 0);
|
||||||
|
ordered.verify(listenerToo, atLeastOnce()).imageProgress(eq(writer), anyInt());
|
||||||
|
ordered.verify(listenerToo).imageComplete(writer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveAllIIOWriteProgressListeners() throws IOException {
|
public void testRemoveAllIIOWriteProgressListeners() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
writer.addIIOWriteProgressListener(listener);
|
||||||
|
|
||||||
writer.removeAllIIOWriteProgressListeners();
|
writer.removeAllIIOWriteProgressListeners();
|
||||||
|
|
||||||
@ -290,20 +306,21 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveAllIIOWriteProgressListenersMultiple() throws IOException {
|
public void testRemoveAllIIOWriteProgressListenersMultiple() throws IOException {
|
||||||
ImageWriter writer = createImageWriter();
|
ImageWriter writer = createImageWriter();
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
writer.setOutput(ImageIO.createImageOutputStream(buffer));
|
||||||
|
|
||||||
|
|
||||||
Mock mockListener = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listener = mock(IIOWriteProgressListener.class);
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListener.proxy());
|
writer.addIIOWriteProgressListener(listener);
|
||||||
|
|
||||||
Mock mockListenerToo = new Mock(IIOWriteProgressListener.class);
|
IIOWriteProgressListener listenerToo = mock(IIOWriteProgressListener.class);
|
||||||
writer.addIIOWriteProgressListener((IIOWriteProgressListener) mockListenerToo.proxy());
|
writer.addIIOWriteProgressListener(listenerToo);
|
||||||
|
|
||||||
writer.removeAllIIOWriteProgressListeners();
|
writer.removeAllIIOWriteProgressListeners();
|
||||||
|
|
||||||
@ -315,8 +332,7 @@ public abstract class ImageWriterAbstractTestCase extends MockObjectTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should not have called any methods...
|
// Should not have called any methods...
|
||||||
mockListener.verify();
|
verifyZeroInteractions(listener);
|
||||||
mockListenerToo.verify();
|
verifyZeroInteractions(listenerToo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.ico;
|
package com.twelvemonkeys.imageio.plugins.ico;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.ImageReadParam;
|
import javax.imageio.ImageReadParam;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
@ -10,6 +11,8 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CURImageReaderTestCase
|
* CURImageReaderTestCase
|
||||||
*
|
*
|
||||||
@ -74,19 +77,23 @@ public class CURImageReaderTestCase extends ImageReaderAbstractTestCase<CURImage
|
|||||||
assertEquals(pExpected, reader.getHotSpot(0));
|
assertEquals(pExpected, reader.getHotSpot(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandHotspot() throws IOException {
|
public void testHandHotspot() throws IOException {
|
||||||
assertHotSpot(getTestData().get(0), null, new Point(15, 15));
|
assertHotSpot(getTestData().get(0), null, new Point(15, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testZoomHotspot() throws IOException {
|
public void testZoomHotspot() throws IOException {
|
||||||
assertHotSpot(getTestData().get(1), null, new Point(13, 11));
|
assertHotSpot(getTestData().get(1), null, new Point(13, 11));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandHotspotWithParam() throws IOException {
|
public void testHandHotspotWithParam() throws IOException {
|
||||||
ImageReadParam param = new ImageReadParam();
|
ImageReadParam param = new ImageReadParam();
|
||||||
assertHotSpot(getTestData().get(0), param, new Point(15, 15));
|
assertHotSpot(getTestData().get(0), param, new Point(15, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandHotspotExplicitDestination() throws IOException {
|
public void testHandHotspotExplicitDestination() throws IOException {
|
||||||
CURImageReader reader = createReader();
|
CURImageReader reader = createReader();
|
||||||
reader.setInput(getTestData().get(0).getInputStream());
|
reader.setInput(getTestData().get(0).getInputStream());
|
||||||
|
@ -34,7 +34,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BMPImageReaderTestCase extends JMagickImageReaderAbstractTestCase<BMPImageReader> {
|
public class BMPImageReaderTestCase extends JMagickImageReaderAbstractTestCase<BMPImageReader> {
|
||||||
private BMPImageReaderSpi mProvider = new BMPImageReaderSpi();
|
private BMPImageReaderSpi provider = new BMPImageReaderSpi();
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
@ -63,7 +63,7 @@ public class BMPImageReaderTestCase extends JMagickImageReaderAbstractTestCase<B
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected BMPImageReader createReader() {
|
protected BMPImageReader createReader() {
|
||||||
return new BMPImageReader(mProvider);
|
return new BMPImageReader(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ImageReaderSpi createProvider() {
|
protected ImageReaderSpi createProvider() {
|
||||||
|
@ -29,6 +29,10 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.jmagick;
|
package com.twelvemonkeys.imageio.plugins.jmagick;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.rules.MethodRule;
|
||||||
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import javax.imageio.ImageReader;
|
import javax.imageio.ImageReader;
|
||||||
|
|
||||||
@ -40,14 +44,20 @@ import javax.imageio.ImageReader;
|
|||||||
* @version $Id: JMagickImageReaderAbstractTestCase.java,v 1.0 Apr 1, 2008 2:59:05 PM haraldk Exp$
|
* @version $Id: JMagickImageReaderAbstractTestCase.java,v 1.0 Apr 1, 2008 2:59:05 PM haraldk Exp$
|
||||||
*/
|
*/
|
||||||
public abstract class JMagickImageReaderAbstractTestCase<T extends ImageReader> extends ImageReaderAbstractTestCase<T> {
|
public abstract class JMagickImageReaderAbstractTestCase<T extends ImageReader> extends ImageReaderAbstractTestCase<T> {
|
||||||
|
@Rule
|
||||||
@Override
|
public MethodRule rule = new MethodRule() {
|
||||||
protected void runTest() throws Throwable {
|
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
|
||||||
if (JMagickImageReaderSpiSupport.AVAILABLE) {
|
if (JMagickImageReaderSpiSupport.AVAILABLE) {
|
||||||
super.runTest();
|
return base;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
System.err.println("WARNING: JMagick not installed. Skipping test " + getName());
|
return new Statement() {
|
||||||
|
@Override
|
||||||
|
public void evaluate() throws Throwable {
|
||||||
|
// TODO: Make this increase "skipped" count, rather than run/success
|
||||||
|
System.err.println("WARNING: JMagick not installed. Skipping test " + method.getName());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- These readers/writers could probably benefit alot from using JNI with nio
|
- These readers/writers could probably benefit alot from using JNI with nio
|
||||||
bytechannel buffers... RFE to JMagick guys?
|
bytechannel buffers... RFE to JMagick guys?
|
||||||
- Create stream providers and allow creatig a ImageInputStream from a
|
- Create stream providers and allow creating an ImageInputStream from a
|
||||||
MagickImage? Does that even make sense? Or maybe create File based streams
|
MagickImage? Does that even make sense? Or maybe create File based streams
|
||||||
that exposes the file name for JMagick to write directly.
|
that exposes the file name for JMagick to write directly.
|
@ -1,6 +1,7 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.pict;
|
package com.twelvemonkeys.imageio.plugins.pict;
|
||||||
|
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -8,6 +9,8 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ICOImageReaderTestCase
|
* ICOImageReaderTestCase
|
||||||
*
|
*
|
||||||
@ -59,11 +62,12 @@ public class PICTImageReaderTestCase extends ImageReaderAbstractTestCase<PICTIma
|
|||||||
return Arrays.asList("image/pict", "image/x-pict");
|
return Arrays.asList("image/pict", "image/x-pict");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProviderNotMatchJPEG() throws IOException {
|
public void testProviderNotMatchJPEG() throws IOException {
|
||||||
// This JPEG contains PICT magic bytes at locations a PICT would normally have them.
|
// This JPEG contains PICT magic bytes at locations a PICT would normally have them.
|
||||||
// We should not claim to be able read it.
|
// We should not claim to be able read it.
|
||||||
assertFalse(sProvider.canDecodeInput(new TestData(
|
assertFalse(sProvider.canDecodeInput(
|
||||||
getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"),
|
new TestData(getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"),
|
||||||
new Dimension(386, 396)
|
new Dimension(386, 396)
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ import java.util.List;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PSDImageReaderTestCase
|
* PSDImageReaderTestCase
|
||||||
*
|
*
|
||||||
|
@ -4,13 +4,14 @@ import com.sun.imageio.plugins.jpeg.JPEGImageReader;
|
|||||||
import com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi;
|
import com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi;
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||||
import com.twelvemonkeys.lang.SystemUtil;
|
import com.twelvemonkeys.lang.SystemUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPEGImageReaderTestCase
|
* JPEGImageReaderTestCase
|
||||||
@ -67,6 +68,7 @@ public class JPEGImageReaderTestCase extends ImageReaderAbstractTestCase<JPEGIma
|
|||||||
return Arrays.asList(provider.getMIMETypes());
|
return Arrays.asList(provider.getMIMETypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testSetDestination() throws IOException {
|
public void testSetDestination() throws IOException {
|
||||||
// Known bug in Sun JPEGImageReader before Java 6
|
// Known bug in Sun JPEGImageReader before Java 6
|
||||||
@ -78,6 +80,7 @@ public class JPEGImageReaderTestCase extends ImageReaderAbstractTestCase<JPEGIma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testSetDestinationType() throws IOException {
|
public void testSetDestinationType() throws IOException {
|
||||||
// Known bug in Sun JPEGImageReader before Java 6
|
// Known bug in Sun JPEGImageReader before Java 6
|
||||||
@ -89,6 +92,7 @@ public class JPEGImageReaderTestCase extends ImageReaderAbstractTestCase<JPEGIma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testReadAsRenderedImageIndexOutOfBounds() throws IIOException {
|
public void testReadAsRenderedImageIndexOutOfBounds() throws IIOException {
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,7 @@ package com.twelvemonkeys.imageio.reference;
|
|||||||
import com.sun.imageio.plugins.png.PNGImageReader;
|
import com.sun.imageio.plugins.png.PNGImageReader;
|
||||||
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
|
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
@ -64,6 +65,7 @@ public class PNGImageReaderTestCase extends ImageReaderAbstractTestCase<PNGImage
|
|||||||
return Arrays.asList(provider.getMIMETypes());
|
return Arrays.asList(provider.getMIMETypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testSetDestinationTypeIllegal() throws IOException {
|
public void testSetDestinationTypeIllegal() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
@ -33,6 +33,7 @@ import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
|||||||
import com.twelvemonkeys.io.ole2.CompoundDocument;
|
import com.twelvemonkeys.io.ole2.CompoundDocument;
|
||||||
import com.twelvemonkeys.io.ole2.Entry;
|
import com.twelvemonkeys.io.ole2.Entry;
|
||||||
import com.twelvemonkeys.lang.SystemUtil;
|
import com.twelvemonkeys.lang.SystemUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
@ -53,7 +54,7 @@ import java.util.List;
|
|||||||
public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<ThumbsDBImageReader> {
|
public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<ThumbsDBImageReader> {
|
||||||
private static final boolean IS_JAVA_6 = SystemUtil.isClassAvailable("java.util.Deque");
|
private static final boolean IS_JAVA_6 = SystemUtil.isClassAvailable("java.util.Deque");
|
||||||
|
|
||||||
private ThumbsDBImageReaderSpi mProvider = new ThumbsDBImageReaderSpi();
|
private ThumbsDBImageReaderSpi provider = new ThumbsDBImageReaderSpi();
|
||||||
|
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
@ -82,12 +83,12 @@ public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<Thu
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ImageReaderSpi createProvider() {
|
protected ImageReaderSpi createProvider() {
|
||||||
return mProvider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThumbsDBImageReader createReader() {
|
protected ThumbsDBImageReader createReader() {
|
||||||
return new ThumbsDBImageReader(mProvider);
|
return new ThumbsDBImageReader(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class<ThumbsDBImageReader> getReaderClass() {
|
protected Class<ThumbsDBImageReader> getReaderClass() {
|
||||||
@ -106,6 +107,7 @@ public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<Thu
|
|||||||
return Arrays.asList("image/x-thumbs-db");
|
return Arrays.asList("image/x-thumbs-db");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testArrayIndexOutOfBoundsBufferedReadBug() throws IOException {
|
public void testArrayIndexOutOfBoundsBufferedReadBug() throws IOException {
|
||||||
ImageInputStream input = new BufferedImageInputStream(new MemoryCacheImageInputStream(getClass().getResourceAsStream("/thumbsdb/Thumbs-camera.db")));
|
ImageInputStream input = new BufferedImageInputStream(new MemoryCacheImageInputStream(getClass().getResourceAsStream("/thumbsdb/Thumbs-camera.db")));
|
||||||
input.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
input.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||||
@ -115,6 +117,7 @@ public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<Thu
|
|||||||
child.getInputStream();
|
child.getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testSetDestination() throws IOException {
|
public void testSetDestination() throws IOException {
|
||||||
// Known bug in Sun JPEGImageReader before Java 6
|
// Known bug in Sun JPEGImageReader before Java 6
|
||||||
@ -126,6 +129,7 @@ public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<Thu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testSetDestinationType() throws IOException {
|
public void testSetDestinationType() throws IOException {
|
||||||
// Known bug in Sun JPEGImageReader before Java 6
|
// Known bug in Sun JPEGImageReader before Java 6
|
||||||
|
@ -32,11 +32,6 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>jmock</groupId>
|
|
||||||
<artifactId>jmock-cglib</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -102,14 +97,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.3.1</version>
|
<version>4.7</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>jmock</groupId>
|
|
||||||
<artifactId>jmock-cglib</artifactId>
|
|
||||||
<version>1.0.1</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TwelveMonkeys :: Sandbox :: Common</name>
|
<name>TwelveMonkeys :: Sandbox :: Common</name>
|
||||||
<description>
|
<description>
|
||||||
The TwelveMonkeys Sandbox Common. Experimental stuff.
|
The TwelveMonkeys Common Sandbox. Experimental stuff.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -28,6 +28,12 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
|
<artifactId>imageio-core</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.common</groupId>
|
<groupId>com.twelvemonkeys.common</groupId>
|
||||||
<artifactId>common-io</artifactId>
|
<artifactId>common-io</artifactId>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TwelveMonkeys :: Sandbox :: Swing</name>
|
<name>TwelveMonkeys :: Sandbox :: Swing</name>
|
||||||
<description>
|
<description>
|
||||||
The TwelveMonkeys Sandbox Swing. Experimental stuff.
|
The TwelveMonkeys Swing Sandbox. Experimental stuff.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -81,17 +81,10 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>jmock</groupId>
|
|
||||||
<artifactId>jmock-cglib</artifactId>
|
|
||||||
<version>1.0.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<version>1.8.0</version>
|
<version>1.8.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -115,17 +115,13 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class MockFilterConfig implements FilterConfig {
|
static class MockFilterConfig implements FilterConfig {
|
||||||
private final Map mParams;
|
private final Map<String, String> params;
|
||||||
|
|
||||||
MockFilterConfig() {
|
MockFilterConfig(Map<String, String> pParams) {
|
||||||
this(new HashMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
MockFilterConfig(Map pParams) {
|
|
||||||
if (pParams == null) {
|
if (pParams == null) {
|
||||||
throw new IllegalArgumentException("params == null");
|
throw new IllegalArgumentException("params == null");
|
||||||
}
|
}
|
||||||
mParams = pParams;
|
params = pParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilterName() {
|
public String getFilterName() {
|
||||||
@ -133,11 +129,11 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getInitParameter(String pName) {
|
public String getInitParameter(String pName) {
|
||||||
return (String) mParams.get(pName);
|
return params.get(pName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumeration getInitParameterNames() {
|
public Enumeration getInitParameterNames() {
|
||||||
return Collections.enumeration(mParams.keySet());
|
return Collections.enumeration(params.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServletContext getServletContext() {
|
public ServletContext getServletContext() {
|
||||||
@ -145,20 +141,20 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class MockServletContext implements ServletContext {
|
private static class MockServletContext implements ServletContext {
|
||||||
private final Map mAttributes;
|
private final Map<String, Object> attributes;
|
||||||
private final Map mParams;
|
private final Map<String, String> params;
|
||||||
|
|
||||||
MockServletContext() {
|
MockServletContext() {
|
||||||
mAttributes = new HashMap();
|
attributes = new HashMap<String, Object>();
|
||||||
mParams = new HashMap();
|
params = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getAttribute(String s) {
|
public Object getAttribute(String s) {
|
||||||
return mAttributes.get(s);
|
return attributes.get(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumeration getAttributeNames() {
|
public Enumeration getAttributeNames() {
|
||||||
return Collections.enumeration(mAttributes.keySet());
|
return Collections.enumeration(attributes.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServletContext getContext(String s) {
|
public ServletContext getContext(String s) {
|
||||||
@ -166,11 +162,11 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getInitParameter(String s) {
|
public String getInitParameter(String s) {
|
||||||
return (String) mParams.get(s);
|
return (String) params.get(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumeration getInitParameterNames() {
|
public Enumeration getInitParameterNames() {
|
||||||
return Collections.enumeration(mParams.keySet());
|
return Collections.enumeration(params.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMajorVersion() {
|
public int getMajorVersion() {
|
||||||
@ -230,40 +226,37 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void log(Exception exception, String s) {
|
public void log(Exception exception, String s) {
|
||||||
// TODO: Implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String s) {
|
public void log(String s) {
|
||||||
// TODO: Implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String s, Throwable throwable) {
|
public void log(String s, Throwable throwable) {
|
||||||
// TODO: Implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAttribute(String s) {
|
public void removeAttribute(String s) {
|
||||||
mAttributes.remove(s);
|
attributes.remove(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAttribute(String s, Object obj) {
|
public void setAttribute(String s, Object obj) {
|
||||||
mAttributes.put(s, obj);
|
attributes.put(s, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MockServletRequest implements ServletRequest {
|
static class MockServletRequest implements ServletRequest {
|
||||||
final private Map mAttributes;
|
final private Map<String, Object> attributes;
|
||||||
|
|
||||||
public MockServletRequest() {
|
public MockServletRequest() {
|
||||||
mAttributes = new HashMap();
|
attributes = new HashMap<String, Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getAttribute(String pKey) {
|
public Object getAttribute(String pKey) {
|
||||||
return mAttributes.get(pKey);
|
return attributes.get(pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumeration getAttributeNames() {
|
public Enumeration getAttributeNames() {
|
||||||
return Collections.enumeration(mAttributes.keySet());
|
return Collections.enumeration(attributes.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCharacterEncoding() {
|
public String getCharacterEncoding() {
|
||||||
@ -331,11 +324,11 @@ public abstract class FilterAbstractTestCase extends ObjectAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAttribute(String pKey, Object pValue) {
|
public void setAttribute(String pKey, Object pValue) {
|
||||||
mAttributes.put(pKey, pValue);
|
attributes.put(pKey, pValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAttribute(String pKey) {
|
public void removeAttribute(String pKey) {
|
||||||
mAttributes.remove(pKey);
|
attributes.remove(pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package com.twelvemonkeys.servlet;
|
package com.twelvemonkeys.servlet;
|
||||||
|
|
||||||
import com.twelvemonkeys.util.MapAbstractTestCase;
|
import com.twelvemonkeys.util.MapAbstractTestCase;
|
||||||
import org.jmock.Mock;
|
import org.mockito.Mockito;
|
||||||
import org.jmock.core.Invocation;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.jmock.core.Stub;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.jmock.core.stub.CustomStub;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ServletConfigMapAdapterTestCase
|
* ServletConfigMapAdapterTestCase
|
||||||
* <p/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-servlet/src/test/java/com/twelvemonkeys/servlet/ServletHeadersMapAdapterTestCase.java#1 $
|
* @version $Id: ServletHeadersMapAdapterTestCase.java#1 $
|
||||||
*/
|
*/
|
||||||
public class ServletHeadersMapAdapterTestCase extends MapAbstractTestCase {
|
public class ServletHeadersMapAdapterTestCase extends MapAbstractTestCase {
|
||||||
private static final List<String> HEADER_VALUE_ETAG = Arrays.asList("\"1234567890abcdef\"");
|
private static final List<String> HEADER_VALUE_ETAG = Arrays.asList("\"1234567890abcdef\"");
|
||||||
@ -43,24 +44,21 @@ public class ServletHeadersMapAdapterTestCase extends MapAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map makeEmptyMap() {
|
public Map makeEmptyMap() {
|
||||||
Mock mockRequest = mock(HttpServletRequest.class);
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||||
mockRequest.stubs().method("getHeaderNames").will(returnValue(Collections.enumeration(Collections.emptyList())));
|
when(request.getHeaderNames()).thenAnswer(returnEnumeration(Collections.emptyList()));
|
||||||
mockRequest.stubs().method("getHeaders").will(returnValue(null));
|
|
||||||
|
|
||||||
return new ServletHeadersMapAdapter((HttpServletRequest) mockRequest.proxy());
|
return new ServletHeadersMapAdapter(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map makeFullMap() {
|
public Map makeFullMap() {
|
||||||
Mock mockRequest = mock(HttpServletRequest.class);
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||||
|
when(request.getHeaderNames()).thenAnswer(returnEnumeration(Arrays.asList(getSampleKeys())));
|
||||||
|
when(request.getHeaders("Date")).thenAnswer(returnEnumeration(HEADER_VALUE_DATE));
|
||||||
|
when(request.getHeaders("ETag")).thenAnswer(returnEnumeration(HEADER_VALUE_ETAG));
|
||||||
|
when(request.getHeaders("X-Foo")).thenAnswer(returnEnumeration(HEADER_VALUE_FOO));
|
||||||
|
|
||||||
mockRequest.stubs().method("getHeaderNames").will(returnEnumeration("ETag", "Date", "X-Foo"));
|
return new ServletHeadersMapAdapter(request);
|
||||||
mockRequest.stubs().method("getHeaders").with(eq("Date")).will(returnEnumeration(HEADER_VALUE_DATE));
|
|
||||||
mockRequest.stubs().method("getHeaders").with(eq("ETag")).will(returnEnumeration(HEADER_VALUE_ETAG));
|
|
||||||
mockRequest.stubs().method("getHeaders").with(eq("X-Foo")).will(returnEnumeration(HEADER_VALUE_FOO));
|
|
||||||
mockRequest.stubs().method("getHeaders").with(not(or(eq("Date"), or(eq("ETag"), eq("X-Foo"))))).will(returnValue(null));
|
|
||||||
|
|
||||||
return new ServletHeadersMapAdapter((HttpServletRequest) mockRequest.proxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,31 +71,25 @@ public class ServletHeadersMapAdapterTestCase extends MapAbstractTestCase {
|
|||||||
return new Object[] {HEADER_VALUE_DATE, HEADER_VALUE_ETAG, HEADER_VALUE_FOO};
|
return new Object[] {HEADER_VALUE_DATE, HEADER_VALUE_ETAG, HEADER_VALUE_FOO};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getNewSampleValues() {
|
public Object[] getNewSampleValues() {
|
||||||
// Needs to be same length but different values
|
// Needs to be same length but different values
|
||||||
return new Object[3];
|
return new Object[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Stub returnEnumeration(final Object... pValues) {
|
protected static <T> ReturnNewEnumeration<T> returnEnumeration(final Collection<T> collection) {
|
||||||
return new EnumerationStub(Arrays.asList(pValues));
|
return new ReturnNewEnumeration<T>(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Stub returnEnumeration(final List<?> pValues) {
|
private static class ReturnNewEnumeration<T> implements Answer<Enumeration<T>> {
|
||||||
return new EnumerationStub(pValues);
|
private final Collection<T> collection;
|
||||||
|
|
||||||
|
private ReturnNewEnumeration(final Collection<T> collection) {
|
||||||
|
this.collection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EnumerationStub extends CustomStub {
|
public Enumeration<T> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
private List<?> mValues;
|
return Collections.enumeration(collection);
|
||||||
|
|
||||||
public EnumerationStub(final List<?> pValues) {
|
|
||||||
super("Returns a new enumeration");
|
|
||||||
mValues = pValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object invoke(Invocation invocation) throws Throwable {
|
|
||||||
return Collections.enumeration(mValues);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,15 @@
|
|||||||
package com.twelvemonkeys.servlet;
|
package com.twelvemonkeys.servlet;
|
||||||
|
|
||||||
import com.twelvemonkeys.util.MapAbstractTestCase;
|
import com.twelvemonkeys.util.MapAbstractTestCase;
|
||||||
import org.jmock.Mock;
|
import org.mockito.Mockito;
|
||||||
import org.jmock.core.Invocation;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.jmock.core.Stub;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.jmock.core.stub.CustomStub;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ServletConfigMapAdapterTestCase
|
* ServletConfigMapAdapterTestCase
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -43,24 +44,22 @@ public class ServletParametersMapAdapterTestCase extends MapAbstractTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map makeEmptyMap() {
|
public Map makeEmptyMap() {
|
||||||
Mock mockRequest = mock(HttpServletRequest.class);
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||||
mockRequest.stubs().method("getParameterNames").will(returnValue(Collections.enumeration(Collections.emptyList())));
|
when(request.getParameterNames()).thenAnswer(returnEnumeration(Collections.emptyList()));
|
||||||
mockRequest.stubs().method("getParameterValues").will(returnValue(null));
|
|
||||||
|
|
||||||
return new ServletParametersMapAdapter((HttpServletRequest) mockRequest.proxy());
|
return new ServletParametersMapAdapter(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map makeFullMap() {
|
public Map makeFullMap() {
|
||||||
Mock mockRequest = mock(HttpServletRequest.class);
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||||
|
|
||||||
mockRequest.stubs().method("getParameterNames").will(returnEnumeration("tag", "date", "foo"));
|
when(request.getParameterNames()).thenAnswer(returnEnumeration(Arrays.asList("tag", "date", "foo")));
|
||||||
mockRequest.stubs().method("getParameterValues").with(eq("date")).will(returnValue(PARAM_VALUE_DATE.toArray(new String[PARAM_VALUE_DATE.size()])));
|
when(request.getParameterValues("date")).thenReturn(PARAM_VALUE_DATE.toArray(new String[PARAM_VALUE_DATE.size()]));
|
||||||
mockRequest.stubs().method("getParameterValues").with(eq("tag")).will(returnValue(PARAM_VALUE_ETAG.toArray(new String[PARAM_VALUE_ETAG.size()])));
|
when(request.getParameterValues("tag")).thenReturn(PARAM_VALUE_ETAG.toArray(new String[PARAM_VALUE_ETAG.size()]));
|
||||||
mockRequest.stubs().method("getParameterValues").with(eq("foo")).will(returnValue(PARAM_VALUE_FOO.toArray(new String[PARAM_VALUE_FOO.size()])));
|
when(request.getParameterValues("foo")).thenReturn(PARAM_VALUE_FOO.toArray(new String[PARAM_VALUE_FOO.size()]));
|
||||||
mockRequest.stubs().method("getParameterValues").with(not(or(eq("date"), or(eq("tag"), eq("foo"))))).will(returnValue(null));
|
|
||||||
|
|
||||||
return new ServletParametersMapAdapter((HttpServletRequest) mockRequest.proxy());
|
return new ServletParametersMapAdapter(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,24 +78,19 @@ public class ServletParametersMapAdapterTestCase extends MapAbstractTestCase {
|
|||||||
return new Object[3];
|
return new Object[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Stub returnEnumeration(final Object... pValues) {
|
protected static <T> ReturnNewEnumeration<T> returnEnumeration(final Collection<T> collection) {
|
||||||
return new EnumerationStub(Arrays.asList(pValues));
|
return new ReturnNewEnumeration<T>(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Stub returnEnumeration(final List<?> pValues) {
|
private static class ReturnNewEnumeration<T> implements Answer<Enumeration<T>> {
|
||||||
return new EnumerationStub(pValues);
|
private final Collection<T> collection;
|
||||||
|
|
||||||
|
private ReturnNewEnumeration(final Collection<T> collection) {
|
||||||
|
this.collection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EnumerationStub extends CustomStub {
|
public Enumeration<T> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
private List<?> mValues;
|
return Collections.enumeration(collection);
|
||||||
|
|
||||||
public EnumerationStub(final List<?> pValues) {
|
|
||||||
super("Returns a new enumeration");
|
|
||||||
mValues = pValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object invoke(Invocation invocation) throws Throwable {
|
|
||||||
return Collections.enumeration(mValues);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user