mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
Upgrade to Junit5 (#1050)
* chore: Update to junit5 for servlet package * chore: Update to junit5 for contrib package * chore: Update to junit5 for common-image package * chore: Update to junit5 for common-lang package * chore: Update to junit5 for entire project files * fix: test case for JPEGImageReaderTest failed for java 8 and 11 assertEquals was using old signature of junit4. * Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-bmp/src/test/java/com/twelvemonkeys/imageio/plugins/bmp/BMPImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageMetadataTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageWriterTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * refactor: few indentation changes and missed test case - review change related to missing test annotation - unwanted new lines inside test case - duplicate assertions * refactor: moved the lambda expression to method reference * review: testNotNullWithParameterNull catch block was never executed. Added the suggested change * Apply suggestions from code review chore: adjust suggested indentation Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageWriterAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * refactor: using assertTimeout doesnot kill the execution, even if the timeout happens. It is better to use assertTimeoutPreemptively in cases, where we really want to kill the execution after timeout. https://stackoverflow.com/questions/57116801/how-to-fail-a-test-after-a-timeout-is-exceeded-in-junit-5/57116959#57116959 --------- Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a67fdd4b80
commit
543acce8a3
@@ -31,9 +31,7 @@
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@@ -49,7 +47,7 @@ import java.util.List;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* AffineTransformOpTest.
|
||||
@@ -146,12 +144,12 @@ public class AffineTransformOpTest {
|
||||
BufferedImage jreResult = jreOp.filter(image, null);
|
||||
BufferedImage tmResult = tmOp.filter(image, null);
|
||||
|
||||
assertNotNull("No result!", tmResult);
|
||||
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
|
||||
assertNotNull(tmResult, "No result!");
|
||||
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +162,7 @@ public class AffineTransformOpTest {
|
||||
BufferedImage image = spec.createBufferedImage(width, height);
|
||||
|
||||
BufferedImage tmResult = tmOp.filter(image, null);
|
||||
assertNotNull("No result!", tmResult);
|
||||
assertNotNull(tmResult, "No result!");
|
||||
|
||||
BufferedImage jreResult = null;
|
||||
|
||||
@@ -176,18 +174,18 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
|
||||
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Bad type", spec.getBufferedImageType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", spec.getColorModel(), tmResult.getColorModel());
|
||||
assertEquals(spec.getBufferedImageType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(spec.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,12 +234,12 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,12 +275,12 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,17 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.color.*;
|
||||
import java.awt.image.*;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BufferedImageFactoryTestCase
|
||||
@@ -50,50 +49,58 @@ import static org.junit.Assert.assertTrue;
|
||||
* @version $Id: BufferedImageFactoryTestCase.java,v 1.0 May 7, 2010 12:40:08 PM haraldk Exp$
|
||||
*/
|
||||
public class BufferedImageFactoryTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullImage() {
|
||||
new BufferedImageFactory((Image) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory((Image) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullProducer() {
|
||||
new BufferedImageFactory((ImageProducer) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory((ImageProducer) null);
|
||||
});
|
||||
}
|
||||
|
||||
// NPE in Toolkit, ok
|
||||
@Test(expected = RuntimeException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceByteArray() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
|
||||
|
||||
new BufferedImageFactory(source);
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
|
||||
new BufferedImageFactory(source);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceImageProducer() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((ImageProducer) null);
|
||||
|
||||
new BufferedImageFactory(source);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory(source);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: This is a quite serious bug, however, the bug is in the Toolkit, allowing such images in the first place...
|
||||
// In any case, there's not much we can do, except until someone is bored and kills the app/thread... :-P
|
||||
@Ignore("Bug in Toolkit")
|
||||
@Test(timeout = 1000, expected = ImageConversionException.class)
|
||||
@Disabled("Bug in Toolkit")
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceString() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
factory.getBufferedImage();
|
||||
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
assertThrows(ImageConversionException.class, factory::getBufferedImage);
|
||||
});
|
||||
}
|
||||
|
||||
// This is a little random, and it would be nicer if we could throw an IllegalArgumentException on create.
|
||||
// Unfortunately, the API doesn't allow this...
|
||||
@Test(timeout = 1000, expected = ImageConversionException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceURL() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/META-INF/MANIFEST.MF"));
|
||||
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
factory.getBufferedImage();
|
||||
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
assertThrows(ImageConversionException.class, factory::getBufferedImage);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +172,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
assertEquals(3, colorModel.getNumColorComponents());
|
||||
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
|
||||
assertTrue(colorModel instanceof IndexColorModel);
|
||||
assertInstanceOf(IndexColorModel.class, colorModel);
|
||||
|
||||
assertTrue(colorModel.hasAlpha());
|
||||
assertEquals(4, colorModel.getNumComponents());
|
||||
@@ -196,7 +203,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(x * 2, y * 2), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x * 2, y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +226,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x, 40 + y), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(40 + x, 40 + y), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,7 +250,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -39,7 +39,7 @@ import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ImageUtilTest {
|
||||
|
||||
@@ -116,8 +116,8 @@ public class ImageUtilTest {
|
||||
public void testImageIsNotBufferedImage() {
|
||||
// Should not be a buffered image
|
||||
assertFalse(
|
||||
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too.",
|
||||
scaled instanceof BufferedImage
|
||||
scaled instanceof BufferedImage,
|
||||
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class ImageUtilTest {
|
||||
if (original != notContrasted) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 constrast should not change image", original.getRGB(x, y), notContrasted.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notContrasted.getRGB(x, y), "0 constrast should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,24 +275,24 @@ public class ImageUtilTest {
|
||||
|
||||
// RED
|
||||
if (oR < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oR >= cR && cR >= dR);
|
||||
assertTrue(oR >= cR && cR >= dR, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oR <= cR && cR <= dR);
|
||||
assertTrue(oR <= cR && cR <= dR, "Contrast should be increased or same");
|
||||
}
|
||||
// GREEN
|
||||
if (oG < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oG >= cG && cG >= dG);
|
||||
assertTrue(oG >= cG && cG >= dG, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oG <= cG && cG <= dG);
|
||||
assertTrue(oG <= cG && cG <= dG, "Contrast should be increased or same");
|
||||
}
|
||||
// BLUE
|
||||
if (oB < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oB >= cB && cB >= dB);
|
||||
assertTrue(oB >= cB && cB >= dB, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oB <= cB && cB <= dB);
|
||||
assertTrue(oB <= cB && cB <= dB, "Contrast should be increased or same");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,9 +304,9 @@ public class ImageUtilTest {
|
||||
int r = rgb >> 16 & 0xFF;
|
||||
int g = rgb >> 8 & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
assertTrue("Max contrast should only produce primary colors", r == 0 || r == 255);
|
||||
assertTrue("Max contrast should only produce primary colors", g == 0 || g == 255);
|
||||
assertTrue("Max contrast should only produce primary colors", b == 0 || b == 255);
|
||||
assertTrue(r == 0 || r == 255, "Max contrast should only produce primary colors");
|
||||
assertTrue(g == 0 || g == 255, "Max contrast should only produce primary colors");
|
||||
assertTrue(b == 0 || b == 255, "Max contrast should only produce primary colors");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,24 +327,24 @@ public class ImageUtilTest {
|
||||
|
||||
// RED
|
||||
if (oR >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oR >= cR);
|
||||
assertTrue(oR >= cR, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oR <= cR);
|
||||
assertTrue(oR <= cR, "Contrast should be increased or same");
|
||||
}
|
||||
// GREEN
|
||||
if (oG >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oG >= cG);
|
||||
assertTrue(oG >= cG, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oG <= cG);
|
||||
assertTrue(oG <= cG, "Contrast should be increased or same");
|
||||
}
|
||||
// BLUE
|
||||
if (oB >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oB >= cB);
|
||||
assertTrue(oB >= cB, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oB <= cB);
|
||||
assertTrue(oB <= cB, "Contrast should be increased or same");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public class ImageUtilTest {
|
||||
int r = rgb >> 16 & 0xFF;
|
||||
int g = rgb >> 8 & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
assertTrue("Minimum contrast should be all gray", r == 127 && g == 127 && b == 127);
|
||||
assertTrue(r == 127 && g == 127 && b == 127, "Minimum contrast should be all gray");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class ImageUtilTest {
|
||||
if (original != notSharpened) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 sharpen should not change image", original.getRGB(x, y), notSharpened.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notSharpened.getRGB(x, y), "0 sharpen should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,13 +446,13 @@ public class ImageUtilTest {
|
||||
}
|
||||
|
||||
// assertEquals("Difference should not change", diffOriginal, diffSharpened);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffSharpened);
|
||||
assertTrue(absDiffOriginal < absDiffSharpened, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffDefault);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffDefault);
|
||||
assertTrue(absDiffOriginal < absDiffDefault, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffMore);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffMore);
|
||||
assertTrue(absDiffOriginal < absDiffMore, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffSharpened, diffMore);
|
||||
assertTrue("Abs difference should increase", absDiffSharpened < absDiffMore);
|
||||
assertTrue(absDiffSharpened < absDiffMore, "Abs difference should increase");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +466,7 @@ public class ImageUtilTest {
|
||||
if (original != notBlurred) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 blur should not change image", original.getRGB(x, y), notBlurred.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notBlurred.getRGB(x, y), "0 blur should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -512,13 +512,13 @@ public class ImageUtilTest {
|
||||
}
|
||||
|
||||
// assertEquals("Difference should not change", diffOriginal, diffBlurred);
|
||||
assertTrue(String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred), absDiffOriginal > absDiffBlurred);
|
||||
assertTrue(absDiffOriginal > absDiffBlurred, String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred));
|
||||
// assertEquals("Difference should not change", diffOriginal, diffDefault);
|
||||
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffDefault);
|
||||
assertTrue(absDiffOriginal > absDiffDefault, "Abs difference should decrease");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffMore);
|
||||
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffMore);
|
||||
assertTrue(absDiffOriginal > absDiffMore, "Abs difference should decrease");
|
||||
// assertEquals("Difference should not change", diffBlurred, diffMore);
|
||||
assertTrue("Abs difference should decrease", absDiffBlurred > absDiffMore);
|
||||
assertTrue(absDiffBlurred > absDiffMore, "Abs difference should decrease");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -528,7 +528,7 @@ public class ImageUtilTest {
|
||||
assertNotNull(sunflower);
|
||||
|
||||
BufferedImage image = ImageUtil.createIndexed(sunflower);
|
||||
assertNotNull("Image was null", image);
|
||||
assertTrue(image.getColorModel() instanceof IndexColorModel);
|
||||
assertNotNull(image, "Image was null");
|
||||
assertInstanceOf(IndexColorModel.class, image.getColorModel());
|
||||
}
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -40,7 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ResampleOpTestCase
|
||||
@@ -124,7 +124,7 @@ public class ResampleOpTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Filter threw exceptions: ", Collections.EMPTY_LIST, exceptions);
|
||||
assertEquals(Collections.EMPTY_LIST, exceptions, "Filter threw exceptions: ");
|
||||
}
|
||||
|
||||
// 1x1
|
||||
@@ -358,7 +358,7 @@ public class ResampleOpTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Not for general unit testing")
|
||||
@Disabled("Not for general unit testing")
|
||||
@Test
|
||||
public void testTime() {
|
||||
int iterations = 1000;
|
||||
|
@@ -32,7 +32,6 @@ package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
import com.twelvemonkeys.util.CollectionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@@ -40,7 +39,8 @@ import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CompoundReaderTestCase
|
||||
|
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* FastByteArrayOutputStreamTestCase
|
||||
|
@@ -30,11 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* MemoryCacheSeekableStreamTestCase
|
||||
@@ -92,13 +91,13 @@ public class FileSeekableStreamTest extends SeekableInputStreamAbstractTest {
|
||||
try {
|
||||
FileUtil.read(stream); // Read until EOF
|
||||
|
||||
assertEquals("EOF not reached (test case broken)", -1, stream.read());
|
||||
assertFalse("Underlying stream closed before close", closed[0]);
|
||||
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
|
||||
assertFalse(closed[0], "Underlying stream closed before close");
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
assertTrue("Underlying stream not closed", closed[0]);
|
||||
assertTrue(closed[0], "Underlying stream not closed");
|
||||
}
|
||||
}
|
||||
|
@@ -46,14 +46,14 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* InputStreamAbstractTestCase
|
||||
@@ -104,15 +104,15 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
int size = 5;
|
||||
InputStream input = makeInputStream(makeOrderedArray(size));
|
||||
for (int i = 0; i < size; i++) {
|
||||
assertTrue("Check Size [" + i + "]", (size - i) >= input.available());
|
||||
assertEquals("Check Value [" + i + "]", i, input.read());
|
||||
assertTrue((size - i) >= input.available(), "Check Size [" + i + "]");
|
||||
assertEquals(i, input.read(), "Check Value [" + i + "]");
|
||||
}
|
||||
assertEquals("Available after contents all read", 0, input.available());
|
||||
assertEquals(0, input.available(), "Available after contents all read");
|
||||
|
||||
// Test reading after the end of file
|
||||
try {
|
||||
int result = input.read();
|
||||
assertEquals("Wrong value read after end of file", -1, result);
|
||||
assertEquals( -1, result, "Wrong value read after end of file");
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail("Should not have thrown an IOException: " + e.getMessage());
|
||||
@@ -122,12 +122,12 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testAvailable() throws Exception {
|
||||
InputStream input = makeInputStream(1);
|
||||
assertFalse("Unexpected EOF", input.read() < 0);
|
||||
assertEquals("Available after contents all read", 0, input.available());
|
||||
assertFalse(input.read() < 0, "Unexpected EOF");
|
||||
assertEquals(0, input.available(), "Available after contents all read");
|
||||
|
||||
// Check availbale is zero after End of file
|
||||
assertEquals("End of File", -1, input.read());
|
||||
assertEquals("Available after End of File", 0, input.available());
|
||||
assertEquals(-1, input.read(), "End of File");
|
||||
assertEquals( 0, input.available(), "Available after End of File");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,26 +138,26 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read into array
|
||||
int count1 = input.read(bytes);
|
||||
assertEquals("Read 1", bytes.length, count1);
|
||||
assertEquals(bytes.length, count1, "Read 1");
|
||||
for (int i = 0; i < count1; i++) {
|
||||
assertEquals("Check Bytes 1", i, bytes[i]);
|
||||
assertEquals(i, bytes[i], "Check Bytes 1");
|
||||
}
|
||||
|
||||
// Read into array
|
||||
int count2 = input.read(bytes);
|
||||
assertEquals("Read 2", 5, count2);
|
||||
assertEquals(5, count2, "Read 2");
|
||||
for (int i = 0; i < count2; i++) {
|
||||
assertEquals("Check Bytes 2", count1 + i, bytes[i]);
|
||||
assertEquals(count1 + i, bytes[i], "Check Bytes 2");
|
||||
}
|
||||
|
||||
// End of File
|
||||
int count3 = input.read(bytes);
|
||||
assertEquals("Read 3 (EOF)", -1, count3);
|
||||
assertEquals(-1, count3, "Read 3 (EOF)");
|
||||
|
||||
// Test reading after the end of file
|
||||
try {
|
||||
int result = input.read(bytes);
|
||||
assertEquals("Wrong value read after end of file", -1, result);
|
||||
assertEquals(-1, result, "Wrong value read after end of file");
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail("Should not have thrown an IOException: " + e.getMessage());
|
||||
@@ -170,20 +170,20 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
int offset = 2;
|
||||
int lth = 4;
|
||||
int count5 = input.read(bytes, offset, lth);
|
||||
assertEquals("Read 5", lth, count5);
|
||||
assertEquals(lth, count5, "Read 5");
|
||||
for (int i = offset; i < lth; i++) {
|
||||
assertEquals("Check Bytes 2", i - offset, bytes[i]);
|
||||
assertEquals(i - offset, bytes[i], "Check Bytes 2");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOF() throws Exception {
|
||||
InputStream input = makeInputStream(makeOrderedArray(2));
|
||||
assertEquals("Read 1", 0, input.read());
|
||||
assertEquals("Read 2", 1, input.read());
|
||||
assertEquals("Read 3", -1, input.read());
|
||||
assertEquals("Read 4", -1, input.read());
|
||||
assertEquals("Read 5", -1, input.read());
|
||||
assertEquals(0, input.read(), "Read 1");
|
||||
assertEquals(1, input.read(), "Read 2");
|
||||
assertEquals(-1, input.read(), "Read 3");
|
||||
assertEquals(-1, input.read(), "Read 4");
|
||||
assertEquals(-1, input.read(), "Read 5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,7 +205,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
fail("Should throw IOException");
|
||||
}
|
||||
catch (IOException e) {
|
||||
assertTrue("Wrong messge: " + e.getMessage(), e.getMessage().contains("reset"));
|
||||
assertTrue(e.getMessage().contains("reset"), "Wrong messge: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,10 +223,10 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
// No mark may either throw exception, or reset to beginning of stream.
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be same", 0, input.read());
|
||||
assertEquals(0, input.read(), "Re-read of reset data should be same");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong no mark IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong no mark IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read further
|
||||
for (int i = 0; i < 3; i++) {
|
||||
assertEquals("Read After Mark [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Mark [" + i + "]");
|
||||
}
|
||||
|
||||
// Reset
|
||||
@@ -257,7 +257,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read from marked position
|
||||
for (int i = 0; i < readlimit + 1; i++) {
|
||||
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,16 +280,16 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read past marked position
|
||||
for (int i = 0; i < readlimit + 1; i++) {
|
||||
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
|
||||
}
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last mark
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be same", 1, input.read());
|
||||
assertEquals(1, input.read(), "Re-read of reset data should be same");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,29 +302,29 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
|
||||
int first = input.read();
|
||||
assertTrue("Expected to read positive value", first >= 0);
|
||||
assertTrue(first >= 0, "Expected to read positive value");
|
||||
|
||||
int readlimit = 5;
|
||||
|
||||
// Mark
|
||||
input.mark(readlimit);
|
||||
int read = input.read();
|
||||
assertTrue("Expected to read positive value", read >= 0);
|
||||
assertTrue(read >= 0, "Expected to read positive value");
|
||||
|
||||
assertTrue(input.read() >= 0);
|
||||
assertTrue(input.read() >= 0);
|
||||
|
||||
input.reset();
|
||||
assertEquals("Expected value read differs from actual", read, input.read());
|
||||
assertEquals(read, input.read(), "Expected value read differs from actual");
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last good mark
|
||||
try {
|
||||
input.reset();
|
||||
int reRead = input.read();
|
||||
assertTrue("Re-read of reset data should be same as initially marked or first", reRead == read || reRead == first);
|
||||
assertTrue(reRead == read || reRead == first, "Re-read of reset data should be same as initially marked or first");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,17 +332,17 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
public void testSkip() throws Exception {
|
||||
InputStream input = makeInputStream(makeOrderedArray(10));
|
||||
|
||||
assertEquals("Unexpected value read", 0, input.read());
|
||||
assertEquals("Unexpected value read", 1, input.read());
|
||||
assertEquals("Unexpected number of bytes skipped", 5, input.skip(5));
|
||||
assertEquals("Unexpected value read", 7, input.read());
|
||||
assertEquals(0, input.read(), "Unexpected value read");
|
||||
assertEquals(1, input.read(), "Unexpected value read");
|
||||
assertEquals(5, input.skip(5), "Unexpected number of bytes skipped");
|
||||
assertEquals(7, input.read(), "Unexpected value read");
|
||||
|
||||
assertEquals("Unexpected number of bytes skipped", 2, input.skip(5)); // only 2 left to skip
|
||||
assertEquals("Unexpected value read after EOF", -1, input.read());
|
||||
assertEquals(2, input.skip(5), "Unexpected number of bytes skipped"); // only 2 left to skip
|
||||
assertEquals(-1, input.read(), "Unexpected value read after EOF");
|
||||
|
||||
// Spec says skip might return 0 or negative after EOF...
|
||||
assertTrue("Positive value skipped after EOF", input.skip(5) <= 0); // End of file
|
||||
assertEquals("Unexpected value read after EOF", -1, input.read());
|
||||
assertTrue(input.skip(5) <= 0, "Positive value skipped after EOF"); // End of file
|
||||
assertEquals(-1, input.read(), "Unexpected value read after EOF");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* LittleEndianDataInputStreamTest
|
||||
|
@@ -31,13 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* InputStreamAbstractTestCase
|
||||
|
@@ -31,12 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ReaderAbstractTestCase
|
||||
@@ -112,7 +112,7 @@ public abstract class ReaderAbstractTest extends ObjectAbstractTest {
|
||||
int toSkip = mInput.length();
|
||||
while (toSkip > 0) {
|
||||
long skipped = reader.skip(toSkip);
|
||||
assertFalse("Skipped < 0", skipped < 0);
|
||||
assertFalse(skipped < 0, "Skipped < 0");
|
||||
toSkip -= skipped;
|
||||
}
|
||||
|
||||
|
@@ -30,10 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SeekableAbstractTestCase
|
||||
|
@@ -30,14 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SeekableInputStreamAbstractTest
|
||||
@@ -79,25 +78,25 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
return; // Not supported, skip test
|
||||
}
|
||||
|
||||
assertTrue("Expected to read positive value", input.read() >= 0);
|
||||
assertTrue(input.read() >= 0, "Expected to read positive value");
|
||||
|
||||
int readlimit = 5;
|
||||
|
||||
// Mark
|
||||
input.mark(readlimit);
|
||||
int read = input.read();
|
||||
assertTrue("Expected to read positive value", read >= 0);
|
||||
assertTrue(read >= 0, "Expected to read positive value");
|
||||
|
||||
input.reset();
|
||||
assertEquals("Expected value read differs from actual", read, input.read());
|
||||
assertEquals(read, input.read(), "Expected value read differs from actual");
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last good mark
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be first", 0, input.read());
|
||||
assertEquals(0, input.read(), "Re-read of reset data should be first");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +126,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
|
||||
seekable.seek(pos);
|
||||
long streamPos = seekable.getStreamPosition();
|
||||
assertEquals("Stream positon should match seeked position", pos, streamPos);
|
||||
assertEquals(pos, streamPos, "Stream positon should match seeked position");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +136,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
seekable.seek(pos);
|
||||
seekable.flushBefore(pos);
|
||||
long flushedPos = seekable.getFlushedPosition();
|
||||
assertEquals("Flushed positon should match position", pos, flushedPos);
|
||||
assertEquals(pos, flushedPos, "Flushed positon should match position");
|
||||
|
||||
try {
|
||||
seekable.seek(pos - 1);
|
||||
@@ -382,13 +381,13 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
int val;
|
||||
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
|
||||
stream.seek(0);
|
||||
|
||||
@@ -422,19 +421,19 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
|
||||
stream.seek(0);
|
||||
for (int i = 0; i < bytes.length; i += 2) {
|
||||
assertEquals("Wrong stream position", i, stream.getStreamPosition());
|
||||
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
|
||||
int count = stream.read(buffer, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], buffer[0]);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i + 1], buffer[1]);
|
||||
assertEquals(bytes[i], buffer[0], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
assertEquals(bytes[i + 1], buffer[1], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
}
|
||||
|
||||
stream.seek(0);
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
assertEquals("Wrong stream position", i, stream.getStreamPosition());
|
||||
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
|
||||
int actual = stream.read();
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i] & 0xff, actual);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], (byte) actual);
|
||||
assertEquals(bytes[i] & 0xff, actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
assertEquals(bytes[i], (byte) actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -456,14 +455,14 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
try {
|
||||
FileUtil.read(stream); // Read until EOF
|
||||
|
||||
assertEquals("EOF not reached (test case broken)", -1, stream.read());
|
||||
assertFalse("Underlying stream closed before close", closed[0]);
|
||||
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
|
||||
assertFalse(closed[0], "Underlying stream closed before close");
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
assertTrue("Underlying stream not closed", closed[0]);
|
||||
assertTrue(closed[0], "Underlying stream not closed");
|
||||
|
||||
}
|
||||
|
||||
|
@@ -31,12 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* StringArrayReaderTestCase
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SubStreamTest.
|
||||
@@ -23,14 +22,18 @@ public class SubStreamTest {
|
||||
private final Random rng = new Random(2918475687L);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullStream() {
|
||||
new SubStream(null, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubStream(null, 42);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNegativeLength() {
|
||||
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,15 +103,17 @@ public class SubStreamTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("EmptyTryBlock")
|
||||
@Test(timeout = 500L)
|
||||
@Test
|
||||
public void testCloseConsumesAllShortStream() throws IOException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
|
||||
assertTimeoutPreemptively(Duration.ofMillis(500), () -> {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
|
||||
|
||||
try (InputStream ignore = new SubStream(stream, 42)) {
|
||||
// Nothing here...
|
||||
}
|
||||
try (InputStream ignore = new SubStream(stream, 42)) {
|
||||
// Nothing here...
|
||||
}
|
||||
|
||||
assertEquals(0, stream.available());
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(0, stream.available());
|
||||
assertEquals(-1, stream.read());
|
||||
});
|
||||
}
|
||||
}
|
@@ -31,15 +31,13 @@
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* Base64DecoderTest
|
||||
* <p/>
|
||||
@@ -66,7 +64,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
|
||||
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +76,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match", "test", new String(bytes.toByteArray()));
|
||||
assertEquals("test", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,11 +91,12 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match",
|
||||
assertEquals(
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing " +
|
||||
"elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " +
|
||||
"dapibus laoreet purus. Nunc viverra dictum nisl. Integer " +
|
||||
"ullamcorper, nisi in dictum amet.",
|
||||
new String(bytes.toByteArray()));
|
||||
new String(bytes.toByteArray()),
|
||||
"Strings does not match");
|
||||
}
|
||||
}
|
@@ -30,13 +30,12 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Base64EncoderTest
|
||||
@@ -63,7 +62,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
|
||||
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,7 +73,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray()));
|
||||
assertEquals("dGVzdA==", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,11 +87,12 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match",
|
||||
assertEquals(
|
||||
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" +
|
||||
"c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" +
|
||||
"b3JlZXQgcHVydXMuIE51bmMgdml2ZXJyYSBkaWN0dW0gbmlzbC4gSW50ZWdlciB1bGxhbWNvcnBlciwg" +
|
||||
"bmlzaSBpbiBkaWN0dW0gYW1ldC4=",
|
||||
new String(bytes.toByteArray()));
|
||||
new String(bytes.toByteArray()),
|
||||
"Strings does not match");
|
||||
}
|
||||
}
|
||||
|
@@ -32,12 +32,13 @@ package com.twelvemonkeys.io.enc;
|
||||
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractDecoderTest
|
||||
@@ -55,13 +56,13 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
return createDecoder();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public final void testNullDecode() throws IOException {
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]);
|
||||
|
||||
decoder.decode(bytes, null);
|
||||
fail("null should throw NullPointerException");
|
||||
assertThrows(NullPointerException.class, () -> {
|
||||
decoder.decode(bytes, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +72,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
try {
|
||||
int count = decoder.decode(bytes, ByteBuffer.allocate(128));
|
||||
assertEquals("Should not be able to read any bytes", 0, count);
|
||||
assertEquals( 0, count, "Should not be able to read any bytes");
|
||||
}
|
||||
catch (EOFException allowed) {
|
||||
// Okay
|
||||
@@ -94,7 +95,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
byte[] encoded = outBytes.toByteArray();
|
||||
|
||||
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createDecoder()));
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
|
||||
|
||||
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createDecoder());
|
||||
outBytes = new ByteArrayOutputStream();
|
||||
@@ -103,7 +104,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
in.close();
|
||||
|
||||
decoded = outBytes.toByteArray();
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -30,7 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -39,7 +38,8 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DecoderStreamTest {
|
||||
|
||||
|
@@ -33,13 +33,12 @@ package com.twelvemonkeys.io.enc;
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractEncoderTest
|
||||
|
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -39,7 +37,8 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class EncoderStreamTest {
|
||||
|
||||
|
@@ -31,9 +31,9 @@
|
||||
package com.twelvemonkeys.io.ole2;
|
||||
|
||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -43,8 +43,8 @@ import java.nio.ByteOrder;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* CompoundDocumentTestCase
|
||||
*
|
||||
@@ -59,8 +59,8 @@ public class CompoundDocumentTest {
|
||||
protected final CompoundDocument createTestDocument() throws IOException {
|
||||
URL input = getClass().getResource(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertEquals("Test resource not a file:// resource", "file", input.getProtocol());
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
assertEquals( "file", input.getProtocol(), "Test resource not a file:// resource");
|
||||
|
||||
try {
|
||||
return new CompoundDocument(new File(input.toURI()));
|
||||
@@ -103,7 +103,7 @@ public class CompoundDocumentTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void testChildEntriesUnmodifiable() throws IOException {
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -111,9 +111,10 @@ public class CompoundDocumentTest {
|
||||
assertNotNull(root);
|
||||
|
||||
SortedSet<Entry> children = root.getChildEntries();
|
||||
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ public class CompoundDocumentTest {
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ public class CompoundDocumentTest {
|
||||
public void testReadCatalogInputStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
CompoundDocument document = new CompoundDocument(input);
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -145,14 +146,14 @@ public class CompoundDocumentTest {
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadCatalogSeekableStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input));
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -161,14 +162,14 @@ public class CompoundDocumentTest {
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadCatalogImageInputStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
MemoryCacheImageInputStream stream = new MemoryCacheImageInputStream(input);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -183,6 +184,6 @@ public class CompoundDocumentTest {
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@
|
||||
package com.twelvemonkeys.io.ole2;
|
||||
|
||||
import com.twelvemonkeys.io.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
|
@@ -33,7 +33,6 @@ package com.twelvemonkeys.io.ole2;
|
||||
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
||||
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
|
||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -42,7 +41,8 @@ import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CompoundDocument_StreamTestCase
|
||||
@@ -165,8 +165,8 @@ public class CompoundDocument_StreamTest extends InputStreamAbstractTest {
|
||||
count++;
|
||||
}
|
||||
|
||||
assertFalse("Short stream", count < 32);
|
||||
assertFalse("Stream overrun", count > 32);
|
||||
assertFalse(count < 32, "Short stream");
|
||||
assertFalse(count > 32, "Stream overrun");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -30,9 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* HTTPUtilTest
|
||||
|
@@ -30,14 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BeanUtilTestCase
|
||||
@@ -161,10 +160,8 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
"one", bean.getAmbiguous());
|
||||
assertSame("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals("one", bean.getAmbiguous(), "String converted rather than invoking setAmbiguous(String), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(), "String converted rather than invoking setAmbiguous(String), ordering not predictable");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,10 +181,10 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
2, bean.getAmbiguous());
|
||||
assertSame("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals(2, bean.getAmbiguous(),
|
||||
"Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(),
|
||||
"Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,10 +204,8 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value.getClass(), bean.getAmbiguous().getClass());
|
||||
assertSame("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals(value.getClass(), bean.getAmbiguous().getClass(), "Object converted rather than invoking setAmbiguous(Object), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(), "Object converted rather than invoking setAmbiguous(Object), ordering not predictable");
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
|
@@ -30,16 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* DateUtilTest
|
||||
@@ -48,12 +48,9 @@ import static org.junit.Assert.assertEquals;
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: DateUtilTest.java,v 1.0 11.04.12 16:21 haraldk Exp$
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
|
||||
public class DateUtilTest {
|
||||
|
||||
private final TimeZone timeZone;
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static List<Object[]> timeZones() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{TimeZone.getTimeZone("UTC")},
|
||||
@@ -62,10 +59,6 @@ public class DateUtilTest {
|
||||
});
|
||||
}
|
||||
|
||||
public DateUtilTest(final TimeZone timeZone) {
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
private Calendar getCalendar(long time) {
|
||||
return getCalendar(time, TimeZone.getDefault());
|
||||
}
|
||||
@@ -101,8 +94,9 @@ public class DateUtilTest {
|
||||
assertEquals(0, calendar.get(Calendar.MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundToHourTZ() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("timeZones")
|
||||
public void testRoundToHourTZ(TimeZone timeZone) {
|
||||
Calendar calendar = getCalendar(DateUtil.roundToHour(System.currentTimeMillis(), timeZone), timeZone);
|
||||
|
||||
assertEquals(0, calendar.get(Calendar.MILLISECOND));
|
||||
@@ -120,8 +114,9 @@ public class DateUtilTest {
|
||||
assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundToDayTZ() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("timeZones")
|
||||
public void testRoundToDayTZ(TimeZone timeZone) {
|
||||
Calendar calendar = getCalendar(DateUtil.roundToDay(System.currentTimeMillis(), timeZone), timeZone);
|
||||
|
||||
assertEquals(0, calendar.get(Calendar.MILLISECOND));
|
||||
|
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractObjectTestCase
|
||||
@@ -79,10 +78,10 @@ public abstract class ObjectAbstractTest {
|
||||
|
||||
Class cl = obj.getClass();
|
||||
if (isEqualsOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl));
|
||||
assertTrue(isHashCodeOverriden(cl), "Class " + cl.getName() + " implements equals but not hashCode");
|
||||
}
|
||||
else if (isHashCodeOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl));
|
||||
assertTrue(isEqualsOverriden(cl), "Class " + cl.getName() + " implements hashCode but not equals");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("An Object should equal itself", obj, obj);
|
||||
assertEquals(obj, obj, "An Object should equal itself");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,32 +114,26 @@ public abstract class ObjectAbstractTest {
|
||||
Object obj = makeObject();
|
||||
// NOTE: Makes sure this doesn't throw NPE either
|
||||
//noinspection ObjectEqualsNull
|
||||
assertFalse("An object should never equal null", obj.equals(null));
|
||||
assertFalse(obj.equals(null), "An object should never equal null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
assertEquals(obj.hashCode(), obj.hashCode(), "hashCode should be repeatable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
assertEquals(obj1.hashCode(), obj1.hashCode(), "[1] When two objects are equal, their hashCodes should be also.");
|
||||
}
|
||||
// TODO: Make sure we create at least one equal object, and one different object
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
assertEquals(obj1.hashCode(), obj2.hashCode(), "[2] When two objects are equal, their hashCodes should be also.");
|
||||
assertTrue(obj2.equals(obj1), "When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,14 +162,14 @@ public abstract class ObjectAbstractTest {
|
||||
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
assertNotNull(cloned, "Cloned object should never be null");
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isHashCodeOverriden(cl)) {
|
||||
assertEquals("Cloned object not equal", obj, cloned);
|
||||
assertEquals(obj, cloned, "Cloned object not equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +228,7 @@ public abstract class ObjectAbstractTest {
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isEqualsOverriden(obj.getClass())) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
assertEquals(obj, dest, "obj != deserialize(serialize(obj))");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PlatformTest
|
||||
@@ -121,7 +119,7 @@ public class PlatformTest {
|
||||
assertEquals(Platform.Architecture.X86, platform.getArchitecture());
|
||||
}
|
||||
|
||||
@Ignore("Known issue, needs resolve")
|
||||
@Disabled("Known issue, needs resolve")
|
||||
@Test
|
||||
public void testCreateWindows686() {
|
||||
Platform platform = new Platform(createProperties("Windows", "5.1", "686"));
|
||||
@@ -129,7 +127,7 @@ public class PlatformTest {
|
||||
assertEquals(Platform.Architecture.X86, platform.getArchitecture());
|
||||
}
|
||||
|
||||
@Ignore("Known issue, needs resolve")
|
||||
@Disabled("Known issue, needs resolve")
|
||||
@Test
|
||||
public void testCreateLinuxX86() {
|
||||
Platform platform = new Platform(createProperties("Linux", "3.0.18", "x86"));
|
||||
|
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
@@ -41,8 +39,8 @@ import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* StringUtilTestCase
|
||||
*
|
||||
@@ -165,10 +163,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if (TEST_STRING.indexOf(i) < 0) {
|
||||
assertFalse(TEST_STRING + " seems to contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.contains(TEST_STRING, i));
|
||||
assertFalse(StringUtil.contains(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.contains(TEST_STRING, i));
|
||||
assertTrue(StringUtil.contains(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,10 +197,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertFalse(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), StringUtil.containsIgnoreCase(TEST_STRING, i));
|
||||
assertFalse(StringUtil.containsIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.containsIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(StringUtil.containsIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,10 +348,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.indexOfIgnoreCase(TEST_STRING, i));
|
||||
assertEquals(-1, StringUtil.indexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,10 +383,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0));
|
||||
assertEquals(-1, StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0));
|
||||
assertTrue(0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,10 +418,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i));
|
||||
assertEquals(-1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,10 +453,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()));
|
||||
assertEquals(-1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()));
|
||||
assertTrue(0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
|
||||
/**
|
||||
* SystemUtilTest
|
||||
@@ -39,6 +39,6 @@ import org.junit.Ignore;
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: SystemUtilTest.java,v 1.0 11.04.12 16:21 haraldk Exp$
|
||||
*/
|
||||
@Ignore
|
||||
@Disabled
|
||||
public class SystemUtilTest {
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -45,12 +45,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link java.util.Collection} methods and contracts.
|
||||
@@ -251,11 +250,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
*/
|
||||
public void verifyAll() {
|
||||
int confirmedSize = confirmed.size();
|
||||
assertEquals("Collection size should match confirmed collection's",
|
||||
confirmedSize, collection.size());
|
||||
assertEquals("Collection isEmpty() result should match confirmed " +
|
||||
" collection's",
|
||||
confirmed.isEmpty(), collection.isEmpty());
|
||||
assertEquals(confirmedSize, collection.size(), "Collection size should match confirmed collection's");
|
||||
assertEquals(confirmed.isEmpty(), collection.isEmpty(), "Collection isEmpty() result should match confirmed collection's");
|
||||
|
||||
// verify the collections are the same by attempting to match each
|
||||
// object in the collection and confirmed collection. To account for
|
||||
@@ -521,8 +517,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
boolean r = collection.add(elements[i]);
|
||||
confirmed.add(elements[i]);
|
||||
verifyAll();
|
||||
assertTrue("Empty collection changed after add", r);
|
||||
assertEquals("Collection size is 1 after first add", 1, collection.size());
|
||||
assertTrue(r, "Empty collection changed after add");
|
||||
assertEquals(1, collection.size(), "Collection size is 1 after first add");
|
||||
}
|
||||
|
||||
resetEmpty();
|
||||
@@ -532,10 +528,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.add(elements[i]);
|
||||
verifyAll();
|
||||
if (r) size++;
|
||||
assertEquals("Collection size should grow after add",
|
||||
size, collection.size());
|
||||
assertTrue("Collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertEquals(size, collection.size(), "Collection size should grow after add");
|
||||
assertTrue(collection.contains(elements[i]), "Collection should contain added element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,10 +546,9 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
boolean r = collection.addAll(Arrays.asList(elements));
|
||||
confirmed.addAll(Arrays.asList(elements));
|
||||
verifyAll();
|
||||
assertTrue("Empty collection should change after addAll", r);
|
||||
assertTrue(r, "Empty collection should change after addAll");
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Collection should contain added element");
|
||||
}
|
||||
|
||||
resetFull();
|
||||
@@ -564,13 +557,11 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
r = collection.addAll(Arrays.asList(elements));
|
||||
confirmed.addAll(Arrays.asList(elements));
|
||||
verifyAll();
|
||||
assertTrue("Full collection should change after addAll", r);
|
||||
assertTrue(r, "Full collection should change after addAll");
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Full collection should contain added element");
|
||||
}
|
||||
assertEquals("Size should increase after addAll",
|
||||
size + elements.length, collection.size());
|
||||
assertEquals(size + elements.length, collection.size(), "Size should increase after addAll");
|
||||
|
||||
resetFull();
|
||||
size = collection.size();
|
||||
@@ -578,11 +569,9 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.addAll(Arrays.asList(getFullElements()));
|
||||
verifyAll();
|
||||
if (r) {
|
||||
assertTrue("Size should increase if addAll returns true",
|
||||
size < collection.size());
|
||||
assertTrue(size < collection.size(), "Size should increase if addAll returns true");
|
||||
} else {
|
||||
assertEquals("Size should not change if addAll returns false",
|
||||
size, collection.size());
|
||||
assertEquals(size, collection.size(), "Size should not change if addAll returns false");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,16 +655,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
elements = getFullElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Empty collection shouldn't contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
|
||||
elements = getOtherElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Empty collection shouldn't contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
@@ -683,8 +670,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
elements = getFullElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection should contain element[" + i + "]",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Full collection should contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
@@ -692,8 +678,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
elements = getOtherElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection shouldn't contain element",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Full collection shouldn't contain element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,22 +690,22 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
public void testCollectionContainsAll() {
|
||||
resetEmpty();
|
||||
Collection col = new HashSet();
|
||||
assertTrue("Every Collection should contain all elements of an " +
|
||||
"empty Collection.", collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col),
|
||||
"Every Collection should contain all elements of an " +
|
||||
"empty Collection.");
|
||||
col.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Empty Collection shouldn't contain all elements of " +
|
||||
"a non-empty Collection.", !collection.containsAll(col));
|
||||
assertTrue(!collection.containsAll(col),
|
||||
"Empty Collection shouldn't contain all elements of " +
|
||||
"a non-empty Collection.");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full collection shouldn't contain other elements",
|
||||
!collection.containsAll(col));
|
||||
assertTrue(!collection.containsAll(col), "Full collection shouldn't contain other elements");
|
||||
|
||||
col.clear();
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
assertTrue("Full collection should containAll full elements",
|
||||
collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll full elements");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
@@ -728,18 +713,17 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
int max = (getFullElements().length == 1 ? 1 :
|
||||
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
||||
col = Arrays.asList(getFullElements()).subList(min, max);
|
||||
assertTrue("Full collection should containAll partial full " +
|
||||
"elements", collection.containsAll(col));
|
||||
assertTrue("Full collection should containAll itself",
|
||||
collection.containsAll(collection));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll partial full " +
|
||||
"elements");
|
||||
assertTrue(collection.containsAll(collection), "Full collection should containAll itself");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
col = new ArrayList();
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
assertTrue("Full collection should containAll duplicate full " +
|
||||
"elements", collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll duplicate full " +
|
||||
"elements");
|
||||
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
@@ -751,14 +735,12 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("New Collection should be empty.",
|
||||
true, collection.isEmpty());
|
||||
assertEquals(true, collection.isEmpty(), "New Collection should be empty.");
|
||||
// make sure calls to "isEmpty() don't change anything
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full collection shouldn't be empty",
|
||||
false, collection.isEmpty());
|
||||
assertEquals(false, collection.isEmpty(), "Full collection shouldn't be empty");
|
||||
// make sure calls to "isEmpty() don't change anything
|
||||
verifyAll();
|
||||
}
|
||||
@@ -771,8 +753,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
public void testCollectionIterator() {
|
||||
resetEmpty();
|
||||
Iterator it1 = collection.iterator();
|
||||
assertEquals("Iterator for empty Collection shouldn't have next.",
|
||||
false, it1.hasNext());
|
||||
assertEquals(false, it1.hasNext(), "Iterator for empty Collection shouldn't have next.");
|
||||
try {
|
||||
it1.next();
|
||||
fail("Iterator at end of Collection should throw " +
|
||||
@@ -786,18 +767,17 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
it1 = collection.iterator();
|
||||
for (int i = 0; i < collection.size(); i++) {
|
||||
assertTrue("Iterator for full collection should haveNext",
|
||||
it1.hasNext());
|
||||
assertTrue(it1.hasNext(), "Iterator for full collection should haveNext");
|
||||
it1.next();
|
||||
}
|
||||
assertTrue("Iterator should be finished", !it1.hasNext());
|
||||
assertTrue(!it1.hasNext(), "Iterator should be finished");
|
||||
|
||||
ArrayList list = new ArrayList();
|
||||
it1 = collection.iterator();
|
||||
for (int i = 0; i < collection.size(); i++) {
|
||||
Object next = it1.next();
|
||||
assertTrue("Collection should contain element returned by " +
|
||||
"its iterator", collection.contains(next));
|
||||
assertTrue(collection.contains(next), "Collection should contain element returned by " +
|
||||
"its iterator");
|
||||
list.add(next);
|
||||
}
|
||||
try {
|
||||
@@ -865,11 +845,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
|
||||
size--;
|
||||
assertEquals("Collection should shrink by one after " +
|
||||
"iterator.remove", size, collection.size());
|
||||
assertEquals(size, collection.size(), "Collection should shrink by one after " +
|
||||
"iterator.remove");
|
||||
}
|
||||
assertTrue("Collection should be empty after iterator purge",
|
||||
collection.isEmpty());
|
||||
assertTrue(collection.isEmpty(), "Collection should be empty after iterator purge");
|
||||
|
||||
resetFull();
|
||||
iter = collection.iterator();
|
||||
@@ -894,8 +873,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
Object[] elements = getFullElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Shouldn't remove nonexistent element",
|
||||
!collection.remove(elements[i]));
|
||||
assertTrue(!collection.remove(elements[i]), "Shouldn't remove nonexistent element");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -903,16 +881,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetFull();
|
||||
for (int i = 0; i < other.length; i++) {
|
||||
assertTrue("Shouldn't remove nonexistent other element",
|
||||
!collection.remove(other[i]));
|
||||
assertTrue(!collection.remove(other[i]), "Shouldn't remove nonexistent other element");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
int size = collection.size();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
resetFull();
|
||||
assertTrue("Collection should remove extant element: " + elements[i],
|
||||
collection.remove(elements[i]));
|
||||
assertTrue(collection.remove(elements[i]), "Collection should remove extant element: " + elements[i]);
|
||||
|
||||
// if the elements aren't distinguishable, we can just remove a
|
||||
// matching element from the confirmed collection and verify
|
||||
@@ -927,8 +903,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
assertEquals("Collection should shrink after remove",
|
||||
size - 1, collection.size());
|
||||
assertEquals(size - 1, collection.size(), "Collection should shrink after remove");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,28 +916,28 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
if (!isRemoveSupported()) return;
|
||||
|
||||
resetEmpty();
|
||||
assertTrue("Emtpy collection removeAll should return false for " +
|
||||
"empty input",
|
||||
!collection.removeAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.removeAll(Collections.EMPTY_SET),
|
||||
"Emtpy collection removeAll should return false for " +
|
||||
"empty input");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Emtpy collection removeAll should return false for " +
|
||||
"nonempty input",
|
||||
!collection.removeAll(new ArrayList(collection)));
|
||||
assertTrue(!collection.removeAll(new ArrayList(collection)),
|
||||
"Emtpy collection removeAll should return false for " +
|
||||
"nonempty input");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full collection removeAll should return false for " +
|
||||
"empty input",
|
||||
!collection.removeAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.removeAll(Collections.EMPTY_SET),
|
||||
"Full collection removeAll should return false for " +
|
||||
"empty input");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Full collection removeAll should return false for other elements",
|
||||
!collection.removeAll(Arrays.asList(getOtherElements())));
|
||||
assertTrue(!collection.removeAll(Arrays.asList(getOtherElements())),
|
||||
"Full collection removeAll should return false for other elements");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Full collection removeAll should return true for full elements",
|
||||
collection.removeAll(new HashSet(collection)));
|
||||
assertTrue(collection.removeAll(new HashSet(collection)),
|
||||
"Full collection removeAll should return true for full elements");
|
||||
confirmed.removeAll(new HashSet(confirmed));
|
||||
verifyAll();
|
||||
|
||||
@@ -972,17 +947,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
int max = (getFullElements().length == 1 ? 1 :
|
||||
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
||||
Collection all = Arrays.asList(getFullElements()).subList(min, max);
|
||||
assertTrue("Full collection removeAll should work",
|
||||
collection.removeAll(all));
|
||||
assertTrue(collection.removeAll(all), "Full collection removeAll should work");
|
||||
confirmed.removeAll(all);
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Collection should shrink after removeAll",
|
||||
collection.size() < size);
|
||||
assertTrue(collection.size() < size, "Collection should shrink after removeAll");
|
||||
Iterator iter = all.iterator();
|
||||
while (iter.hasNext()) {
|
||||
assertTrue("Collection shouldn't contain removed element",
|
||||
!collection.contains(iter.next()));
|
||||
assertTrue(!collection.contains(iter.next()), "Collection shouldn't contain removed element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -998,59 +970,51 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
List elements = Arrays.asList(getFullElements());
|
||||
List other = Arrays.asList(getOtherElements());
|
||||
|
||||
assertTrue("Empty retainAll() should return false",
|
||||
!collection.retainAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.retainAll(Collections.EMPTY_SET), "Empty retainAll() should return false");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Empty retainAll() should return false",
|
||||
!collection.retainAll(elements));
|
||||
assertTrue(!collection.retainAll(elements), "Empty retainAll() should return false");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Collection should change from retainAll empty",
|
||||
collection.retainAll(Collections.EMPTY_SET));
|
||||
assertTrue(collection.retainAll(Collections.EMPTY_SET), "Collection should change from retainAll empty");
|
||||
confirmed.retainAll(Collections.EMPTY_SET);
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Collection changed from retainAll other",
|
||||
collection.retainAll(other));
|
||||
assertTrue(collection.retainAll(other), "Collection changed from retainAll other");
|
||||
confirmed.retainAll(other);
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
int size = collection.size();
|
||||
assertTrue("Collection shouldn't change from retainAll elements",
|
||||
!collection.retainAll(elements));
|
||||
assertTrue(!collection.retainAll(elements), "Collection shouldn't change from retainAll elements");
|
||||
verifyAll();
|
||||
assertEquals("Collection size shouldn't change", size,
|
||||
collection.size());
|
||||
assertEquals(size, collection.size(), "Collection size shouldn't change");
|
||||
|
||||
if (getFullElements().length > 1) {
|
||||
resetFull();
|
||||
size = collection.size();
|
||||
int min = (getFullElements().length < 2 ? 0 : 2);
|
||||
int max = (getFullElements().length <= 5 ? getFullElements().length - 1 : 5);
|
||||
assertTrue("Collection should changed by partial retainAll",
|
||||
collection.retainAll(elements.subList(min, max)));
|
||||
assertTrue(collection.retainAll(elements.subList(min, max)), "Collection should changed by partial retainAll");
|
||||
confirmed.retainAll(elements.subList(min, max));
|
||||
verifyAll();
|
||||
|
||||
Iterator iter = collection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
assertTrue("Collection only contains retained element",
|
||||
elements.subList(min, max).contains(iter.next()));
|
||||
assertTrue(elements.subList(min, max).contains(iter.next()), "Collection only contains retained element");
|
||||
}
|
||||
}
|
||||
|
||||
resetFull();
|
||||
HashSet set = new HashSet(elements);
|
||||
size = collection.size();
|
||||
assertTrue("Collection shouldn't change from retainAll without " +
|
||||
"duplicate elements", !collection.retainAll(set));
|
||||
assertTrue(!collection.retainAll(set),
|
||||
"Collection shouldn't change from retainAll without duplicate elements");
|
||||
verifyAll();
|
||||
assertEquals("Collection size didn't change from nonduplicate " +
|
||||
"retainAll", size, collection.size());
|
||||
assertEquals( size, collection.size(),
|
||||
"Collection size didn't change from nonduplicate retainAll");
|
||||
}
|
||||
|
||||
|
||||
@@ -1060,11 +1024,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Size of new Collection is 0.", 0, collection.size());
|
||||
assertEquals(0, collection.size(), "Size of new Collection is 0.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("Size of full collection should be greater than zero",
|
||||
collection.size() > 0);
|
||||
assertTrue(collection.size() > 0, "Size of full collection should be greater than zero");
|
||||
}
|
||||
|
||||
|
||||
@@ -1073,22 +1036,18 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
*/
|
||||
public void testCollectionToArray() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty Collection should return empty array for toArray",
|
||||
0, collection.toArray().length);
|
||||
assertEquals(0, collection.toArray().length, "Empty Collection should return empty array for toArray");
|
||||
|
||||
resetFull();
|
||||
Object[] array = collection.toArray();
|
||||
assertEquals("Full collection toArray should be same size as " +
|
||||
"collection", array.length, collection.size());
|
||||
assertEquals(array.length, collection.size(), "Full collection toArray should be same size as collection");
|
||||
Object[] confirmedArray = confirmed.toArray();
|
||||
assertEquals("length of array from confirmed collection should " +
|
||||
"match the length of the collection's array",
|
||||
confirmedArray.length, array.length);
|
||||
assertEquals(confirmedArray.length, array.length,
|
||||
"length of array from confirmed collection should match the length of the collection's array");
|
||||
boolean[] matched = new boolean[array.length];
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
assertTrue("Collection should contain element in toArray",
|
||||
collection.contains(array[i]));
|
||||
assertTrue(collection.contains(array[i]), "Collection should contain element in toArray");
|
||||
|
||||
boolean match = false;
|
||||
// find a match in the confirmed array
|
||||
@@ -1108,8 +1067,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < matched.length; i++) {
|
||||
assertEquals("Collection should return all its elements in " +
|
||||
"toArray", true, matched[i]);
|
||||
assertEquals(true, matched[i], "Collection should return all its elements in toArray");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1123,8 +1081,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
Object[] a = new Object[] { new Object(), null, null };
|
||||
Object[] array = collection.toArray(a);
|
||||
assertArrayEquals("Given array shouldn't shrink", array, a);
|
||||
assertNull("Last element should be set to null", a[0]);
|
||||
assertArrayEquals(array, a, "Given array shouldn't shrink");
|
||||
assertNull(a[0], "Last element should be set to null");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
@@ -1146,8 +1104,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
array = collection.toArray(new Object[0]);
|
||||
a = collection.toArray();
|
||||
assertEquals("toArrays should be equal",
|
||||
Arrays.asList(array), Arrays.asList(a));
|
||||
assertEquals(Arrays.asList(array), Arrays.asList(a), "toArrays should be equal");
|
||||
|
||||
// Figure out if they're all the same class
|
||||
// TODO: It'd be nicer to detect a common superclass
|
||||
@@ -1163,11 +1120,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
a = (Object[])Array.newInstance(cl, 0);
|
||||
array = collection.toArray(a);
|
||||
assertEquals("toArray(Object[]) should return correct array type",
|
||||
a.getClass(), array.getClass());
|
||||
assertEquals("type-specific toArrays should be equal",
|
||||
Arrays.asList(array),
|
||||
Arrays.asList(collection.toArray()));
|
||||
assertEquals(a.getClass(), array.getClass(), "toArray(Object[]) should return correct array type");
|
||||
assertEquals(Arrays.asList(array),
|
||||
Arrays.asList(collection.toArray()),
|
||||
"type-specific toArrays should be equal");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -1178,12 +1134,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionToString() {
|
||||
resetEmpty();
|
||||
assertTrue("toString shouldn't return null",
|
||||
collection.toString() != null);
|
||||
assertTrue(collection.toString() != null, "toString shouldn't return null");
|
||||
|
||||
resetFull();
|
||||
assertTrue("toString shouldn't return null",
|
||||
collection.toString() != null);
|
||||
assertTrue(collection.toString() != null, "toString shouldn't return null");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* CollectionUtilTest
|
||||
*
|
||||
@@ -61,44 +59,60 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new Object[] {"bar", "baz", 3}, merged);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 4, 2, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 4, 2, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadSecondOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 4, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 4, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 4, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 4, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadSecondLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, 2);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, 2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, -1, 2, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, -1, 2, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeSecondOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, -1, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, -1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, -1, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, -1, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeSecondLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, -1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,20 +123,24 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new Object[] {"foo", "bar", "baz", 1, 2, 3}, merged);
|
||||
}
|
||||
|
||||
@Test(expected = ArrayStoreException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectIllegalType() {
|
||||
String[] strings = {"foo", "bar", "baz"};
|
||||
Integer[] integers = {1, 2, 3}; // Integer not assignable to String
|
||||
|
||||
CollectionUtil.mergeArrays(strings, integers);
|
||||
assertThrows(ArrayStoreException.class, () -> {
|
||||
CollectionUtil.mergeArrays(strings, integers);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ArrayStoreException.class)
|
||||
@Test
|
||||
public void testMergeArraysNativeIllegalType() {
|
||||
char[] chars = {'a', 'b', 'c'};
|
||||
int[] integers = {1, 2, 3}; // Integer not assignable to String
|
||||
|
||||
CollectionUtil.mergeArrays(chars, integers);
|
||||
assertThrows(ArrayStoreException.class, () -> {
|
||||
CollectionUtil.mergeArrays(chars, integers);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -147,9 +165,11 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new int[] {2, 3, 4}, numbers);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testEnumIteratorNull() {
|
||||
CollectionUtil.iterator((Enumeration<Object>) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator((Enumeration<Object>) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,9 +203,11 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorNull() {
|
||||
CollectionUtil.iterator((Object[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator((Object[]) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -262,7 +284,7 @@ public class CollectionUtilTest {
|
||||
|
||||
int count = 0;
|
||||
for (Object element : elements) {
|
||||
assertTrue("No next element for element '" + element + "' at index: " + count, iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "No next element for element '" + element + "' at index: " + count);
|
||||
assertEquals(count > 0, iterator.hasPrevious());
|
||||
assertEquals(count, iterator.nextIndex());
|
||||
assertEquals(count - 1, iterator.previousIndex());
|
||||
@@ -318,7 +340,7 @@ public class CollectionUtilTest {
|
||||
assertEquals(elements.length, iterator.nextIndex());
|
||||
|
||||
for (int i = count; i > 0; i--) {
|
||||
assertTrue("No previous element for element '" + elements[i - 1] + "' at index: " + (i - 1), iterator.hasPrevious());
|
||||
assertTrue(iterator.hasPrevious(), "No previous element for element '" + elements[i - 1] + "' at index: " + (i - 1));
|
||||
assertEquals(i < elements.length, iterator.hasNext());
|
||||
assertEquals(i - 1, iterator.previousIndex());
|
||||
assertEquals(i, iterator.nextIndex());
|
||||
@@ -339,18 +361,24 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeNull() {
|
||||
CollectionUtil.iterator(null, 0, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(null, 0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeBadStart() {
|
||||
CollectionUtil.iterator(stringObjects, stringObjects.length + 1, 2);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(stringObjects, stringObjects.length + 1, 2);
|
||||
});
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeBadLength() {
|
||||
CollectionUtil.iterator(stringObjects, 1, stringObjects.length);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(stringObjects, 1, stringObjects.length);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,9 +407,11 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReverseOrderNull() {
|
||||
CollectionUtil.reverseOrder(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.reverseOrder(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,7 +461,7 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("For development only")
|
||||
@Disabled("For development only")
|
||||
@Test
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void testGenerify() {
|
||||
|
@@ -45,11 +45,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests LRUMap.
|
||||
@@ -81,8 +80,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map2.put(4,"foo"); // removes 1 since max size exceeded
|
||||
map2.removeLRU(); // should be Integer(2)
|
||||
|
||||
assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo"));
|
||||
assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null);
|
||||
assertTrue(map2.get(new Integer(3)).equals("foo"), "Second to last value should exist");
|
||||
assertTrue(map2.get(new Integer(1)) == null, "First value inserted should not exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,8 +92,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"bar");
|
||||
|
||||
assertTrue("last value should exist",map2.get(new Integer(4)).equals("bar"));
|
||||
assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
|
||||
assertTrue(map2.get(new Integer(4)).equals("bar"), "last value should exist");
|
||||
assertTrue(map2.get(new Integer(1)) == null, "LRU should not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,10 +112,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
assertTrue("max size is 3, but actual size is " + map2.size(),
|
||||
map2.size() == 3);
|
||||
assertTrue("map should contain the Integer(4) object",
|
||||
map2.containsKey(new Integer(4)));
|
||||
assertTrue(map2.size() == 3, "max size is 3, but actual size is " + map2.size());
|
||||
assertTrue(map2.containsKey(new Integer(4)), "map should contain the Integer(4) object");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,8 +131,7 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map.put("6","6");
|
||||
map.setMaxSize(3);
|
||||
|
||||
assertTrue("map should have size = 3, but actually = " + map.size(),
|
||||
map.size() == 3);
|
||||
assertTrue(map.size() == 3, "map should have size = 3, but actually = " + map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,9 +156,9 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
keys[i] = keyIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3"));
|
||||
assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1"));
|
||||
assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4"));
|
||||
assertTrue(keys[0].equals("3"), "first evicted should be 3, was " + keys[0]);
|
||||
assertTrue(keys[1].equals("1"), "second evicted should be 1, was " + keys[1]);
|
||||
assertTrue(keys[2].equals("4"), "third evicted should be 4, was " + keys[2]);
|
||||
|
||||
}
|
||||
|
||||
@@ -192,13 +188,12 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
// 4 2
|
||||
counter.remove("5");
|
||||
|
||||
assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2);
|
||||
assertTrue("removedCount should be 3 but was " + counter.removedCount,
|
||||
counter.removedCount == 3);
|
||||
assertTrue(counter.size() == 2, "size should be 2, but was " + counter.size());
|
||||
assertTrue(counter.removedCount == 3, "removedCount should be 3 but was " + counter.removedCount);
|
||||
|
||||
assertTrue("first removed was '2'",counter.list.get(0).equals("2"));
|
||||
assertTrue("second removed was '3'",counter.list.get(1).equals("3"));
|
||||
assertTrue("third removed was '1'",counter.list.get(2).equals("1"));
|
||||
assertTrue(counter.list.get(0).equals("2"), "first removed was '2'");
|
||||
assertTrue(counter.list.get(1).equals("3"), "second removed was '3'");
|
||||
assertTrue(counter.list.get(2).equals("1"), "third removed was '1'");
|
||||
|
||||
//assertTrue("oldest key is '4'",counter.get(0).equals("4"));
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
|
@@ -45,15 +45,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
@@ -74,7 +70,7 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
*/
|
||||
protected LinkedMap labRat;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
// use makeMap and cast the result to a SeqHashMap
|
||||
// so that subclasses of SeqHashMap can share these tests
|
||||
@@ -103,27 +99,21 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
}
|
||||
|
||||
// Test size().
|
||||
assertEquals("size() does not match expected size",
|
||||
expectedSize, labRat.size());
|
||||
assertEquals(expectedSize, labRat.size(), "size() does not match expected size");
|
||||
|
||||
// Test clone(), iterator(), and get(Object).
|
||||
LinkedMap clone = (LinkedMap) labRat.clone();
|
||||
assertEquals("Size of clone does not match original",
|
||||
labRat.size(), clone.size());
|
||||
assertEquals(labRat.size(), clone.size(), "Size of clone does not match original");
|
||||
Iterator origEntries = labRat.entrySet().iterator();
|
||||
Iterator copiedEntries = clone.entrySet().iterator();
|
||||
while (origEntries.hasNext()) {
|
||||
Map.Entry origEntry = (Map.Entry)origEntries.next();
|
||||
Map.Entry copiedEntry = (Map.Entry)copiedEntries.next();
|
||||
assertEquals("Cloned key does not match original",
|
||||
origEntry.getKey(), copiedEntry.getKey());
|
||||
assertEquals("Cloned value does not match original",
|
||||
origEntry.getValue(), copiedEntry.getValue());
|
||||
assertEquals("Cloned entry does not match original",
|
||||
origEntry, copiedEntry);
|
||||
assertEquals(origEntry.getKey(), copiedEntry.getKey(), "Cloned key does not match original");
|
||||
assertEquals(origEntry.getValue(), copiedEntry.getValue(), "Cloned value does not match original");
|
||||
assertEquals(origEntry, copiedEntry, "Cloned entry does not match original");
|
||||
}
|
||||
assertTrue("iterator() returned different number of elements than keys()",
|
||||
!copiedEntries.hasNext());
|
||||
assertTrue(!copiedEntries.hasNext(), "iterator() returned different number of elements than keys()");
|
||||
|
||||
// Test sequence()
|
||||
/*
|
||||
@@ -207,7 +197,7 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
}
|
||||
*/
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
labRat = null;
|
||||
}
|
||||
|
@@ -45,12 +45,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link java.util.Map} methods and contracts.
|
||||
@@ -390,19 +388,19 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
m.put(keys[i], values[i]);
|
||||
}
|
||||
catch (NullPointerException exception) {
|
||||
assertTrue("NullPointerException only allowed to be thrown if either the key or value is null.",
|
||||
keys[i] == null || values[i] == null);
|
||||
assertTrue(keys[i] == null || values[i] == null,
|
||||
"NullPointerException only allowed to be thrown if either the key or value is null.");
|
||||
|
||||
assertTrue("NullPointerException on null key, but isAllowNullKey is not overridden to return false.",
|
||||
keys[i] == null || !isAllowNullKey());
|
||||
assertTrue(keys[i] == null || !isAllowNullKey(),
|
||||
"NullPointerException on null key, but isAllowNullKey is not overridden to return false.");
|
||||
|
||||
assertTrue("NullPointerException on null value, but isAllowNullValue is not overridden to return false.",
|
||||
values[i] == null || !isAllowNullValue());
|
||||
assertTrue(values[i] == null || !isAllowNullValue(),
|
||||
"NullPointerException on null value, but isAllowNullValue is not overridden to return false.");
|
||||
|
||||
assertTrue("Unknown reason for NullPointer.", false);
|
||||
fail("Unknown reason for NullPointer.");
|
||||
}
|
||||
}
|
||||
assertEquals("size must reflect number of mappings added.", keys.length, m.size());
|
||||
assertEquals(keys.length, m.size(), "size must reflect number of mappings added.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -481,27 +479,26 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
Object[] newValues = getNewSampleValues();
|
||||
|
||||
assertTrue("failure in test: Must have keys returned from getSampleKeys.", keys != null);
|
||||
assertTrue("failure in test: Must have values returned from getSampleValues.", values != null);
|
||||
assertTrue(keys != null, "failure in test: Must have keys returned from getSampleKeys.");
|
||||
assertTrue(values != null, "failure in test: Must have values returned from getSampleValues.");
|
||||
|
||||
// verify keys and values have equivalent lengths (in case getSampleX are
|
||||
// overridden)
|
||||
assertEquals("failure in test: not the same number of sample 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(keys.length, values.length, "failure in test: not the same number of sample keys and values.");
|
||||
assertEquals(values.length, newValues.length, "failure in test: not the same number of values and new values.");
|
||||
|
||||
// verify there aren't duplicate keys, and check values
|
||||
for (int i = 0; i < keys.length - 1; i++) {
|
||||
for (int j = i + 1; j < keys.length; j++) {
|
||||
assertTrue("failure in test: duplicate null keys.", (keys[i] != null || keys[j] != null));
|
||||
assertTrue("failure in test: duplicate non-null key.",
|
||||
(keys[i] == null || keys[j] == null || (!keys[i].equals(keys[j]) && !keys[j].equals(keys[i]))));
|
||||
assertTrue((keys[i] != null || keys[j] != null), "failure in test: duplicate null keys.");
|
||||
assertTrue((keys[i] == null || keys[j] == null || (!keys[i].equals(keys[j]) && !keys[j].equals(keys[i]))),
|
||||
"failure in test: duplicate non-null key.");
|
||||
}
|
||||
|
||||
assertTrue("failure in test: found null key, but isNullKeySupported is false.", keys[i] != null || isAllowNullKey());
|
||||
assertTrue("failure in test: found null value, but isNullValueSupported 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: values should not be the same as new value",
|
||||
values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])));
|
||||
assertTrue(keys[i] != null || isAllowNullKey(),"failure in test: found null key, but isNullKeySupported is false.");
|
||||
assertTrue(values[i] != null || isAllowNullValue(),"failure in test: found null value, but isNullValueSupported is false.");
|
||||
assertTrue(newValues[i] != null || isAllowNullValue(), "failure in test: found null new value, but isNullValueSupported is false.");
|
||||
assertTrue(values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])), "failure in test: values should not be the same as new value");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,18 +514,18 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMakeMap() {
|
||||
Map em = makeEmptyMap();
|
||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em != null);
|
||||
assertTrue(em != null, "failure in test: makeEmptyMap must return a non-null map.");
|
||||
|
||||
Map em2 = makeEmptyMap();
|
||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em2 != null);
|
||||
assertTrue("failure in test: makeEmptyMap must return a new map with each invocation.", em != em2);
|
||||
assertTrue(em2 != null, "failure in test: makeEmptyMap must return a non-null map.");
|
||||
assertTrue(em != em2, "failure in test: makeEmptyMap must return a new map with each invocation.");
|
||||
|
||||
Map fm = makeFullMap();
|
||||
assertTrue("failure in test: makeFullMap must return a non-null map.", fm != null);
|
||||
assertTrue(fm != null, "failure in test: makeFullMap must return a non-null map.");
|
||||
|
||||
Map fm2 = makeFullMap();
|
||||
assertTrue("failure in test: makeFullMap must return a non-null map.", fm2 != null);
|
||||
assertTrue("failure in test: makeFullMap must return a new map with each invocation.", fm != fm2);
|
||||
assertTrue(fm2 != null, "failure in test: makeFullMap must return a non-null map.");
|
||||
assertTrue(fm != fm2, "failure in test: makeFullMap must return a new map with each invocation.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,11 +534,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map", true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(), "Map.isEmpty() should return true with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return false with a non-empty map", false, map.isEmpty());
|
||||
assertEquals(false, map.isEmpty(), "Map.isEmpty() should return false with a non-empty map");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -551,11 +548,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map", 0, map.size());
|
||||
assertEquals(0, map.size(), "Map.size() should be 0 with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries in the map", getSampleKeys().length, map.size());
|
||||
assertEquals(getSampleKeys().length, map.size(), "Map.size() should equal the number of entries in the map");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -602,13 +599,13 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||
assertTrue(!map.containsKey(key), "Map must not contain key when map is empty");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must contain key for a mapping in the map. Missing: " + key, map.containsKey(key));
|
||||
assertTrue(map.containsKey(key), "Map must contain key for a mapping in the map. Missing: " + key);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -624,13 +621,13 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object value : values) {
|
||||
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||
assertTrue(!map.containsValue(value), "Empty map must not contain value");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (Object value : values) {
|
||||
assertTrue("Map must contain value for a mapping in the map.", map.containsValue(value));
|
||||
assertTrue(map.containsValue(value), "Map must contain value for a mapping in the map.");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -641,11 +638,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Empty maps unequal.");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Full maps unequal.");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
@@ -654,11 +651,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Iterator iter = confirmed.keySet().iterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
assertTrue("Different maps equal.", !map.equals(confirmed));
|
||||
assertTrue(!map.equals(confirmed), "Different maps equal.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("equals(null) returned true.", !map.equals(null));
|
||||
assertTrue("equals(new Object()) returned true.", !map.equals(new Object()));
|
||||
assertTrue(!map.equals(null), "equals(null) returned true.");
|
||||
assertTrue(!map.equals(new Object()), "equals(new Object()) returned true.");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -673,14 +670,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
|
||||
for (Object key : keys) {
|
||||
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||
assertTrue(map.get(key) == null, "Empty map.get() should return null.");
|
||||
}
|
||||
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
assertEquals("Full map.get() should return value from mapping.", values[i], map.get(keys[i]));
|
||||
assertEquals(values[i], map.get(keys[i]), "Full map.get() should return value from mapping.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,10 +687,10 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Empty maps have different hashCodes.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("Equal maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Equal maps have different hashCodes.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -708,11 +705,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||
assertTrue(map.toString() != null, "Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||
assertTrue(map.toString() != null, "Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -776,29 +773,23 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
assertTrue("Map should contain key after put",
|
||||
map.containsKey(keys[i]));
|
||||
assertTrue("Map should contain value after put",
|
||||
map.containsValue(values[i]));
|
||||
assertTrue(o == null, "First map.put should return null");
|
||||
assertTrue(map.containsKey(keys[i]), "Map should contain key after put");
|
||||
assertTrue(map.containsValue(values[i]), "Map should contain value after put");
|
||||
}
|
||||
if (isPutChangeSupported()) {
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.put(keys[i], newValues[i]);
|
||||
confirmed.put(keys[i], newValues[i]);
|
||||
verifyAll();
|
||||
assertEquals("Map.put should return previous value when changed",
|
||||
values[i], o);
|
||||
assertTrue("Map should still contain key after put when changed",
|
||||
map.containsKey(keys[i]));
|
||||
assertTrue("Map should contain new value after put when changed",
|
||||
map.containsValue(newValues[i]));
|
||||
assertEquals(values[i], o, "Map.put should return previous value when changed");
|
||||
assertTrue(map.containsKey(keys[i]), "Map should still contain key after put when changed");
|
||||
assertTrue(map.containsValue(newValues[i]), "Map should contain new value after put when changed");
|
||||
|
||||
// if duplicates are allowed, we're not guaranteed that the value
|
||||
// no longer exists, so don't try checking that.
|
||||
if (!isAllowDuplicateValues()) {
|
||||
assertTrue("Map should not contain old value after put when changed",
|
||||
!map.containsValue(values[i]));
|
||||
assertTrue(!map.containsValue(values[i]), "Map should not contain old value after put when changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -832,18 +823,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object o = map.put(key, newValues[i]);
|
||||
Object value = confirmed.put(key, newValues[i]);
|
||||
verifyAll();
|
||||
assertEquals("Map.put should return previous value when changed",
|
||||
value, o);
|
||||
assertTrue("Map should still contain key after put when changed",
|
||||
map.containsKey(key));
|
||||
assertTrue("Map should contain new value after put when changed",
|
||||
map.containsValue(newValues[i]));
|
||||
assertEquals(value, o, "Map.put should return previous value when changed");
|
||||
assertTrue(map.containsKey(key), "Map should still contain key after put when changed");
|
||||
assertTrue(map.containsValue(newValues[i]), "Map should contain new value after put when changed");
|
||||
|
||||
// if duplicates are allowed, we're not guaranteed that the value
|
||||
// no longer exists, so don't try checking that.
|
||||
if (!isAllowDuplicateValues()) {
|
||||
assertTrue("Map should not contain old value after put when changed",
|
||||
!map.containsValue(values[i]));
|
||||
assertTrue(!map.containsValue(values[i]), "Map should not contain old value after put when changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -970,7 +957,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
assertTrue(o == null, "First map.remove should return null");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
@@ -981,8 +968,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.remove(keys[i]);
|
||||
verifyAll();
|
||||
|
||||
assertEquals("map.remove with valid key should return value",
|
||||
values[i], o);
|
||||
assertEquals(values[i], o, "map.remove with valid key should return value");
|
||||
}
|
||||
|
||||
Object[] other = getOtherKeys();
|
||||
@@ -991,10 +977,8 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
int size = map.size();
|
||||
for (int i = 0; i < other.length; i++) {
|
||||
Object o = map.remove(other[i]);
|
||||
assertEquals("map.remove for nonexistent key should return null",
|
||||
o, null);
|
||||
assertEquals("map.remove for nonexistent key should not " +
|
||||
"shrink map", size, map.size());
|
||||
assertEquals(o, null, "map.remove for nonexistent key should return null");
|
||||
assertEquals(size, map.size(), "map.remove for nonexistent key should not shrink map");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -1204,10 +1188,9 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
j++;
|
||||
}
|
||||
assertTrue("values().remove(obj) is broken", j < 10000);
|
||||
assertTrue(
|
||||
"Value should have been removed from the underlying map.",
|
||||
!map.containsValue(sampleValues[i]));
|
||||
assertTrue(j < 10000, "values().remove(obj) is broken");
|
||||
assertTrue(!map.containsValue(sampleValues[i]),
|
||||
"Value should have been removed from the underlying map.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1230,9 +1213,8 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
// if key.remove is unsupported, just skip this test
|
||||
return;
|
||||
}
|
||||
assertTrue(
|
||||
"Key should have been removed from the underlying map.",
|
||||
!map.containsKey(sampleKeys[i]));
|
||||
assertTrue(!map.containsKey(sampleKeys[i]),
|
||||
"Key should have been removed from the underlying map.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1413,7 +1395,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull("No matching entry in map for key '" + key + "'", entry);
|
||||
assertNotNull(entry, "No matching entry in map for key '" + key + "'");
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -1638,14 +1620,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
public void verifyMap() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("Map should be same size as HashMap", size, map.size());
|
||||
assertEquals("Map should be empty if HashMap is", empty, map.isEmpty());
|
||||
assertEquals("hashCodes should be the same", confirmed.hashCode(), map.hashCode());
|
||||
assertEquals(size, map.size(), "Map should be same size as HashMap");
|
||||
assertEquals(empty, map.isEmpty(), "Map should be empty if HashMap is");
|
||||
assertEquals(confirmed.hashCode(), map.hashCode(), "hashCodes should be the same");
|
||||
// this fails for LRUMap because confirmed.equals() somehow modifies
|
||||
// map, causing concurrent modification exceptions.
|
||||
//assertEquals("Map should still equal HashMap", confirmed, map);
|
||||
// this works though and performs the same verification:
|
||||
assertTrue("Map should still equal HashMap", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Map should still equal HashMap");
|
||||
// TODO: this should really be reexamined to figure out why LRU map
|
||||
// behaves like it does (the equals shouldn't modify since all accesses
|
||||
// by the confirmed collection should be through an iterator, thus not
|
||||
@@ -1655,29 +1637,29 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
public void verifyEntrySet() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("entrySet should be same size as HashMap's\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
size, entrySet.size());
|
||||
assertEquals("entrySet should be empty if HashMap is\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
empty, entrySet.isEmpty());
|
||||
assertTrue("entrySet should contain all HashMap's elements\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
entrySet.containsAll(confirmed.entrySet()));
|
||||
assertEquals("entrySet hashCodes should be the same\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
confirmed.entrySet().hashCode(), entrySet.hashCode());
|
||||
assertEquals("Map's entry set should still equal HashMap's", confirmed.entrySet(), entrySet);
|
||||
assertEquals(size, entrySet.size(),
|
||||
"entrySet should be same size as HashMap's\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(empty, entrySet.isEmpty(),
|
||||
"entrySet should be empty if HashMap is\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertTrue(entrySet.containsAll(confirmed.entrySet()),
|
||||
"entrySet should contain all HashMap's elements\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(confirmed.entrySet().hashCode(), entrySet.hashCode(),
|
||||
"entrySet hashCodes should be the same\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(confirmed.entrySet(), entrySet,"Map's entry set should still equal HashMap's");
|
||||
}
|
||||
|
||||
public void verifyKeySet() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("keySet should be same size as HashMap's\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
size, keySet.size());
|
||||
assertEquals("keySet should be empty if HashMap is\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
empty, keySet.isEmpty());
|
||||
assertTrue("keySet should contain all HashMap's elements\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
keySet.containsAll(confirmed.keySet()));
|
||||
assertEquals("keySet hashCodes should be the same\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
confirmed.keySet().hashCode(), keySet.hashCode());
|
||||
assertEquals("Map's key set should still equal HashMap's", confirmed.keySet(), keySet);
|
||||
assertEquals(size, keySet.size(),
|
||||
"keySet should be same size as HashMap's\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(empty, keySet.isEmpty(),
|
||||
"keySet should be empty if HashMap is\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertTrue(keySet.containsAll(confirmed.keySet()),
|
||||
"keySet should contain all HashMap's elements\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(confirmed.keySet().hashCode(), keySet.hashCode(),
|
||||
"keySet hashCodes should be the same\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(confirmed.keySet(), keySet, "Map's key set should still equal HashMap's");
|
||||
}
|
||||
|
||||
public void verifyValues() {
|
||||
@@ -1687,23 +1669,23 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
|
||||
assertEquals("values should be same size as HashMap's\nTest: " + test + "\nReal: " + known, size, values.size());
|
||||
assertEquals("values should be empty if HashMap is\nTest: " + test + "\nReal: " + known, empty, values.isEmpty());
|
||||
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, test.containsAll(known));
|
||||
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, known.containsAll(test));
|
||||
assertEquals(size, values.size(), "values should be same size as HashMap's\nTest: " + test + "\nReal: " + known);
|
||||
assertEquals(empty, values.isEmpty(), "values should be empty if HashMap is\nTest: " + test + "\nReal: " + known);
|
||||
assertTrue(test.containsAll(known), "values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known);
|
||||
assertTrue(known.containsAll(test), "values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known);
|
||||
|
||||
for (Object aKnown : known) {
|
||||
boolean removed = test.remove(aKnown);
|
||||
assertTrue("Map's values should still equal HashMap's", removed);
|
||||
assertTrue(removed, "Map's values should still equal HashMap's");
|
||||
}
|
||||
|
||||
assertTrue("Map's values should still equal HashMap's", test.isEmpty());
|
||||
assertTrue(test.isEmpty(), "Map's values should still equal HashMap's");
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases any leftover instance variables by setting them to null.
|
||||
*/
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
map = null;
|
||||
keySet = null;
|
||||
|
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* NOTE: This TestCase is written especially for NullMap, and is full of dirty
|
||||
@@ -83,12 +81,12 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map",
|
||||
true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(),
|
||||
"Map.isEmpty() should return true with an empty map");
|
||||
verifyAll();
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return true with a full map",
|
||||
true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(),
|
||||
"Map.isEmpty() should return true with a full map");
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
@@ -96,13 +94,13 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map",
|
||||
0, map.size());
|
||||
assertEquals(0, map.size(),
|
||||
"Map.size() should be 0 with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries " +
|
||||
"in the map", 0, map.size());
|
||||
assertEquals(0, map.size(),
|
||||
"Map.size() should equal the number of entries in the map");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +110,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||
assertTrue(!map.containsKey(key),"Map must not contain key when map is empty");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -124,7 +122,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object value : values) {
|
||||
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||
assertTrue(!map.containsValue(value), "Empty map must not contain value");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -133,7 +131,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Empty maps unequal.");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -141,8 +139,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.",
|
||||
map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Empty maps have different hashCodes.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +150,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
for (Object key : keys) {
|
||||
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||
assertTrue(map.get(key) == null, "Empty map.get() should return null.");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -170,7 +167,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
//confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
assertTrue(o == null, "First map.put should return null");
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
map.put(keys[i], newValues[i]);
|
||||
@@ -183,8 +180,8 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null",
|
||||
map.toString() != null);
|
||||
assertTrue(map.toString() != null,
|
||||
"Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -202,7 +199,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object[] keys = getSampleKeys();
|
||||
for(int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
assertTrue(o == null, "First map.remove should return null");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
@@ -44,12 +44,10 @@
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Object} methods and contracts.
|
||||
@@ -119,7 +117,7 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("A Object should equal itself", obj, obj);
|
||||
assertEquals(obj, obj, "A Object should equal itself");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,25 +129,24 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
assertEquals(obj.hashCode(), obj.hashCode(), "hashCode should be repeatable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
assertEquals(obj1.hashCode(), obj1.hashCode(),
|
||||
"[1] When two objects are equal, their hashCodes should be also.");
|
||||
}
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
obj1.hashCode(), obj2.hashCode(),
|
||||
"[2] When two objects are equal, their hashCodes should be also.");
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
obj2.equals(obj1),
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +163,7 @@ public abstract class ObjectAbstractTest {
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
if (isEqualsCheckable()) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
assertEquals(obj, dest, "obj != deserialize(serialize(obj))");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,8 +196,8 @@ public abstract class ObjectAbstractTest {
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalEmptyCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical empty collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
new File(name).exists(),
|
||||
"Canonical empty collection (" + name + ") is not in CVS");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,8 +213,8 @@ public abstract class ObjectAbstractTest {
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalFullCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical full collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
new File(name).exists(),
|
||||
"Canonical full collection (" + name + ") is not in CVS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -44,12 +44,10 @@
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Set} methods and contracts.
|
||||
@@ -79,14 +77,12 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
public void verifyAll() {
|
||||
super.verifyAll();
|
||||
|
||||
assertEquals("Sets should be equal", confirmed, collection);
|
||||
assertEquals("Sets should have equal hashCodes",
|
||||
confirmed.hashCode(), collection.hashCode());
|
||||
assertEquals(confirmed, collection, "Sets should be equal");
|
||||
assertEquals(confirmed.hashCode(), collection.hashCode(), "Sets should have equal hashCodes");
|
||||
Collection set = makeConfirmedCollection();
|
||||
Iterator iterator = collection.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
assertTrue("Set.iterator should only return unique elements",
|
||||
set.add(iterator.next()));
|
||||
assertTrue(set.add(iterator.next()), "Set.iterator should only return unique elements");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,23 +176,20 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
@Test
|
||||
public void testSetEquals() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets should be equal",
|
||||
getSet(), getConfirmedSet());
|
||||
assertEquals(getSet(), getConfirmedSet(), "Empty sets should be equal");
|
||||
verifyAll();
|
||||
|
||||
Collection set2 = makeConfirmedCollection();
|
||||
set2.add("foo");
|
||||
assertTrue("Empty set shouldn't equal nonempty set",
|
||||
!getSet().equals(set2));
|
||||
assertTrue(!getSet().equals(set2), "Empty set shouldn't equal nonempty set");
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full sets should be equal", getSet(), getConfirmedSet());
|
||||
assertEquals(getSet(), getConfirmedSet(), "Full sets should be equal");
|
||||
verifyAll();
|
||||
|
||||
set2.clear();
|
||||
set2.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Sets with different contents shouldn't be equal",
|
||||
!getSet().equals(set2));
|
||||
assertTrue(!getSet().equals(set2), "Sets with different contents shouldn't be equal");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,11 +198,9 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
@Test
|
||||
public void testSetHashCode() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
assertEquals(getSet().hashCode(), getConfirmedSet().hashCode(), "Empty sets have equal hashCodes");
|
||||
|
||||
resetFull();
|
||||
assertEquals("Equal sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
assertEquals(getSet().hashCode(), getConfirmedSet().hashCode(), "Equal sets have equal hashCodes");
|
||||
}
|
||||
}
|
||||
|
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
@@ -56,88 +54,88 @@ public class StringTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("", "");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "Empty string has elements");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", " ,.;:");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
}
|
||||
|
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* TimeoutMapTest
|
||||
* <p/>
|
||||
@@ -541,7 +539,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -573,7 +571,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -613,7 +611,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -630,7 +628,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
Object removedKey = null;
|
||||
Object otherKey = null;
|
||||
Iterator iterator = map.entrySet().iterator();
|
||||
assertTrue("Iterator was empty", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "Iterator was empty");
|
||||
try {
|
||||
Map.Entry entry = (Map.Entry) iterator.next();
|
||||
assertNotNull(entry);
|
||||
@@ -648,8 +646,8 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
fail("Elements expired between Interator.hasNext() and Iterator.remove()");
|
||||
}
|
||||
|
||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", !map.containsKey(removedKey));
|
||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", map.containsKey(otherKey));
|
||||
assertTrue(!map.containsKey(removedKey), "Wrong entry removed, keySet().iterator() is broken.");
|
||||
assertTrue(map.containsKey(otherKey), "Wrong entry removed, keySet().iterator() is broken.");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* TokenIteratorAbstractTestCase
|
||||
@@ -80,7 +78,7 @@ public abstract class TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testEmptyString() {
|
||||
Iterator iterator = createTokenIterator("");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "Empty string has elements");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ConverterTest
|
||||
@@ -43,7 +43,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class ConverterTest {
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Disabled("Not implemented")
|
||||
@Test
|
||||
public void testMe() {
|
||||
// TODO: Implement tests
|
||||
|
@@ -31,7 +31,7 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.DateUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
@@ -31,13 +31,13 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* DefaultConverterTest
|
||||
@@ -138,7 +138,7 @@ public class DefaultConverterTest extends PropertyConverterAbstractTest {
|
||||
assertEquals(-2.3456, (Double) converter.toObject("-2.3456", Double.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Ignore("Known issue. Why would anyone do something like this?")
|
||||
@Disabled("Known issue. Why would anyone do something like this?")
|
||||
@Test
|
||||
public void testConvertCharPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
|
@@ -32,11 +32,11 @@ package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PropertyConverterAbstractTest
|
||||
@@ -66,26 +66,26 @@ public abstract class PropertyConverterAbstractTest extends ObjectAbstractTest {
|
||||
try {
|
||||
obj = converter.toObject(test.original(), test.type(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
assertEquals(test.type(), obj.getClass(), String.format("'%s' converted to incorrect type", test.original()));
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
assertEquals(test.value(), obj, String.format("'%s' not converted", test.original()));
|
||||
}
|
||||
|
||||
String result = converter.toString(test.value(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' does not match", test.converted()), test.converted(), result);
|
||||
assertEquals(test.converted(), result, String.format("'%s' does not match", test.converted()));
|
||||
|
||||
obj = converter.toObject(result, test.type(), test.format());
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
assertEquals(test.type(), obj.getClass(), String.format("'%s' converted to incorrect type", test.original()));
|
||||
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
assertEquals(test.value(), obj, String.format("'%s' did not survive round trip conversion", test.original()));
|
||||
}
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
@@ -98,35 +98,35 @@ public abstract class PropertyConverterAbstractTest extends ObjectAbstractTest {
|
||||
Class<?> componentType = left.getClass().getComponentType();
|
||||
if (componentType.isPrimitive()) {
|
||||
if (int.class == componentType) {
|
||||
assertArrayEquals(message, (int[]) left, (int[]) right);
|
||||
assertArrayEquals((int[]) left, (int[]) right, message);
|
||||
}
|
||||
else if (short.class == componentType) {
|
||||
assertArrayEquals(message, (short[]) left, (short[]) right);
|
||||
assertArrayEquals((short[]) left, (short[]) right, message);
|
||||
}
|
||||
else if (long.class == componentType) {
|
||||
assertArrayEquals(message, (long[]) left, (long[]) right);
|
||||
assertArrayEquals((long[]) left, (long[]) right, message);
|
||||
}
|
||||
else if (float.class == componentType) {
|
||||
assertArrayEquals(message, (float[]) left, (float[]) right, 0f);
|
||||
assertArrayEquals((float[]) left, (float[]) right, 0f, message);
|
||||
}
|
||||
else if (double.class == componentType) {
|
||||
assertArrayEquals(message, (double[]) left, (double[]) right, 0d);
|
||||
assertArrayEquals((double[]) left, (double[]) right, 0d, message);
|
||||
}
|
||||
else if (boolean.class == componentType) {
|
||||
assertTrue(message, Arrays.equals((boolean[]) left, (boolean[]) right));
|
||||
assertTrue(Arrays.equals((boolean[]) left, (boolean[]) right), message);
|
||||
}
|
||||
else if (byte.class == componentType) {
|
||||
assertArrayEquals(message, (byte[]) left, (byte[]) right);
|
||||
assertArrayEquals((byte[]) left, (byte[]) right, message);
|
||||
}
|
||||
else if (char.class == componentType) {
|
||||
assertArrayEquals(message, (char[]) left, (char[]) right);
|
||||
assertArrayEquals((char[]) left, (char[]) right, message);
|
||||
}
|
||||
else {
|
||||
fail(String.format("Unknown primitive type: %s", componentType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertArrayEquals(message, (Object[]) left, (Object[]) right);
|
||||
assertArrayEquals((Object[]) left, (Object[]) right, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,12 +32,11 @@ package com.twelvemonkeys.util.regex;
|
||||
|
||||
import com.twelvemonkeys.util.TokenIterator;
|
||||
import com.twelvemonkeys.util.TokenIteratorAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
@@ -68,9 +67,9 @@ public class RegExTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,67 +86,67 @@ public class RegExTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", "[^ ,.;:]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
Object o = iterator.next();
|
||||
assertEquals("A", o);
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
}
|
||||
|
@@ -30,12 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import com.twelvemonkeys.util.CollectionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ServiceRegistryTest
|
||||
@@ -48,9 +49,11 @@ public class ServiceRegistryTest {
|
||||
|
||||
private final TestRegistry registry = new TestRegistry();
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new ServiceRegistry(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new ServiceRegistry(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,11 +67,12 @@ public class ServiceRegistryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ServiceConfigurationError.class)
|
||||
@Test
|
||||
public void testCreateBadConfig() {
|
||||
@SuppressWarnings("unchecked")
|
||||
ServiceRegistry registry = new ServiceRegistry(Arrays.asList(BadSPI.class).iterator());
|
||||
registry.registerApplicationClasspathSPIs();
|
||||
assertThrows(ServiceConfigurationError.class, () -> {
|
||||
ServiceRegistry registry = new ServiceRegistry(Arrays.asList(BadSPI.class).iterator());
|
||||
registry.registerApplicationClasspathSPIs();
|
||||
});
|
||||
|
||||
// DONE: Test non-class
|
||||
|
||||
|
@@ -45,9 +45,15 @@
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.11.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.11.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
Reference in New Issue
Block a user