| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.test.InstrumentationTestCase; | 7 import android.test.InstrumentationTestCase; |
| 8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 | 9 |
| 10 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
| 11 | 11 |
| 12 import java.util.Collection; |
| 12 import java.util.Iterator; | 13 import java.util.Iterator; |
| 13 import java.util.NoSuchElementException; | 14 import java.util.NoSuchElementException; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * Tests for (@link ObserverList}. | 17 * Tests for (@link ObserverList}. |
| 17 */ | 18 */ |
| 18 public class ObserverListTest extends InstrumentationTestCase { | 19 public class ObserverListTest extends InstrumentationTestCase { |
| 19 interface Observer { | 20 interface Observer { |
| 20 void observe(int x); | 21 void observe(int x); |
| 21 } | 22 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 mList = list; | 64 mList = list; |
| 64 mDoomed = innocent; | 65 mDoomed = innocent; |
| 65 } | 66 } |
| 66 | 67 |
| 67 @Override | 68 @Override |
| 68 public void observe(int x) { | 69 public void observe(int x) { |
| 69 mList.removeObserver(mDoomed); | 70 mList.removeObserver(mDoomed); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 74 @SuppressWarnings("ElementsCountedInLoop") |
| 73 private static <T> int getSizeOfIterable(Iterable<T> iterable) { | 75 private static <T> int getSizeOfIterable(Iterable<T> iterable) { |
| 76 if (iterable instanceof Collection<?>) return ((Collection<?>) iterable)
.size(); |
| 74 int num = 0; | 77 int num = 0; |
| 75 for (T el : iterable) num++; | 78 for (T el : iterable) num++; |
| 76 return num; | 79 return num; |
| 77 } | 80 } |
| 78 | 81 |
| 79 @SmallTest | 82 @SmallTest |
| 80 @Feature({"Android-AppBase"}) | 83 @Feature({"Android-AppBase"}) |
| 81 public void testRemoveWhileIteration() { | 84 public void testRemoveWhileIteration() { |
| 82 ObserverList<Observer> observerList = new ObserverList<Observer>(); | 85 ObserverList<Observer> observerList = new ObserverList<Observer>(); |
| 83 Foo a = new Foo(1); | 86 Foo a = new Foo(1); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 assertTrue(observerList.isEmpty()); | 320 assertTrue(observerList.isEmpty()); |
| 318 | 321 |
| 319 observerList.removeObserver(a); | 322 observerList.removeObserver(a); |
| 320 observerList.removeObserver(b); | 323 observerList.removeObserver(b); |
| 321 observerList.removeObserver(null); | 324 observerList.removeObserver(null); |
| 322 observerList.removeObserver(new Object()); | 325 observerList.removeObserver(new Object()); |
| 323 assertEquals(0, observerList.size()); | 326 assertEquals(0, observerList.size()); |
| 324 assertTrue(observerList.isEmpty()); | 327 assertTrue(observerList.isEmpty()); |
| 325 } | 328 } |
| 326 } | 329 } |
| OLD | NEW |