|
| 1 | +package edu.uci.ics.crawler4j.util; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Rule; |
| 5 | +import org.junit.Test; |
| 6 | +import org.junit.rules.Timeout; |
| 7 | + |
| 8 | +public class UtilTest { |
| 9 | + |
| 10 | + @Rule |
| 11 | + public final Timeout globalTimeout = new Timeout(10000); |
| 12 | + |
| 13 | + /* testedClasses: Util */ |
| 14 | + // Test written by Diffblue Cover. |
| 15 | + @Test |
| 16 | + public void long2ByteArray() { |
| 17 | + |
| 18 | + // Arrange |
| 19 | + final long l = 0x12ff34ff56ffL; |
| 20 | + |
| 21 | + // Act |
| 22 | + final byte[] actual = Util.long2ByteArray(l); |
| 23 | + |
| 24 | + // Assert result |
| 25 | + Assert.assertArrayEquals( |
| 26 | + new byte[] {0, 0, 0x12, -1, 0x34, -1, 0x56, -1}, actual); |
| 27 | + } |
| 28 | + |
| 29 | + // Test written by Diffblue Cover. |
| 30 | + @Test |
| 31 | + public void int2ByteArray() { |
| 32 | + |
| 33 | + // Arrange |
| 34 | + final int value = 0x12ff34ff; |
| 35 | + |
| 36 | + // Act |
| 37 | + final byte[] actual = Util.int2ByteArray(value); |
| 38 | + |
| 39 | + // Assert result |
| 40 | + Assert.assertArrayEquals(new byte[] {0x12, -1, 0x34, -1}, actual); |
| 41 | + } |
| 42 | + |
| 43 | + // Test written by Diffblue Cover. |
| 44 | + @Test |
| 45 | + public void putIntInByteArray() { |
| 46 | + |
| 47 | + // Arrange |
| 48 | + final int value = 0x12ff34ff; |
| 49 | + final byte[] buf = {0, 0, 0, 0, 0, 0}; |
| 50 | + final int offset = 2; |
| 51 | + |
| 52 | + // Act |
| 53 | + Util.putIntInByteArray(value, buf, offset); |
| 54 | + |
| 55 | + // Assert side effects |
| 56 | + Assert.assertArrayEquals(new byte[] {0, 0, 0x12, -1, 0x34, -1}, buf); |
| 57 | + } |
| 58 | + |
| 59 | + // Test written by Diffblue Cover. |
| 60 | + @Test |
| 61 | + public void byteArray2Int() { |
| 62 | + |
| 63 | + // Arrange |
| 64 | + final byte[] b = {0x12, -1, 0x34, -1}; |
| 65 | + |
| 66 | + // Act |
| 67 | + final int actual = Util.byteArray2Int(b); |
| 68 | + |
| 69 | + // Assert result |
| 70 | + Assert.assertEquals(0x12ff34ff, actual); |
| 71 | + } |
| 72 | + |
| 73 | + // Test written by Diffblue Cover. |
| 74 | + @Test |
| 75 | + public void byteArray2Long() { |
| 76 | + |
| 77 | + // Arrange |
| 78 | + final byte[] b = {0, 0, 0, -1, 0x34, -1, 0x56, -1}; |
| 79 | + |
| 80 | + // Act |
| 81 | + final long actual = Util.byteArray2Long(b); |
| 82 | + |
| 83 | + // Assert result |
| 84 | + Assert.assertEquals(0x0ff34ff56ffL, actual); |
| 85 | + } |
| 86 | + |
| 87 | + // Test written by Diffblue Cover. |
| 88 | + @Test |
| 89 | + public void hasBinaryContent() { |
| 90 | + Assert.assertFalse(Util.hasBinaryContent("BAZ")); |
| 91 | + Assert.assertTrue(Util.hasBinaryContent("hhhYaimage")); |
| 92 | + } |
| 93 | + |
| 94 | + // Test written by Diffblue Cover. |
| 95 | + @Test |
| 96 | + public void hasPlainTextContent() { |
| 97 | + Assert.assertFalse(Util.hasPlainTextContent("1")); |
| 98 | + Assert.assertFalse(Util.hasPlainTextContent("htmlTTeXT")); |
| 99 | + Assert.assertTrue(Util.hasPlainTextContent("YxtEXTeXT")); |
| 100 | + } |
| 101 | + |
| 102 | + // Test written by Diffblue Cover. |
| 103 | + @Test |
| 104 | + public void hasCssTextContentOutputFalse() { |
| 105 | + Assert.assertFalse(Util.hasCssTextContent("1234")); |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments