| 1 |
/* |
| 2 |
* Copyright (c) 2021 Goldman Sachs. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* and Eclipse Distribution License v. 1.0 which accompany this distribution. |
| 6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* and the Eclipse Distribution License is available at |
| 8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 |
*/ |
| 10 |
|
| 11 |
package org.eclipse.collections.impl.collection.mutable |
| 12 |
|
| 13 |
import org.eclipse.collections.api.collection.MutableCollection |
| 14 |
import org.eclipse.collections.api.list.MutableList |
| 15 |
import org.eclipse.collections.impl.Prelude._ |
| 16 |
import org.eclipse.collections.impl.list.mutable.FastList |
| 17 |
import org.eclipse.collections.impl.{SynchronizedCollectionTestTrait, SynchronizedRichIterableTestTrait} |
| 18 |
import org.junit.Test |
| 19 |
|
| 20 |
trait SynchronizedMutableCollectionTestTrait |
| 21 |
extends SynchronizedRichIterableTestTrait |
| 22 |
with SynchronizedCollectionTestTrait |
| 23 |
with MutableCollectionTestTrait |
| 24 |
{ |
| 25 |
val classUnderTest: MutableCollection[String] |
| 26 |
|
| 27 |
@Test |
| 28 |
def newEmpty_synchronized |
| 29 |
{ |
| 30 |
this.assertSynchronized |
| 31 |
{ |
| 32 |
this.classUnderTest.newEmpty |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* {@link SynchronizedRichIterableTestTrait} and {@link SynchronizedCollectionTestTrait} both define these methods |
| 38 |
* the same way. They need to be overridden to point to one. Which one to pick was an arbitrary choice. |
| 39 |
*/ |
| 40 |
override def size_synchronized = super[SynchronizedRichIterableTestTrait].size_synchronized |
| 41 |
|
| 42 |
override def isEmpty_synchronized = super[SynchronizedRichIterableTestTrait].isEmpty_synchronized |
| 43 |
|
| 44 |
override def contains_synchronized = super[SynchronizedRichIterableTestTrait].contains_synchronized |
| 45 |
|
| 46 |
override def iterator_not_synchronized = super[SynchronizedRichIterableTestTrait].iterator_not_synchronized |
| 47 |
|
| 48 |
override def toArray_synchronized = super[SynchronizedRichIterableTestTrait].toArray_synchronized |
| 49 |
|
| 50 |
override def toArray_with_target_synchronized = super[SynchronizedRichIterableTestTrait].toArray_with_target_synchronized |
| 51 |
|
| 52 |
@Test |
| 53 |
def addAllIterable_synchronized |
| 54 |
{ |
| 55 |
this.assertSynchronized |
| 56 |
{ |
| 57 |
this.classUnderTest.addAllIterable(FastList.newList[String]) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
@Test |
| 62 |
def removeAllIterable_synchronized |
| 63 |
{ |
| 64 |
this.assertSynchronized |
| 65 |
{ |
| 66 |
this.classUnderTest.removeAllIterable(FastList.newList[String]) |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
def retainAllIterable_synchronized |
| 72 |
{ |
| 73 |
this.assertSynchronized |
| 74 |
{ |
| 75 |
this.classUnderTest.retainAllIterable(FastList.newList[String]) |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
@Test |
| 80 |
def selectWith_synchronized |
| 81 |
{ |
| 82 |
this.assertSynchronized |
| 83 |
{ |
| 84 |
this.classUnderTest.selectWith({ |
| 85 |
(_: String, _: String) => false |
| 86 |
}, "") |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
@Test |
| 91 |
def selectWith_with_target_synchronized |
| 92 |
{ |
| 93 |
this.assertSynchronized |
| 94 |
{ |
| 95 |
this.classUnderTest.selectWith({ |
| 96 |
(_: String, _: String) => false |
| 97 |
}, "", FastList.newList[String]) |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
@Test |
| 102 |
def rejectWith_synchronized |
| 103 |
{ |
| 104 |
this.assertSynchronized |
| 105 |
{ |
| 106 |
this.classUnderTest.rejectWith({ |
| 107 |
(_: String, _: String) => true |
| 108 |
}, "") |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
@Test |
| 113 |
def rejectWith_with_target_synchronized |
| 114 |
{ |
| 115 |
this.assertSynchronized |
| 116 |
{ |
| 117 |
this.classUnderTest.rejectWith({ |
| 118 |
(_: String, _: String) => true |
| 119 |
}, "", FastList.newList[String]) |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
@Test |
| 124 |
def selectAndRejectWith_synchronized |
| 125 |
{ |
| 126 |
this.assertSynchronized |
| 127 |
{ |
| 128 |
this.classUnderTest.selectAndRejectWith({ |
| 129 |
(_: String, _: String) => true |
| 130 |
}, "") |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
@Test |
| 135 |
def removeIf_synchronized |
| 136 |
{ |
| 137 |
this.assertSynchronized |
| 138 |
{ |
| 139 |
this.classUnderTest.removeIf({ |
| 140 |
(_: String) => false |
| 141 |
}) |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
@Test |
| 146 |
def removeIfWith_synchronized |
| 147 |
{ |
| 148 |
this.assertSynchronized |
| 149 |
{ |
| 150 |
this.classUnderTest.removeIfWith({ |
| 151 |
(_: String, _: String) => false |
| 152 |
}, "") |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
@Test |
| 157 |
def collectWith_synchronized |
| 158 |
{ |
| 159 |
this.assertSynchronized |
| 160 |
{ |
| 161 |
this.classUnderTest.collectWith({ |
| 162 |
(_: String, _: String) => "" |
| 163 |
}, "") |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
@Test |
| 168 |
def collectWith_with_target_synchronized |
| 169 |
{ |
| 170 |
this.assertSynchronized |
| 171 |
{ |
| 172 |
this.classUnderTest.collectWith[String, String, MutableList[String]]( |
| 173 |
{ |
| 174 |
(_: String, _: String) => "" |
| 175 |
}, |
| 176 |
"", |
| 177 |
FastList.newList[String]) |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
@Test |
| 182 |
def detectWith_synchronized |
| 183 |
{ |
| 184 |
this.assertSynchronized |
| 185 |
{ |
| 186 |
this.classUnderTest.detectWith({ |
| 187 |
(_: String, _: String) => true |
| 188 |
}, "") |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
@Test |
| 193 |
def detectWithIfNone_synchronized |
| 194 |
{ |
| 195 |
this.assertSynchronized |
| 196 |
{ |
| 197 |
this.classUnderTest.detectWithIfNone({ |
| 198 |
(_: String, _: String) => true |
| 199 |
}, "", null) |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
@Test |
| 204 |
def countWith_synchronized |
| 205 |
{ |
| 206 |
this.assertSynchronized |
| 207 |
{ |
| 208 |
this.classUnderTest.countWith({ |
| 209 |
(_: String, _: String) => true |
| 210 |
}, "") |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
@Test |
| 215 |
def injectIntoWith_synchronized |
| 216 |
{ |
| 217 |
this.assertSynchronized |
| 218 |
{ |
| 219 |
this.classUnderTest.injectIntoWith[String, String]("", (_: String, _: String, _: String) => "", "") |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
@Test |
| 224 |
def asUnmodifiable_synchronized |
| 225 |
{ |
| 226 |
this.assertSynchronized |
| 227 |
{ |
| 228 |
this.classUnderTest.asUnmodifiable |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
@Test |
| 233 |
def asSynchronized_not_synchronized |
| 234 |
{ |
| 235 |
this.assertNotSynchronized |
| 236 |
{ |
| 237 |
this.classUnderTest.asSynchronized |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
@Test |
| 242 |
def toImmutable_synchronized |
| 243 |
{ |
| 244 |
this.assertSynchronized |
| 245 |
{ |
| 246 |
this.classUnderTest.toImmutable |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
@Test |
| 251 |
def with_synchronized |
| 252 |
{ |
| 253 |
this.assertSynchronized(this.classUnderTest.`with`("4")) |
| 254 |
} |
| 255 |
|
| 256 |
@Test |
| 257 |
def withAll_synchronized |
| 258 |
{ |
| 259 |
this.assertSynchronized(this.classUnderTest.withAll(FastList.newListWith("4"))) |
| 260 |
} |
| 261 |
|
| 262 |
@Test |
| 263 |
def without_synchronized |
| 264 |
{ |
| 265 |
this.assertSynchronized(this.classUnderTest.without("4")) |
| 266 |
} |
| 267 |
|
| 268 |
@Test |
| 269 |
def withoutAll_synchronized |
| 270 |
{ |
| 271 |
this.assertSynchronized(this.classUnderTest.withoutAll(FastList.newListWith("4"))) |
| 272 |
} |
| 273 |
} |