Testing Lottie Animation Composition Cache Implementation in lottie-android
This test suite validates the caching functionality of Lottie animations in the Android implementation. It focuses on testing the LottieCompositionCache class which manages caching of animation compositions for improved performance and resource management.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
airbnb/lottie-android
lottie/src/test/java/com/airbnb/lottie/model/LottieCompositionCacheTest.java
package com.airbnb.lottie.model;
import com.airbnb.lottie.BaseTest;
import com.airbnb.lottie.LottieComposition;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class LottieCompositionCacheTest extends BaseTest {
private LottieComposition composition;
private LottieCompositionCache cache;
@Before
public void setup() {
composition = Mockito.mock(LottieComposition.class);
cache = new LottieCompositionCache();
}
@Test
public void testEmpty() {
assertNull(cache.get("foo"));
}
@Test
public void testStrongAsset() {
cache.put("foo", composition);
assertEquals(composition, cache.get("foo"));
}
@Test
public void testWeakAsset() {
cache.put("foo", composition);
assertEquals(composition, cache.get("foo"));
}
}