Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for util #411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crawler4j/src/main/java/edu/uci/ics/crawler4j/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public static int byteArray2Int(byte[] b) {
}

public static long byteArray2Long(byte[] b) {
int value = 0;
long value = 0;
for (int i = 0; i < 8; i++) {
int shift = (8 - 1 - i) * 8;
value += (b[i] & 0x000000FF) << shift;
value += (b[i] & 0x000000FFL) << shift;
}
return value;
}
Expand Down
108 changes: 108 additions & 0 deletions crawler4j/src/test/java/edu/uci/ics/crawler4j/tests/util/UtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package edu.uci.ics.crawler4j.util;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

public class UtilTest {

@Rule
public final Timeout globalTimeout = new Timeout(10000);

/* testedClasses: Util */
// Test written by Diffblue Cover.
@Test
public void long2ByteArray() {

// Arrange
final long l = 0x12ff34ff56ffL;

// Act
final byte[] actual = Util.long2ByteArray(l);

// Assert result
Assert.assertArrayEquals(
new byte[] {0, 0, 0x12, -1, 0x34, -1, 0x56, -1}, actual);
}

// Test written by Diffblue Cover.
@Test
public void int2ByteArray() {

// Arrange
final int value = 0x12ff34ff;

// Act
final byte[] actual = Util.int2ByteArray(value);

// Assert result
Assert.assertArrayEquals(new byte[] {0x12, -1, 0x34, -1}, actual);
}

// Test written by Diffblue Cover.
@Test
public void putIntInByteArray() {

// Arrange
final int value = 0x12ff34ff;
final byte[] buf = {0, 0, 0, 0, 0, 0};
final int offset = 2;

// Act
Util.putIntInByteArray(value, buf, offset);

// Assert side effects
Assert.assertArrayEquals(new byte[] {0, 0, 0x12, -1, 0x34, -1}, buf);
}

// Test written by Diffblue Cover.
@Test
public void byteArray2Int() {

// Arrange
final byte[] b = {0x12, -1, 0x34, -1};

// Act
final int actual = Util.byteArray2Int(b);

// Assert result
Assert.assertEquals(0x12ff34ff, actual);
}

// Test written by Diffblue Cover.
@Test
public void byteArray2Long() {

// Arrange
final byte[] b = {0, 0, 0, -1, 0x34, -1, 0x56, -1};

// Act
final long actual = Util.byteArray2Long(b);

// Assert result
Assert.assertEquals(0x0ff34ff56ffL, actual);
}

// Test written by Diffblue Cover.
@Test
public void hasBinaryContent() {
Assert.assertFalse(Util.hasBinaryContent("BAZ"));
Assert.assertTrue(Util.hasBinaryContent("hhhYaimage"));
}

// Test written by Diffblue Cover.
@Test
public void hasPlainTextContent() {
Assert.assertFalse(Util.hasPlainTextContent("1"));
Assert.assertFalse(Util.hasPlainTextContent("htmlTTeXT"));
Assert.assertTrue(Util.hasPlainTextContent("YxtEXTeXT"));
}

// Test written by Diffblue Cover.
@Test
public void hasCssTextContentOutputFalse() {
Assert.assertFalse(Util.hasCssTextContent("1234"));
}

}