Testing SimpleResource Object Management in Glide Library
This test suite validates the SimpleResource class functionality in the Glide library, focusing on resource object handling and null value validation. The tests ensure proper object retrieval and error handling behaviors.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
bumptech/glide
library/test/src/test/java/com/bumptech/glide/load/resource/SimpleResourceTest.java
package com.bumptech.glide.load.resource;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class SimpleResourceTest {
private Anything object;
private SimpleResource<?> resource;
@Before
public void setUp() {
object = new Anything();
resource = new SimpleResource<>(object);
}
@Test
public void testReturnsGivenObject() {
assertEquals(object, resource.get());
}
@Test
public void testReturnsGivenObjectMultipleTimes() {
assertEquals(object, resource.get());
assertEquals(object, resource.get());
assertEquals(object, resource.get());
}
@Test(expected = NullPointerException.class)
public void testThrowsIfGivenNullData() {
new SimpleResource<>(null);
}
private static class Anything {}
}