Testing View Property Animation Transitions in Glide Library
This test suite validates the ViewPropertyViewTransitionAnimationFactory class in Glide, focusing on animation transitions based on data source and resource state. It ensures proper animation handling for memory cache, disk cache, and first-time resource loading scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
bumptech/glide
library/test/src/test/java/com/bumptech/glide/request/transition/ViewPropertyViewTransitionAnimationFactoryTest.java
package com.bumptech.glide.request.transition;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.mock;
import com.bumptech.glide.load.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ViewPropertyViewTransitionAnimationFactoryTest {
private ViewPropertyAnimationFactory<Object> factory;
@Before
public void setUp() {
ViewPropertyTransition.Animator animator = mock(ViewPropertyTransition.Animator.class);
factory = new ViewPropertyAnimationFactory<>(animator);
}
@Test
public void testReturnsNoAnimationIfFromMemoryCache() {
assertEquals(
NoTransition.get(), factory.build(DataSource.MEMORY_CACHE, true /*isFirstResource*/));
}
@Test
public void testReturnsNoAnimationIfNotFirstResource() {
assertEquals(
NoTransition.get(), factory.build(DataSource.DATA_DISK_CACHE, false /*isFirstResource*/));
}
@Test
public void testReturnsAnimationIfNotFromMemoryCacheAndFirstResource() {
assertNotEquals(
NoTransition.get(), factory.build(DataSource.DATA_DISK_CACHE, true /*isFirstResource*/));
}
}