xref: /aosp_15_r20/external/cronet/base/android/junit/src/org/chromium/base/CollectionUtilTest.java (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 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;
6 
7 import static org.junit.Assert.assertEquals;
8 
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.robolectric.annotation.Config;
12 
13 import org.chromium.base.test.BaseRobolectricTestRunner;
14 
15 import java.lang.ref.WeakReference;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 
19 /** Unit tests for {@link Log}. */
20 @RunWith(BaseRobolectricTestRunner.class)
21 @Config(manifest = Config.NONE)
22 public class CollectionUtilTest {
23     /** Tests that the computed call origin is the correct one. */
24     @Test
testStrengthen()25     public void testStrengthen() {
26         // Java never GC's small constants, so there's no risk of the weak refs becoming null.
27         ArrayList<WeakReference<Integer>> weakList = new ArrayList<>();
28         weakList.add(new WeakReference<>(0));
29         weakList.add(new WeakReference<>(1));
30         weakList.add(new WeakReference<>(2));
31 
32         assertEquals(Arrays.asList(0, 1, 2), CollectionUtil.strengthen(weakList));
33 
34         weakList.set(1, new WeakReference<>(null));
35         assertEquals(Arrays.asList(0, 2), CollectionUtil.strengthen(weakList));
36     }
37 }
38