Testing BytesResource Array Management in Glide Framework
A comprehensive unit test suite for Glide’s BytesResource class that validates byte array handling and resource management. The tests ensure proper byte array storage, size reporting, and null input validation in the BytesResource implementation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
bumptech/glide
library/test/src/test/java/com/bumptech/glide/load/resource/bytes/BytesResourceTest.java
package com.bumptech.glide.load.resource.bytes;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class BytesResourceTest {
@Test
public void testReturnsGivenBytes() {
byte[] bytes = new byte[0];
BytesResource resource = new BytesResource(bytes);
assertEquals(bytes, resource.get());
}
@Test
public void testReturnsSizeOfGivenBytes() {
byte[] bytes = new byte[123];
BytesResource resource = new BytesResource(bytes);
assertEquals(bytes.length, resource.getSize());
}
@Test(expected = NullPointerException.class)
public void testThrowsIfGivenNullBytes() {
new BytesResource(null);
}
}