• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.base.util;
6 
7 import static org.junit.Assert.assertFalse;
8 import static org.junit.Assert.assertNotNull;
9 import static org.junit.Assert.assertTrue;
10 
11 import static org.chromium.base.GarbageCollectionTestUtils.canBeGarbageCollected;
12 
13 import android.graphics.Bitmap;
14 
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.robolectric.annotation.Config;
18 
19 import org.chromium.base.GarbageCollectionTestUtils;
20 import org.chromium.base.test.BaseRobolectricTestRunner;
21 
22 import java.lang.ref.WeakReference;
23 
24 /** Tests for {@link GarbageCollectionTestUtils}. */
25 @RunWith(BaseRobolectricTestRunner.class)
26 @Config(manifest = Config.NONE)
27 public class GarbageCollectionTestUtilsUnitTest {
28     @Test
testCanBeGarbageCollected()29     public void testCanBeGarbageCollected() {
30         Bitmap bitmap = Bitmap.createBitmap(1, 2, Bitmap.Config.ARGB_8888);
31         WeakReference<Bitmap> bitmapWeakReference = new WeakReference<>(bitmap);
32         assertNotNull(bitmapWeakReference.get());
33         assertFalse(canBeGarbageCollected(bitmapWeakReference));
34 
35         bitmap = null;
36         assertTrue(canBeGarbageCollected(bitmapWeakReference));
37     }
38 }
39