How to use List.shouldExistInOrder method of io.kotest.matchers.collections.matchers class

Best Kotest code snippet using io.kotest.matchers.collections.matchers.List.shouldExistInOrder

TraceIteratorTest.kt

Source:TraceIteratorTest.kt Github

copy

Full Screen

1/*2 * This file is part of OMJ.3 *4 * OMJ is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 3 of the License, or7 * (at your option) any later version.8 *9 * OMJ is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with OMJ. If not, see <https://www.gnu.org/licenses/>.16 */17package com.octogonapus.omj.ui.model18import com.octogonapus.omj.testutil.CompileUtil19import io.kotest.assertions.throwables.shouldThrow20import io.kotest.matchers.collections.shouldBeStrictlyIncreasingWith21import io.kotest.matchers.collections.shouldExist22import io.kotest.matchers.collections.shouldExistInOrder23import io.kotest.matchers.collections.shouldHaveSize24import mu.KotlinLogging25import org.junit.jupiter.api.Nested26import org.junit.jupiter.api.Test27import org.junit.jupiter.api.io.TempDir28import java.io.BufferedInputStream29import java.io.File30import java.io.FileInputStream31internal class TraceIteratorTest {32 @Nested33 inner class MethodTraceTests {34 @Test35 fun `parse method call with no args`(@TempDir tempDir: File) {36 val traces = generateTraces(tempDir, "agent-test_noargs.jar")37 traces.shouldExistInOrder(38 {39 it.constructorCall(40 receiverType = "com.agenttest.noargs.Foo",41 callerClass = "com.agenttest.noargs.Main"42 )43 },44 {45 it.virtualMethodCall(46 receiverType = "com.agenttest.noargs.Foo",47 callerClass = "com.agenttest.noargs.Main",48 methodName = "with"49 )50 }51 )52 }53 @Test54 fun `parse method call with args byte 3C`(@TempDir tempDir: File) {55 val traces = generateTraces(tempDir, "agent-test_byte3c.jar")56 traces.shouldExistInOrder(57 {58 it.constructorCall(59 receiverType = "com.agenttest.byte3c.Foo",60 callerClass = "com.agenttest.byte3c.Main"61 )62 },63 {64 it.virtualMethodCall(65 receiverType = "com.agenttest.byte3c.Foo",66 methodName = "with",67 callerClass = "com.agenttest.byte3c.Main",68 args = listOf("byte" to "60")69 )70 }71 )72 }73 @Test74 fun `parse method call with args char Q`(@TempDir tempDir: File) {75 val traces = generateTraces(tempDir, "agent-test_charQ.jar")76 traces.shouldExistInOrder(77 {78 it.constructorCall(79 receiverType = "com.agenttest.charQ.Foo",80 callerClass = "com.agenttest.charQ.Main"81 )82 },83 {84 it.virtualMethodCall(85 receiverType = "com.agenttest.charQ.Foo",86 methodName = "with",87 callerClass = "com.agenttest.charQ.Main",88 args = listOf("char" to "Q")89 )90 }91 )92 }93 @Test94 fun `parse method call with args double 1p2`(@TempDir tempDir: File) {95 val traces = generateTraces(tempDir, "agent-test_double1p2.jar")96 traces.shouldExistInOrder(97 {98 it.constructorCall(99 receiverType = "com.agenttest.double1p2.Foo",100 callerClass = "com.agenttest.double1p2.Main"101 )102 },103 {104 it.virtualMethodCall(105 receiverType = "com.agenttest.double1p2.Foo",106 methodName = "with",107 callerClass = "com.agenttest.double1p2.Main",108 args = listOf("double" to "1.2")109 )110 }111 )112 }113 @Test114 fun `parse method call with args float 4p3`(@TempDir tempDir: File) {115 val traces = generateTraces(tempDir, "agent-test_float4p3.jar")116 traces.shouldExistInOrder(117 {118 it.constructorCall(119 receiverType = "com.agenttest.float4p3.Foo",120 callerClass = "com.agenttest.float4p3.Main"121 )122 },123 {124 it.virtualMethodCall(125 receiverType = "com.agenttest.float4p3.Foo",126 methodName = "with",127 callerClass = "com.agenttest.float4p3.Main",128 args = listOf("float" to "4.3")129 )130 }131 )132 }133 @Test134 fun `parse method call with args int 42`(@TempDir tempDir: File) {135 val traces = generateTraces(tempDir, "agent-test_int42.jar")136 traces.shouldExistInOrder(137 {138 it.constructorCall(139 receiverType = "com.agenttest.int42.Foo",140 callerClass = "com.agenttest.int42.Main"141 )142 },143 {144 it.virtualMethodCall(145 receiverType = "com.agenttest.int42.Foo",146 methodName = "with",147 callerClass = "com.agenttest.int42.Main",148 args = listOf("int" to "42")149 )150 }151 )152 }153 @Test154 fun `parse method call with args long 123456789123456789`(@TempDir tempDir: File) {155 val traces = generateTraces(tempDir, "agent-test_long123456789123456789.jar")156 traces.shouldExistInOrder(157 {158 it.constructorCall(159 receiverType = "com.agenttest.long123456789123456789.Foo",160 callerClass = "com.agenttest.long123456789123456789.Main"161 )162 },163 {164 it.virtualMethodCall(165 receiverType = "com.agenttest.long123456789123456789.Foo",166 methodName = "with",167 callerClass = "com.agenttest.long123456789123456789.Main",168 args = listOf("long" to "123456789123456789")169 )170 }171 )172 }173 @Test174 fun `parse method call with args string hello`(@TempDir tempDir: File) {175 val traces = generateTraces(tempDir, "agent-test_stringHello.jar")176 traces.shouldExistInOrder(177 {178 it.constructorCall(179 receiverType = "com.agenttest.stringHello.Foo",180 callerClass = "com.agenttest.stringHello.Main"181 )182 },183 {184 it.virtualMethodCall(185 receiverType = "com.agenttest.stringHello.Foo",186 methodName = "with",187 callerClass = "com.agenttest.stringHello.Main",188 args = listOf("java.lang.String" to "Hello")189 )190 }191 )192 }193 @Test194 fun `parse method call with args string hello with null byte`(@TempDir tempDir: File) {195 val traces = generateTraces(tempDir, "agent-test_stringHelloNull1.jar")196 traces.shouldExistInOrder(197 {198 it.constructorCall(199 receiverType = "com.agenttest.stringHelloNull1.Foo",200 callerClass = "com.agenttest.stringHelloNull1.Main"201 )202 },203 {204 it.virtualMethodCall(205 receiverType = "com.agenttest.stringHelloNull1.Foo",206 methodName = "with",207 callerClass = "com.agenttest.stringHelloNull1.Main",208 args = listOf("java.lang.String" to "Hello\u0000 1")209 )210 }211 )212 }213 @Test214 fun `parse method call with args object`(@TempDir tempDir: File) {215 val traces = generateTraces(tempDir, "agent-test_objectStringArray.jar")216 traces.shouldExistInOrder(217 {218 it.constructorCall(219 receiverType = "com.agenttest.objectStringArray.Foo",220 callerClass = "com.agenttest.objectStringArray.Main"221 )222 },223 {224 it.virtualMethodCall(225 receiverType = "com.agenttest.objectStringArray.Foo",226 methodName = "with",227 callerClass = "com.agenttest.objectStringArray.Main",228 args = listOf("[Ljava.lang.String;" to null)229 )230 }231 )232 }233 @Test234 fun `parse method call with args short 12345`(@TempDir tempDir: File) {235 val traces = generateTraces(tempDir, "agent-test_short12345.jar")236 traces.shouldExistInOrder(237 {238 it.constructorCall(239 receiverType = "com.agenttest.short12345.Foo",240 callerClass = "com.agenttest.short12345.Main"241 )242 },243 {244 it.virtualMethodCall(245 receiverType = "com.agenttest.short12345.Foo",246 methodName = "with",247 callerClass = "com.agenttest.short12345.Main",248 args = listOf("short" to "12345")249 )250 }251 )252 }253 @Test254 fun `parse method call with args boolean true`(@TempDir tempDir: File) {255 val traces = generateTraces(tempDir, "agent-test_booleanTrue.jar")256 traces.shouldExistInOrder(257 {258 it.constructorCall(259 receiverType = "com.agenttest.booleanTrue.Foo",260 callerClass = "com.agenttest.booleanTrue.Main"261 )262 },263 {264 it.virtualMethodCall(265 receiverType = "com.agenttest.booleanTrue.Foo",266 methodName = "with",267 callerClass = "com.agenttest.booleanTrue.Main",268 args = listOf("boolean" to "true")269 )270 }271 )272 }273 @Test274 fun `parse method call with args object MyDataClass`(@TempDir tempDir: File) {275 val traces = generateTraces(tempDir, "agent-test_objectTestDataClass.jar")276 traces.shouldExistInOrder(277 {278 it.constructorCall(279 receiverType = "com.agenttest.objectTestDataClass.Foo",280 callerClass = "com.agenttest.objectTestDataClass.Main"281 )282 },283 {284 it.virtualMethodCall(285 receiverType = "com.agenttest.objectTestDataClass.Foo",286 methodName = "with",287 callerClass = "com.agenttest.objectTestDataClass.Main",288 args = listOf("com.agenttest.objectTestDataClass.TestDataClass" to null)289 )290 }291 )292 }293 @Test294 fun `parse constructor call with int 6`(@TempDir tempDir: File) {295 val traces = generateTraces(tempDir, "agent-test_constructorInt6.jar")296 traces.shouldExistInOrder(297 {298 it.constructorCall(299 receiverType = "com.agenttest.constructorInt6.Foo",300 callerClass = "com.agenttest.constructorInt6.Main",301 args = listOf("int" to "6")302 )303 }304 )305 }306 @Test307 fun `parse a static method call in a static block`(@TempDir tempDir: File) {308 val traces = generateTraces(tempDir, "agent-test_staticBlockCallStaticMethod.jar")309 traces.shouldExistInOrder(310 {311 it.staticMethodCall(312 methodName = "callMe",313 callerClass = "com.agenttest.staticBlockCallStaticMethod.Foo"314 )315 }316 )317 }318 @Test319 fun `parse a static method call with an int after a double`(@TempDir tempDir: File) {320 val traces = generateTraces(tempDir, "agent-test_methodCallIntAfterDouble.jar")321 traces.shouldExistInOrder(322 {323 it.staticMethodCall(324 methodName = "callMe",325 callerClass = "com.agenttest.methodCallIntAfterDouble.Main",326 args = listOf("double" to "4.2", "int" to "1")327 )328 }329 )330 }331 }332 @Nested333 inner class LocalVariableStoreTraceTests {334 @Test335 fun `test boolean store`(@TempDir tempDir: File) {336 val traces = generateTraces(tempDir, "agent-test_storeBoolean.jar")337 traces.shouldExist {338 it.storeVar("com.agenttest.storeBoolean.Main", "boolean", "b", "true")339 }340 }341 @Test342 fun `test byte store`(@TempDir tempDir: File) {343 val traces = generateTraces(tempDir, "agent-test_storeByte.jar")344 traces.shouldExist {345 it.storeVar("com.agenttest.storeByte.Main", "byte", "b", "250")346 }347 }348 @Test349 fun `test char store`(@TempDir tempDir: File) {350 val traces = generateTraces(tempDir, "agent-test_storeChar.jar")351 traces.shouldExist {352 it.storeVar("com.agenttest.storeChar.Main", "char", "c", "Q")353 }354 }355 @Test356 fun `test double store`(@TempDir tempDir: File) {357 val traces = generateTraces(tempDir, "agent-test_storeDouble.jar")358 traces.shouldExist {359 it.storeVar("com.agenttest.storeDouble.Main", "double", "d", "4.2")360 }361 }362 @Test363 fun `test float store`(@TempDir tempDir: File) {364 val traces = generateTraces(tempDir, "agent-test_storeFloat.jar")365 traces.shouldExist {366 it.storeVar("com.agenttest.storeFloat.Main", "float", "f", "2.3")367 }368 }369 @Test370 fun `test int store`(@TempDir tempDir: File) {371 val traces = generateTraces(tempDir, "agent-test_storeInt.jar")372 traces.shouldExist {373 it.storeVar("com.agenttest.storeInt.Main", "int", "i", "123456")374 }375 }376 @Test377 fun `test long store`(@TempDir tempDir: File) {378 val traces = generateTraces(tempDir, "agent-test_storeLong.jar")379 traces.shouldExist {380 it.storeVar("com.agenttest.storeLong.Main", "long", "l", "123456789123456789")381 }382 }383 @Test384 fun `test ref store`(@TempDir tempDir: File) {385 val traces = generateTraces(tempDir, "agent-test_storeRef.jar")386 traces.shouldExist {387 it.storeVar("com.agenttest.storeRef.Main", "java.lang.Object", "o", null)388 }389 }390 @Test391 fun `test short store`(@TempDir tempDir: File) {392 val traces = generateTraces(tempDir, "agent-test_storeShort.jar")393 traces.shouldExist {394 it.storeVar("com.agenttest.storeShort.Main", "short", "s", "12345")395 }396 }397 @Test398 fun `test string store`(@TempDir tempDir: File) {399 val traces = generateTraces(tempDir, "agent-test_storeString.jar")400 traces.shouldExist {401 it.storeVar("com.agenttest.storeString.Main", "java.lang.String", "s", "My String")402 }403 }404 @Test405 fun `test int increment`(@TempDir tempDir: File) {406 val traces = generateTraces(tempDir, "agent-test_storeIncrementInt.jar")407 traces.shouldExist {408 // Started at 3 and was incremented to 4409 it.storeVar("com.agenttest.storeIncrementInt.Main", "int", "i", "4")410 }411 }412 @Test413 fun `test int array store`(@TempDir tempDir: File) {414 val traces = generateTraces(tempDir, "agent-test_storeIntArray.jar")415 traces.shouldExistInOrder(416 {417 it.storeVar("com.agenttest.storeIntArray.Main", "[I", "i", null)418 },419 {420 it.storeArray(421 containingClass = "com.agenttest.storeIntArray.Main",422 varType = "int",423 arrayIndex = 0,424 value = "6"425 )426 }427 )428 }429 @Test430 fun `test int array store one-liner`(@TempDir tempDir: File) {431 val traces = generateTraces(tempDir, "agent-test_storeIntArrayOneLiner.jar")432 traces.shouldExistInOrder(433 {434 it.storeArray(435 containingClass = "com.agenttest.storeIntArrayOneLiner.Main",436 varType = "int",437 arrayIndex = 0,438 value = "6"439 )440 },441 {442 it.storeVar("com.agenttest.storeIntArrayOneLiner.Main", "[I", "i", null)443 }444 )445 }446 @Test447 fun `test double array store`(@TempDir tempDir: File) {448 val traces = generateTraces(tempDir, "agent-test_storeDoubleArray.jar")449 traces.shouldExistInOrder(450 {451 it.storeVar("com.agenttest.storeDoubleArray.Main", "[D", "d", null)452 },453 {454 it.storeArray(455 containingClass = "com.agenttest.storeDoubleArray.Main",456 varType = "double",457 arrayIndex = 0,458 value = "4.2"459 )460 }461 )462 }463 @Test464 fun `test double array store one-liner`(@TempDir tempDir: File) {465 val traces = generateTraces(tempDir, "agent-test_storeDoubleArrayOneLiner.jar")466 traces.shouldExistInOrder(467 {468 it.storeArray(469 containingClass = "com.agenttest.storeDoubleArrayOneLiner.Main",470 varType = "double",471 arrayIndex = 0,472 value = "4.2"473 )474 },475 {476 it.storeVar("com.agenttest.storeDoubleArrayOneLiner.Main", "[D", "d", null)477 }478 )479 }480 @Test481 fun `test object array store`(@TempDir tempDir: File) {482 val traces = generateTraces(tempDir, "agent-test_storeObjectArray.jar")483 traces.shouldExistInOrder(484 {485 it.storeVar(486 "com.agenttest.storeObjectArray.Main",487 "[Ljava.lang.Object;",488 "o",489 null490 )491 },492 {493 it.storeArray(494 containingClass = "com.agenttest.storeObjectArray.Main",495 varType = "java.lang.Object",496 arrayIndex = 0,497 value = null498 )499 }500 )501 }502 @Test503 fun `test object array store one-liner`(@TempDir tempDir: File) {504 val traces = generateTraces(tempDir, "agent-test_storeObjectArrayOneLiner.jar")505 traces.shouldExistInOrder(506 {507 it.storeArray(508 containingClass = "com.agenttest.storeObjectArrayOneLiner.Main",509 varType = "java.lang.Object",510 arrayIndex = 0,511 value = null512 )513 },514 {515 it.storeVar(516 "com.agenttest.storeObjectArrayOneLiner.Main",517 "[Ljava.lang.Object;",518 "o",519 null520 )521 }522 )523 }524 @Test525 fun `test string array store`(@TempDir tempDir: File) {526 val traces = generateTraces(tempDir, "agent-test_storeStringArray.jar")527 traces.shouldExistInOrder(528 {529 it.storeVar(530 "com.agenttest.storeStringArray.Main",531 "[Ljava.lang.String;",532 "o",533 null534 )535 },536 {537 it.storeArray(538 containingClass = "com.agenttest.storeStringArray.Main",539 varType = "java.lang.String",540 arrayIndex = 0,541 value = "Hello"542 )543 }544 )545 }546 @Test547 fun `test string array store one-liner`(@TempDir tempDir: File) {548 val traces = generateTraces(tempDir, "agent-test_storeStringArrayOneLiner.jar")549 traces.shouldExistInOrder(550 {551 it.storeArray(552 containingClass = "com.agenttest.storeStringArrayOneLiner.Main",553 varType = "java.lang.String",554 arrayIndex = 0,555 value = "Hello"556 )557 },558 {559 it.storeVar(560 "com.agenttest.storeStringArrayOneLiner.Main",561 "[Ljava.lang.String;",562 "o",563 null564 )565 }566 )567 }568 @Test569 fun `test 2D int array store`(@TempDir tempDir: File) {570 val traces = generateTraces(tempDir, "agent-test_storeMultiIntArray.jar")571 traces.shouldExistInOrder(572 {573 it.storeVar("com.agenttest.storeMultiIntArray.Main", "[[I", "i", null)574 },575 {576 it.storeArray(577 "com.agenttest.storeMultiIntArray.Main",578 "int",579 0,580 "6"581 )582 }583 )584 }585 @Test586 fun `test 3D int array store`(@TempDir tempDir: File) {587 val traces = generateTraces(tempDir, "agent-test_storeMultiIntArray3.jar")588 traces.shouldExistInOrder(589 {590 it.storeVar("com.agenttest.storeMultiIntArray3.Main", "[[[I", "i", null)591 },592 {593 it.storeArray(594 "com.agenttest.storeMultiIntArray3.Main",595 "int",596 0,597 "6"598 )599 }600 )601 }602 @Test603 fun `test boolean array store`(@TempDir tempDir: File) {604 val traces = generateTraces(tempDir, "agent-test_storeBooleanArray.jar")605 traces.shouldExistInOrder(606 {607 it.storeVar("com.agenttest.storeBooleanArray.Main", "[Z", "b", null)608 },609 {610 it.storeArray(611 containingClass = "com.agenttest.storeBooleanArray.Main",612 varType = "boolean",613 arrayIndex = 0,614 value = "true"615 )616 }617 )618 }619 @Test620 fun `test byte array store`(@TempDir tempDir: File) {621 val traces = generateTraces(tempDir, "agent-test_storeByteArray.jar")622 traces.shouldExistInOrder(623 {624 it.storeVar("com.agenttest.storeByteArray.Main", "[B", "b", null)625 },626 {627 it.storeArray(628 containingClass = "com.agenttest.storeByteArray.Main",629 varType = "byte",630 arrayIndex = 0,631 value = "250"632 )633 }634 )635 }636 @Test637 fun `test char array store`(@TempDir tempDir: File) {638 val traces = generateTraces(tempDir, "agent-test_storeCharArray.jar")639 traces.shouldExistInOrder(640 {641 it.storeVar("com.agenttest.storeCharArray.Main", "[C", "c", null)642 },643 {644 it.storeArray(645 containingClass = "com.agenttest.storeCharArray.Main",646 varType = "char",647 arrayIndex = 0,648 value = "Q"649 )650 }651 )652 }653 @Test654 fun `test float array store`(@TempDir tempDir: File) {655 val traces = generateTraces(tempDir, "agent-test_storeFloatArray.jar")656 traces.shouldExistInOrder(657 {658 it.storeVar("com.agenttest.storeFloatArray.Main", "[F", "f", null)659 },660 {661 it.storeArray(662 containingClass = "com.agenttest.storeFloatArray.Main",663 varType = "float",664 arrayIndex = 0,665 value = "2.3"666 )667 }668 )669 }670 @Test671 fun `test long array store`(@TempDir tempDir: File) {672 val traces = generateTraces(tempDir, "agent-test_storeLongArray.jar")673 traces.shouldExistInOrder(674 {675 it.storeVar("com.agenttest.storeLongArray.Main", "[J", "l", null)676 },677 {678 it.storeArray(679 containingClass = "com.agenttest.storeLongArray.Main",680 varType = "long",681 arrayIndex = 0,682 value = "123456789123456789"683 )684 }685 )686 }687 @Test688 fun `test short array store`(@TempDir tempDir: File) {689 val traces = generateTraces(tempDir, "agent-test_storeShortArray.jar")690 traces.shouldExistInOrder(691 {692 it.storeVar("com.agenttest.storeShortArray.Main", "[S", "s", null)693 },694 {695 it.storeArray(696 containingClass = "com.agenttest.storeShortArray.Main",697 varType = "short",698 arrayIndex = 0,699 value = "12345"700 )701 }702 )703 }704 @Test705 fun `test multithreaded int array store`(@TempDir tempDir: File) {706 val traces = generateTraces(tempDir, "agent-test_storeIntMultithreaded.jar")707 // One thread writes even numbers and the other writes odd numbers. Both use a lock so708 // all numbers should be traced.709 repeat(20) { number ->710 traces.shouldExist {711 it.storeVar(712 "com.agenttest.storeIntMultithreaded.Main",713 "int",714 "com.agenttest.storeIntMultithreaded.Main.i",715 "$number"716 )717 }718 }719 // All traces should be in order720 traces.shouldBeStrictlyIncreasingWith(Comparator { t1, t2 -> (t1.index - t2.index).toInt() })721 }722 }723 @Nested724 inner class FormalMethodParameterStoreTraceTests {725 @Test726 fun `mutate both method params`(@TempDir tempDir: File) {727 val traces = generateTraces(tempDir, "agent-test_storeTwoMethodParams.jar")728 traces.shouldExist {729 it.storeVar(730 "com.agenttest.storeTwoMethodParams.Main",731 "java.lang.String",732 "s",733 "Second"734 )735 it.storeVar("com.agenttest.storeTwoMethodParams.Main", "int", "i", "2")736 }737 }738 }739 @Nested740 inner class PutFieldTraceTests {741 @Test742 fun `test put boolean`(@TempDir tempDir: File) {743 val traces = generateTraces(tempDir, "agent-test_putBooleanField.jar")744 traces.shouldExist {745 it.storeVar(746 "com.agenttest.putBooleanField.Main",747 "boolean",748 "com.agenttest.putBooleanField.Main.b",749 "true"750 )751 }752 }753 @Test754 fun `test put byte`(@TempDir tempDir: File) {755 val traces = generateTraces(tempDir, "agent-test_putByteField.jar")756 traces.shouldExist {757 it.storeVar(758 "com.agenttest.putByteField.Main",759 "byte",760 "com.agenttest.putByteField.Main.b",761 "250"762 )763 }764 }765 @Test766 fun `test put char`(@TempDir tempDir: File) {767 val traces = generateTraces(tempDir, "agent-test_putCharField.jar")768 traces.shouldExist {769 it.storeVar(770 "com.agenttest.putCharField.Main",771 "char",772 "com.agenttest.putCharField.Main.c",773 "Q"774 )775 }776 }777 @Test778 fun `test put double`(@TempDir tempDir: File) {779 val traces = generateTraces(tempDir, "agent-test_putDoubleField.jar")780 traces.shouldExist {781 it.storeVar(782 "com.agenttest.putDoubleField.Main",783 "double",784 "com.agenttest.putDoubleField.Main.d",785 "4.2"786 )787 }788 }789 @Test790 fun `test put float`(@TempDir tempDir: File) {791 val traces = generateTraces(tempDir, "agent-test_putFloatField.jar")792 traces.shouldExist {793 it.storeVar(794 "com.agenttest.putFloatField.Main",795 "float",796 "com.agenttest.putFloatField.Main.f",797 "2.3"798 )799 }800 }801 @Test802 fun `test put int`(@TempDir tempDir: File) {803 val traces = generateTraces(tempDir, "agent-test_putIntField.jar")804 traces.shouldExist {805 it.storeVar(806 "com.agenttest.putIntField.Main",807 "int",808 "com.agenttest.putIntField.Main.i",809 "7"810 )811 }812 }813 @Test814 fun `test put long`(@TempDir tempDir: File) {815 val traces = generateTraces(tempDir, "agent-test_putLongField.jar")816 traces.shouldExist {817 it.storeVar(818 "com.agenttest.putLongField.Main",819 "long",820 "com.agenttest.putLongField.Main.l",821 "123456789123456789"822 )823 }824 }825 @Test826 fun `test put object`(@TempDir tempDir: File) {827 val traces = generateTraces(tempDir, "agent-test_putObjectField.jar")828 traces.shouldExist {829 it.storeVar(830 "com.agenttest.putObjectField.Main",831 "java.lang.Object",832 "com.agenttest.putObjectField.Main.o",833 null834 )835 }836 }837 @Test838 fun `test put short`(@TempDir tempDir: File) {839 val traces = generateTraces(tempDir, "agent-test_putShortField.jar")840 traces.shouldExist {841 it.storeVar(842 "com.agenttest.putShortField.Main",843 "short",844 "com.agenttest.putShortField.Main.s",845 "12345"846 )847 }848 }849 @Test850 fun `test put string`(@TempDir tempDir: File) {851 val traces = generateTraces(tempDir, "agent-test_putStringField.jar")852 traces.shouldExist {853 it.storeVar(854 "com.agenttest.putStringField.Main",855 "java.lang.String",856 "com.agenttest.putStringField.Main.s",857 "Hello"858 )859 }860 }861 }862 @Nested863 inner class PutStaticFieldTraceTests {864 @Test865 fun `test put boolean`(@TempDir tempDir: File) {866 val traces = generateTraces(tempDir, "agent-test_putBooleanStaticField.jar")867 traces.shouldExist {868 it.storeVar(869 "com.agenttest.putBooleanStaticField.Main",870 "boolean",871 "com.agenttest.putBooleanStaticField.Main.b",872 "true"873 )874 }875 }876 @Test877 fun `test put byte`(@TempDir tempDir: File) {878 val traces = generateTraces(tempDir, "agent-test_putByteStaticField.jar")879 traces.shouldExist {880 it.storeVar(881 "com.agenttest.putByteStaticField.Main",882 "byte",883 "com.agenttest.putByteStaticField.Main.b",884 "250"885 )886 }887 }888 @Test889 fun `test put char`(@TempDir tempDir: File) {890 val traces = generateTraces(tempDir, "agent-test_putCharStaticField.jar")891 traces.shouldExist {892 it.storeVar(893 "com.agenttest.putCharStaticField.Main",894 "char",895 "com.agenttest.putCharStaticField.Main.c",896 "Q"897 )898 }899 }900 @Test901 fun `test put double`(@TempDir tempDir: File) {902 val traces = generateTraces(tempDir, "agent-test_putDoubleStaticField.jar")903 traces.shouldExist {904 it.storeVar(905 "com.agenttest.putDoubleStaticField.Main",906 "double",907 "com.agenttest.putDoubleStaticField.Main.d",908 "4.2"909 )910 }911 }912 @Test913 fun `test put float`(@TempDir tempDir: File) {914 val traces = generateTraces(tempDir, "agent-test_putFloatStaticField.jar")915 traces.shouldExist {916 it.storeVar(917 "com.agenttest.putFloatStaticField.Main",918 "float",919 "com.agenttest.putFloatStaticField.Main.f",920 "2.3"921 )922 }923 }924 @Test925 fun `test put int`(@TempDir tempDir: File) {926 val traces = generateTraces(tempDir, "agent-test_putIntStaticField.jar")927 traces.shouldExist {928 it.storeVar(929 "com.agenttest.putIntStaticField.Main",930 "int",931 "com.agenttest.putIntStaticField.Main.i",932 "7"933 )934 }935 }936 @Test937 fun `test put long`(@TempDir tempDir: File) {938 val traces = generateTraces(tempDir, "agent-test_putLongStaticField.jar")939 traces.shouldExist {940 it.storeVar(941 "com.agenttest.putLongStaticField.Main",942 "long",943 "com.agenttest.putLongStaticField.Main.l",944 "123456789123456789"945 )946 }947 }948 @Test949 fun `test put object`(@TempDir tempDir: File) {950 val traces = generateTraces(tempDir, "agent-test_putObjectStaticField.jar")951 traces.shouldExist {952 it.storeVar(953 "com.agenttest.putObjectStaticField.Main",954 "java.lang.Object",955 "com.agenttest.putObjectStaticField.Main.o",956 null957 )958 }959 }960 @Test961 fun `test put short`(@TempDir tempDir: File) {962 val traces = generateTraces(tempDir, "agent-test_putShortStaticField.jar")963 traces.shouldExist {964 it.storeVar(965 "com.agenttest.putShortStaticField.Main",966 "short",967 "com.agenttest.putShortStaticField.Main.s",968 "12345"969 )970 }971 }972 @Test973 fun `test put string`(@TempDir tempDir: File) {974 val traces = generateTraces(tempDir, "agent-test_putStringStaticField.jar")975 traces.shouldExist {976 it.storeVar(977 "com.agenttest.putStringStaticField.Main",978 "java.lang.String",979 "com.agenttest.putStringStaticField.Main.s",980 "Hello"981 )982 }983 }984 }985 @Test986 fun `read past end of trace`(@TempDir tempDir: File) {987 CompileUtil.checkForAgentTestErrors(988 CompileUtil.runAgentTest("agent-test_noargs.jar", tempDir.toPath())989 )990 val traceFiles = tempDir.listFiles()!!.toList().filter { it.extension == "trace" }991 traceFiles.shouldHaveSize(1)992 TraceIterator(BufferedInputStream(FileInputStream(traceFiles[0]))).use {993 // Go to the end994 while (it.hasNext()) {995 it.next()996 }997 // Past the end998 shouldThrow<NoSuchElementException> { it.next() }999 }1000 }1001 companion object {1002 private val logger = KotlinLogging.logger { }1003 /**1004 * Generate traces by running the Jar under the agent. Asserts that there is only one trace1005 * file.1006 *1007 * @param tempDir The dir to save the trace file into.1008 * @param jarFilename The filename of the Jar to load from1009 * `rootProject/build/agent-test-jars`.1010 * @return The traces.1011 */1012 private fun generateTraces(tempDir: File, jarFilename: String): List<Trace> {1013 CompileUtil.checkForAgentTestErrors(1014 CompileUtil.runAgentTest(jarFilename, tempDir.toPath())1015 )1016 logger.debug {1017 """1018 |Files in temp dir:1019 |${tempDir.walkTopDown().joinToString("\n")}1020 """.trimMargin()1021 }1022 val traceFiles = tempDir.listFiles()!!.filter { it.extension == "trace" }1023 traceFiles.shouldHaveSize(1)1024 return TraceIterator(BufferedInputStream(FileInputStream(traceFiles[0]))).use {1025 it.asSequence().toList()1026 }1027 }1028 /**1029 * Assumes there is a virtual method call and asserts about its receiver type and arguments.1030 * Excludes instance and class initialization methods.1031 *1032 * @param receiverType The expected receiver type.1033 * @param methodName The expected method name.1034 * @param callerClass The class that the method is expected to be called from.1035 * @param args The expected (type, value) pairs for each argument in order.1036 */1037 private fun Trace.virtualMethodCall(1038 receiverType: String,1039 methodName: String,1040 callerClass: String,1041 args: List<Pair<String, String?>> = emptyList()1042 ) = this is MethodTrace &&1043 !isStatic &&1044 methodName != "<init>" &&1045 methodName != "<clinit>" &&1046 hasArguments(listOf(receiverType to null) + args) &&1047 this.methodName == methodName &&1048 this.callerClass == callerClass1049 /**1050 * Assumes there is a static method call and asserts about its arguments. Excludes instance1051 * and class initialization methods.1052 *1053 * @param methodName The expected method name.1054 * @param callerClass The class that the method is expected to be called from.1055 * @param args The expected (type, value) pairs for each argument in order.1056 */1057 private fun Trace.staticMethodCall(1058 methodName: String,1059 callerClass: String,1060 args: List<Pair<String, String?>> = emptyList()1061 ) = this is MethodTrace &&1062 isStatic &&1063 methodName != "<init>" &&1064 methodName != "<clinit>" &&1065 hasArguments(args) &&1066 this.methodName == methodName &&1067 this.callerClass == callerClass1068 /**1069 * Assumes there is an instance initializer method call and asserts about its arguments.1070 *1071 * @param receiverType The expected receiver type.1072 * @param callerClass The class that the method is expected to be called from.1073 * @param args The expected (type, value) pairs for each argument in order.1074 */1075 private fun Trace.constructorCall(1076 receiverType: String,1077 callerClass: String,1078 args: List<Pair<String, String?>> = emptyList()1079 ) = this is MethodTrace &&1080 !isStatic &&1081 methodName == "<init>" &&1082 hasArguments(listOf(receiverType to null) + args) &&1083 this.callerClass == callerClass1084 /**1085 * Checks there is a store with a value of [value] into a variable of type [varType].1086 *1087 * @param containingClass The class the store happens in.1088 * @param varType The type of the variable the value was stored in.1089 * @param name The name of the variable.1090 * @param value The value that was stored. Set to null if you don't care about the value.1091 */1092 private fun Trace.storeVar(1093 containingClass: String,1094 varType: String,1095 name: String,1096 value: String?1097 ) = this is StoreTrace &&1098 callerClass == containingClass &&1099 typeValuePair.type == varType &&1100 variableName == name &&1101 value?.let { typeValuePair.value == it } ?: true1102 /**1103 * Checks there is a store with a value of [value] into an array of type [varType] at index1104 * [arrayIndex].1105 *1106 * @param containingClass The class the store happens in.1107 * @param varType The type of the variable the value was stored in.1108 * @param arrayIndex The index in the array the value was stored in.1109 * @param value The value that was stored. Set to null if you don't care about the value.1110 */1111 private fun Trace.storeArray(1112 containingClass: String,1113 varType: String,1114 arrayIndex: Int,1115 value: String?1116 ) = this is ArrayStoreTrace &&1117 callerClass == containingClass &&1118 this.arrayIndex == arrayIndex &&1119 typeValuePair.type == varType &&1120 value?.let { typeValuePair.value == it } ?: true1121 private fun MethodTrace.hasArguments(args: List<Pair<String, String?>>) =1122 args.foldIndexed(true) { index, acc, (type, value) ->1123 if (value == null) {1124 // Null means we don't care about the value1125 acc && hasArgumentType(index, type)1126 } else {1127 acc && hasArgument(index, type, value)1128 }1129 }1130 private fun MethodTrace.hasArgumentType(index: Int, type: String) =1131 arguments[index].type == type1132 private fun MethodTrace.hasArgument(index: Int, type: String, value: String) =1133 arguments[index].type == type && arguments[index].value == value1134 }1135}...

Full Screen

Full Screen

ColorContainerTest.kt

Source:ColorContainerTest.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2018-2021 AnimatedLEDStrip3 *4 * Permission is hereby granted, free of charge, to any person obtaining a copy5 * of this software and associated documentation files (the "Software"), to deal6 * in the Software without restriction, including without limitation the rights7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8 * copies of the Software, and to permit persons to whom the Software is9 * furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20 * THE SOFTWARE.21 *22 */23package animatedledstrip.test.colors24import animatedledstrip.colors.*25import io.kotest.assertions.throwables.shouldThrow26import io.kotest.core.spec.style.StringSpec27import io.kotest.matchers.booleans.shouldBeFalse28import io.kotest.matchers.booleans.shouldBeTrue29import io.kotest.matchers.collections.shouldBeEmpty30import io.kotest.matchers.collections.shouldContainExactly31import io.kotest.matchers.collections.shouldExistInOrder32import io.kotest.matchers.collections.shouldStartWith33import io.kotest.matchers.shouldBe34import io.kotest.matchers.shouldNotBe35import io.kotest.matchers.types.shouldBeSameInstanceAs36import io.kotest.matchers.types.shouldNotBeSameInstanceAs37import io.kotest.property.Arb38import io.kotest.property.arbitrary.filter39import io.kotest.property.arbitrary.int40import io.kotest.property.arbitrary.list41import io.kotest.property.arbitrary.next42import io.kotest.property.checkAll43class ColorContainerTest : StringSpec(44 {45 "primary constructor" {46 checkAll<Int> { c ->47 ColorContainer(c).color shouldBe c48 }49 }50 "ColorContainer constructor" {51 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->52 val cc = ColorContainer(c.toMutableList())53 ColorContainer(cc).colors shouldBe cc.colors54 }55 }56 "RGB constructor" {57 checkAll(Arb.int(0..0xFF),58 Arb.int(0..0xFF),59 Arb.int(0..0xFF)) { r, g, b ->60 ColorContainer(Triple(r, g, b)).color shouldBe ((r shl 16) or (g shl 8) or b)61 }62 }63 "list constructor" {64 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->65 ColorContainer(c.toMutableList()).colors shouldBe c.toMutableList()66 }67 }68 "get" {69 checkAll(Arb.int(0..0xFFFFFF),70 Arb.int(0..0xFFFFFF),71 Arb.int(0..0xFFFFFF),72 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->73 val testCC = ColorContainer(c1, c2, c3, c4)74 testCC[0] shouldBe c175 testCC[0, 2] shouldBe listOf(c1, c3)76 testCC[0..2] shouldBe listOf(c1, c2, c3)77 testCC[IntRange(2, 0)] shouldBe listOf() // Test with empty IntRange78 testCC.color shouldBe c179 testCC[5] shouldBe 080 testCC[3, 5] shouldBe listOf(c4, 0)81 testCC[3..5] shouldBe listOf(c4, 0, 0)82 }83 val testCC = ColorContainer()84 testCC.color shouldBe 085 }86 "set" {87 checkAll(Arb.int(0..0xFFFFFF),88 Arb.int(0..0xFFFFFF),89 Arb.int(0..0xFFFFFF),90 Arb.int(0..0xFFFFFF),91 Arb.int(0..0xFFFFFF),92 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4, c5, c6 ->93 val testCC = ColorContainer(c1, c2, c3)94 testCC.colors.shouldContainExactly(c1, c2, c3)95 testCC[2] = c496 testCC.colors.shouldContainExactly(c1, c2, c4)97 testCC[3, 5] = c598 testCC.colors.shouldContainExactly(c1, c2, c4, c5, c5)99 testCC[3..7] = c6100 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6)101 testCC[IntRange(5, 3)] = c1102 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6)103 testCC += c4104 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6, c4)105 }106 }107 "prepare" {108 val p = ColorContainer(0xFF7B51, 0xF0AF29, 0x3C538B).prepare(50)109 p.colors.shouldStartWith(0xFF7B51)110 p.colors.shouldExistInOrder({ it == 0xFF7B51 }, { it == 0xF0AF29 }, { it == 0x3C538B })111 p.originalColors.shouldContainExactly(0xFF7B51, 0xF0AF29, 0x3C538B)112 ColorContainer().prepare(5).colors.shouldContainExactly(0, 0, 0, 0, 0)113 shouldThrow<IllegalArgumentException> {114 ColorContainer(0xFF).prepare(0)115 }116 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->117 ColorContainer(c.toMutableList()).prepare(500)118 }119 }120 "string" {121 ColorContainer(0xFF3B82).toString() shouldBe "[ff3b82]"122 ColorContainer(0xFF7B50, 0xFFFFFF).toString() shouldBe "[ff7b50, ffffff]"123 ColorContainer().toString() shouldBe "[]"124 }125 "toInt" {126 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->127 ColorContainer(c.toMutableList()).toInt() shouldBe c.first()128 }129 }130 "toRGB" {131 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->132 ColorContainer(c.toMutableList()).toRGB() shouldBe Triple(c.first().r, c.first().g, c.first().b)133 ColorContainer(c.toMutableList()).toTriple() shouldBe Triple(c.first().r, c.first().g, c.first().b)134 }135 }136 "toColorContainer" {137 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->138 val testCC = ColorContainer(c.toMutableList())139 testCC.toColorContainer() shouldBeSameInstanceAs testCC140 }141 }142 "equality" {143 checkAll(50, Arb.int(0..0xFFFFFF)) { c ->144 val testCC = ColorContainer(c)145 testCC shouldBe ColorContainer(c)146 testCC.hashCode() shouldBe ColorContainer(c).hashCode()147 testCC shouldBe c148 checkAll(10, Arb.int(0..0xFFFFFF).filter { it != c }) { c2 ->149 testCC shouldNotBe ColorContainer(c2)150 testCC.hashCode() shouldNotBe ColorContainer(c2).hashCode()151 testCC shouldNotBe c2152 }153 checkAll(10, Arb.list(Arb.int(0..0xFFFFFF), 2..100)) { c3 ->154 testCC shouldNotBe ColorContainer(c3.toMutableList())155 }156 }157 checkAll(Arb.list(Arb.int(0..0xFFFFFF)).filter { it.isNotEmpty() }) { c ->158 val testCC = ColorContainer(c.toMutableList())159 testCC shouldBe ColorContainer(c.toMutableList())160 testCC.hashCode() shouldBe ColorContainer(c.toMutableList()).hashCode()161 testCC shouldNotBe c162 testCC.hashCode() shouldBe c.hashCode()163 checkAll(50, Arb.int(1..500).filter { it != c.size }) { len ->164 testCC shouldBe ColorContainer(c.toMutableList()).prepare(len)165 testCC.hashCode() shouldNotBe ColorContainer(c.toMutableList()).prepare(len).hashCode()166 }167 checkAll(10, Arb.list(Arb.int(0..0xFFFFFF)).filter { it != c }) { c2 ->168 testCC shouldNotBe ColorContainer(c2.toMutableList())169 testCC.hashCode() shouldNotBe ColorContainer(c2.toMutableList()).hashCode()170 testCC shouldNotBe c2171 testCC.hashCode() shouldNotBe c2.hashCode()172 }173 }174 }175 "contains" {176 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->177 val testCC = ColorContainer(c.toMutableList())178 for (i in c) {179 (i in testCC).shouldBeTrue()180 }181 for (i in Arb.list(Arb.int(0..0xFFFFFF).filter { it !in c }, 10..10).next())182 (i in testCC).shouldBeFalse()183 }184 }185 "size" {186 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->187 ColorContainer(c.toMutableList()).size shouldBe c.size188 }189 }190 "grayscale" {191 checkAll(Arb.int(0..0xFFFFFF),192 Arb.int(0..0xFFFFFF)) { c1, c2 ->193 val testCC = ColorContainer(c1, c2)194 testCC.grayscale() shouldBeSameInstanceAs testCC195 testCC.colors.shouldContainExactly(c1.grayscale(),196 c2.grayscale())197 }198 checkAll(Arb.int(0..0xFFFFFF),199 Arb.int(0..0xFFFFFF),200 Arb.int(0..0xFFFFFF),201 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->202 val testCC = ColorContainer(c1, c2, c3, c4)203 testCC.grayscale(0, 3) shouldBeSameInstanceAs testCC204 testCC.colors.shouldContainExactly(c1.grayscale(),205 c2,206 c3,207 c4.grayscale())208 testCC.grayscale(1, 2) shouldBeSameInstanceAs testCC209 testCC.colors.shouldContainExactly(c1.grayscale(),210 c2.grayscale(),211 c3.grayscale(),212 c4.grayscale())213 val testCC2 = ColorContainer(c1, c2, c3, c4)214 testCC2.grayscale(3, 1, 2) shouldBeSameInstanceAs testCC2215 testCC2.colors.shouldContainExactly(c1,216 c2.grayscale(),217 c3.grayscale(),218 c4.grayscale())219 val testCC3 = ColorContainer(c1, c2, c3, c4)220 testCC3.grayscale(8) shouldBeSameInstanceAs testCC3221 testCC3.colors.shouldContainExactly(c1, c2, c3, c4)222 }223 checkAll(Arb.int(0..0xFFFFFF),224 Arb.int(0..0xFFFFFF),225 Arb.int(0..0xFFFFFF),226 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->227 val testCC = ColorContainer(c1, c2, c3, c4)228 testCC.grayscale(0..2) shouldBeSameInstanceAs testCC229 testCC.colors.shouldContainExactly(c1.grayscale(),230 c2.grayscale(),231 c3.grayscale(),232 c4)233 val testCC2 = ColorContainer(c1, c2, c3, c4)234 testCC2.grayscale(0..1, 3..5) shouldBeSameInstanceAs testCC2235 testCC2.colors.shouldContainExactly(c1.grayscale(),236 c2.grayscale(),237 c3,238 c4.grayscale())239 val testCC3 = ColorContainer(c1, c2, c3, c4)240 testCC3.grayscale(IntRange(2, 0)) shouldBeSameInstanceAs testCC3241 testCC3.colors.shouldContainExactly(c1, c2, c3, c4)242 }243 }244 "grayscaled" {245 checkAll(Arb.int(0..0xFFFFFF),246 Arb.int(0..0xFFFFFF)) { c1, c2 ->247 val testCC = ColorContainer(c1, c2)248 val gTestCC1 = testCC.grayscaled()249 gTestCC1 shouldNotBeSameInstanceAs testCC250 testCC.colors.shouldContainExactly(c1, c2)251 gTestCC1.colors.shouldContainExactly(c1.grayscale(),252 c2.grayscale())253 }254 checkAll(Arb.int(0..0xFFFFFF),255 Arb.int(0..0xFFFFFF),256 Arb.int(0..0xFFFFFF),257 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->258 val testCC = ColorContainer(c1, c2, c3, c4)259 val gTestCC1 = testCC.grayscaled(0, 3)260 gTestCC1 shouldNotBeSameInstanceAs testCC261 testCC.colors.shouldContainExactly(c1, c2, c3, c4)262 gTestCC1.colors.shouldContainExactly(c1.grayscale(),263 c4.grayscale())264 val gTestCC2 = testCC.grayscaled(3, 1, 2)265 gTestCC2 shouldNotBeSameInstanceAs testCC266 testCC.colors.shouldContainExactly(c1, c2, c3, c4)267 gTestCC2.colors.shouldContainExactly(c4.grayscale(),268 c2.grayscale(),269 c3.grayscale())270 val gTestCC3 = testCC.grayscaled(8)271 gTestCC3 shouldNotBeSameInstanceAs testCC272 testCC.colors.shouldContainExactly(c1, c2, c3, c4)273 gTestCC3.colors.shouldBeEmpty()274 }275 checkAll(Arb.int(0..0xFFFFFF),276 Arb.int(0..0xFFFFFF),277 Arb.int(0..0xFFFFFF),278 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->279 val testCC = ColorContainer(c1, c2, c3, c4)280 val gTestCC1 = testCC.grayscaled(0..2)281 gTestCC1 shouldNotBeSameInstanceAs testCC282 testCC.colors.shouldContainExactly(c1, c2, c3, c4)283 gTestCC1.colors.shouldContainExactly(c1.grayscale(),284 c2.grayscale(),285 c3.grayscale())286 val gTestCC2 = testCC.grayscaled(0..1, 3..5)287 gTestCC2 shouldNotBeSameInstanceAs testCC288 testCC.colors.shouldContainExactly(c1, c2, c3, c4)289 gTestCC2.colors.shouldContainExactly(c1.grayscale(),290 c2.grayscale(),291 c4.grayscale())292 val gTestCC3 = testCC.grayscaled(IntRange(2, 0))293 gTestCC3 shouldNotBeSameInstanceAs testCC294 testCC.colors.shouldContainExactly(c1, c2, c3, c4)295 gTestCC3.colors.shouldBeEmpty()296 }297 }298 "invert" {299 checkAll(Arb.int(0..0xFFFFFF),300 Arb.int(0..0xFFFFFF)) { c1, c2 ->301 val testCC = ColorContainer(c1, c2)302 testCC.invert() shouldBeSameInstanceAs testCC303 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,304 c2.inv() and 0xFFFFFF)305 testCC.invert() shouldBeSameInstanceAs testCC306 testCC.colors.shouldContainExactly(c1, c2)307 }308 checkAll(Arb.int(0..0xFFFFFF),309 Arb.int(0..0xFFFFFF),310 Arb.int(0..0xFFFFFF),311 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->312 val testCC = ColorContainer(c1, c2, c3, c4)313 testCC.invert(0, 3) shouldBeSameInstanceAs testCC314 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,315 c2,316 c3,317 c4.inv() and 0xFFFFFF)318 testCC.invert(1, 2) shouldBeSameInstanceAs testCC319 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,320 c2.inv() and 0xFFFFFF,321 c3.inv() and 0xFFFFFF,322 c4.inv() and 0xFFFFFF)323 testCC.invert(3, 1, 2) shouldBeSameInstanceAs testCC324 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,325 c2,326 c3,327 c4)328 testCC.invert(8) shouldBeSameInstanceAs testCC329 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,330 c2,331 c3,332 c4)333 }334 checkAll(Arb.int(0..0xFFFFFF),335 Arb.int(0..0xFFFFFF),336 Arb.int(0..0xFFFFFF),337 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->338 val testCC = ColorContainer(c1, c2, c3, c4)339 testCC.invert(0..2) shouldBeSameInstanceAs testCC340 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,341 c2.inv() and 0xFFFFFF,342 c3.inv() and 0xFFFFFF,343 c4)344 testCC.invert(1..2) shouldBeSameInstanceAs testCC345 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,346 c2,347 c3,348 c4)349 testCC.invert(0..1, 3..5) shouldBeSameInstanceAs testCC350 testCC.colors.shouldContainExactly(c1,351 c2.inv() and 0xFFFFFF,352 c3,353 c4.inv() and 0xFFFFFF)354 testCC.invert(IntRange(2, 0)) shouldBeSameInstanceAs testCC355 testCC.colors.shouldContainExactly(c1,356 c2.inv() and 0xFFFFFF,357 c3,358 c4.inv() and 0xFFFFFF)359 }360 }361 "inverse" {362 checkAll(Arb.int(0..0xFFFFFF),363 Arb.int(0..0xFFFFFF)) { c1, c2 ->364 val testCC = ColorContainer(c1, c2)365 val iTestCC1 = testCC.inverse()366 iTestCC1 shouldNotBeSameInstanceAs testCC367 testCC.colors.shouldContainExactly(c1, c2)368 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,369 c2.inv() and 0xFFFFFF)370 val iTestCC2 = -testCC371 iTestCC2 shouldNotBeSameInstanceAs testCC372 testCC.colors.shouldContainExactly(c1, c2)373 iTestCC2.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,374 c2.inv() and 0xFFFFFF)375 }376 checkAll(Arb.int(0..0xFFFFFF),377 Arb.int(0..0xFFFFFF),378 Arb.int(0..0xFFFFFF),379 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->380 val testCC = ColorContainer(c1, c2, c3, c4)381 val iTestCC1 = testCC.inverse(0, 3)382 iTestCC1 shouldNotBeSameInstanceAs testCC383 testCC.colors.shouldContainExactly(c1, c2, c3, c4)384 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,385 c4.inv() and 0xFFFFFF)386 val iTestCC2 = testCC.inverse(3, 1, 2)387 iTestCC2 shouldNotBeSameInstanceAs testCC388 testCC.colors.shouldContainExactly(c1, c2, c3, c4)389 iTestCC2.colors.shouldContainExactly(c4.inv() and 0xFFFFFF,390 c2.inv() and 0xFFFFFF,391 c3.inv() and 0xFFFFFF)392 val iTestCC3 = testCC.inverse(8)393 iTestCC3 shouldNotBeSameInstanceAs testCC394 testCC.colors.shouldContainExactly(c1, c2, c3, c4)395 iTestCC3.colors.shouldBeEmpty()396 }397 checkAll(Arb.int(0..0xFFFFFF),398 Arb.int(0..0xFFFFFF),399 Arb.int(0..0xFFFFFF),400 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->401 val testCC = ColorContainer(c1, c2, c3, c4)402 val iTestCC1 = testCC.inverse(0..2)403 iTestCC1 shouldNotBeSameInstanceAs testCC404 testCC.colors.shouldContainExactly(c1, c2, c3, c4)405 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,406 c2.inv() and 0xFFFFFF,407 c3.inv() and 0xFFFFFF)408 val iTestCC2 = testCC.inverse(0..1, 3..5)409 iTestCC2 shouldNotBeSameInstanceAs testCC410 testCC.colors.shouldContainExactly(c1, c2, c3, c4)411 iTestCC2.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,412 c2.inv() and 0xFFFFFF,413 c4.inv() and 0xFFFFFF)414 val iTestCC3 = testCC.inverse(IntRange(2, 0))415 iTestCC3 shouldNotBeSameInstanceAs testCC416 testCC.colors.shouldContainExactly(c1, c2, c3, c4)417 iTestCC3.colors.shouldBeEmpty()418 }419 }420 "is empty" {421 val testCC1 = ColorContainer()422 testCC1.isEmpty().shouldBeTrue()423 testCC1.isNotEmpty().shouldBeFalse()424 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->425 val testCC2 = ColorContainer(c.toMutableList())426 testCC2.isEmpty().shouldBeFalse()427 testCC2.isNotEmpty().shouldBeTrue()428 }429 }430 })...

Full Screen

Full Screen

KotlinValueParameterNameShrinkerTest.kt

Source:KotlinValueParameterNameShrinkerTest.kt Github

copy

Full Screen

1/*2 * ProGuard -- shrinking, optimization, obfuscation, and preverification3 * of Java bytecode.4 *5 * Copyright (c) 2002-2021 Guardsquare NV6 *7 * This program is free software; you can redistribute it and/or modify it8 * under the terms of the GNU General Public License as published by the Free9 * Software Foundation; either version 2 of the License, or (at your option)10 * any later version.11 *12 * This program is distributed in the hope that it will be useful, but WITHOUT13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for15 * more details.16 *17 * You should have received a copy of the GNU General Public License along18 * with this program; if not, write to the Free Software Foundation, Inc.,19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20 */21package proguard.obfuscate.kotlin22import io.kotest.core.spec.IsolationMode23import io.kotest.core.spec.style.FreeSpec24import io.kotest.matchers.collections.shouldExistInOrder25import io.kotest.matchers.shouldBe26import io.mockk.every27import io.mockk.mockkStatic28import io.mockk.spyk29import io.mockk.verify30import proguard.classfile.kotlin.KotlinClassKindMetadata31import proguard.classfile.kotlin.KotlinConstructorMetadata32import proguard.classfile.kotlin.KotlinFunctionMetadata33import proguard.classfile.kotlin.KotlinPropertyMetadata34import proguard.classfile.kotlin.visitor.AllConstructorVisitor35import proguard.classfile.kotlin.visitor.AllFunctionVisitor36import proguard.classfile.kotlin.visitor.AllPropertyVisitor37import proguard.classfile.kotlin.visitor.AllValueParameterVisitor38import proguard.classfile.kotlin.visitor.KotlinValueParameterVisitor39import testutils.ClassPoolBuilder40import testutils.KotlinSource41import proguard.classfile.kotlin.KotlinValueParameterMetadata as ValueParameter42import proguard.obfuscate.kotlin.KotlinValueParameterUsageMarker as VpUsageMarker43class KotlinValueParameterNameShrinkerTest : FreeSpec({44 // InstancePerTest so the names are reset before every test45 isolationMode = IsolationMode.InstancePerTest46 val (programClassPool, _) = ClassPoolBuilder.fromSource(47 KotlinSource(48 "Test.kt",49 """50 @Suppress("UNUSED_PARAMETER")51 class Foo(param1: String, param2: String, param3: String) {52 var property: String = "foo"53 set(param1) { }54 fun foo(param1: String, param2: String, param3: String) {}55 }56 """.trimIndent()57 )58 )59 "Given a class with value parameters" - {60 val clazz = programClassPool.getClass("Foo")61 "When none are marked unused" - {62 "Then they should keep their names" {63 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()64 mockkStatic(VpUsageMarker::class)65 every { VpUsageMarker.isUsed(any()) } returns true66 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())67 clazz.kotlinMetadataAccept(68 AllConstructorVisitor(69 AllValueParameterVisitor(70 valueParameterVisitor71 )72 )73 )74 val valueParameters = mutableListOf<ValueParameter>()75 verify {76 valueParameterVisitor.visitConstructorValParameter(77 clazz,78 ofType(KotlinClassKindMetadata::class),79 ofType(KotlinConstructorMetadata::class),80 capture(valueParameters)81 )82 }83 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(84 { it.parameterName == "param1" },85 { it.parameterName == "param2" },86 { it.parameterName == "param3" }87 )88 }89 }90 "When all are marked unused" - {91 "Then they should be renamed" {92 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()93 mockkStatic(VpUsageMarker::class)94 every { VpUsageMarker.isUsed(any()) } returns false95 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())96 clazz.kotlinMetadataAccept(97 AllConstructorVisitor(98 AllValueParameterVisitor(99 valueParameterVisitor100 )101 )102 )103 val valueParameters = mutableListOf<ValueParameter>()104 verify {105 valueParameterVisitor.visitConstructorValParameter(106 clazz,107 ofType(KotlinClassKindMetadata::class),108 ofType(KotlinConstructorMetadata::class),109 capture(valueParameters)110 )111 }112 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(113 { it.parameterName == "p0" },114 { it.parameterName == "p1" },115 { it.parameterName == "p2" }116 )117 }118 }119 "When some are marked used" - {120 "Then only the unused ones should be renamed" {121 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()122 val valueParameters = mutableListOf<ValueParameter>()123 mockkStatic(VpUsageMarker::class)124 every {125 VpUsageMarker.isUsed(match { it is ValueParameter && it.parameterName == "param2" })126 } returns true127 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())128 clazz.kotlinMetadataAccept(129 AllConstructorVisitor(130 AllValueParameterVisitor(131 valueParameterVisitor132 )133 )134 )135 verify(exactly = 3) {136 valueParameterVisitor.visitConstructorValParameter(137 clazz,138 ofType(KotlinClassKindMetadata::class),139 ofType(KotlinConstructorMetadata::class),140 capture(valueParameters)141 )142 }143 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(144 { it.parameterName == "p0" },145 { it.parameterName == "param2" },146 { it.parameterName == "p1" }147 )148 }149 }150 }151 "Given a function with value parameters" - {152 val clazz = programClassPool.getClass("Foo")153 "When none are marked unused" - {154 "Then they should keep their names" {155 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()156 mockkStatic(VpUsageMarker::class)157 every { VpUsageMarker.isUsed(any()) } returns true158 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())159 clazz.kotlinMetadataAccept(160 AllFunctionVisitor(161 AllValueParameterVisitor(162 valueParameterVisitor163 )164 )165 )166 val valueParameters = mutableListOf<ValueParameter>()167 verify {168 valueParameterVisitor.visitFunctionValParameter(169 clazz,170 ofType(KotlinClassKindMetadata::class),171 ofType(KotlinFunctionMetadata::class),172 capture(valueParameters)173 )174 }175 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(176 { it.parameterName == "param1" },177 { it.parameterName == "param2" },178 { it.parameterName == "param3" }179 )180 }181 }182 "When all are marked unused" - {183 "Then they should be renamed" {184 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()185 mockkStatic(VpUsageMarker::class)186 every { VpUsageMarker.isUsed(any()) } returns false187 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())188 clazz.kotlinMetadataAccept(189 AllFunctionVisitor(190 AllValueParameterVisitor(191 valueParameterVisitor192 )193 )194 )195 val valueParameters = mutableListOf<ValueParameter>()196 verify {197 valueParameterVisitor.visitFunctionValParameter(198 clazz,199 ofType(KotlinClassKindMetadata::class),200 ofType(KotlinFunctionMetadata::class),201 capture(valueParameters)202 )203 }204 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(205 { it.parameterName == "p0" },206 { it.parameterName == "p1" },207 { it.parameterName == "p2" }208 )209 }210 }211 "When some are marked used" - {212 "Then only the unused ones should be renamed" {213 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()214 val valueParameters = mutableListOf<ValueParameter>()215 mockkStatic(VpUsageMarker::class)216 every {217 VpUsageMarker.isUsed(match { it is ValueParameter && it.parameterName == "param2" })218 } returns true219 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())220 clazz.kotlinMetadataAccept(221 AllFunctionVisitor(222 AllValueParameterVisitor(223 valueParameterVisitor224 )225 )226 )227 verify(exactly = 3) {228 valueParameterVisitor.visitFunctionValParameter(229 clazz,230 ofType(KotlinClassKindMetadata::class),231 ofType(KotlinFunctionMetadata::class),232 capture(valueParameters)233 )234 }235 valueParameters shouldExistInOrder listOf<(ValueParameter) -> Boolean>(236 { it.parameterName == "p0" },237 { it.parameterName == "param2" },238 { it.parameterName == "p1" }239 )240 }241 }242 }243 "Given a property with value parameters" - {244 val clazz = programClassPool.getClass("Foo")245 "When none are marked unused" - {246 "Then they should keep their names" {247 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()248 mockkStatic(VpUsageMarker::class)249 every { VpUsageMarker.isUsed(any()) } returns true250 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())251 clazz.kotlinMetadataAccept(252 AllPropertyVisitor(253 AllValueParameterVisitor(254 valueParameterVisitor255 )256 )257 )258 verify {259 valueParameterVisitor.visitPropertyValParameter(260 clazz,261 ofType(KotlinClassKindMetadata::class),262 ofType(KotlinPropertyMetadata::class),263 withArg { it.parameterName shouldBe "param1" }264 )265 }266 }267 }268 "When all are marked unused" - {269 "Then they should be renamed" {270 val valueParameterVisitor = spyk<KotlinValueParameterVisitor>()271 mockkStatic(VpUsageMarker::class)272 every { VpUsageMarker.isUsed(any()) } returns false273 clazz.kotlinMetadataAccept(KotlinValueParameterNameShrinker())274 clazz.kotlinMetadataAccept(275 AllPropertyVisitor(276 AllValueParameterVisitor(277 valueParameterVisitor278 )279 )280 )281 verify {282 valueParameterVisitor.visitPropertyValParameter(283 clazz,284 ofType(KotlinClassKindMetadata::class),285 ofType(KotlinPropertyMetadata::class),286 withArg { it.parameterName shouldBe "p0" }287 )288 }289 }290 }291 }292})...

Full Screen

Full Screen

SealedClassesTest.kt

Source:SealedClassesTest.kt Github

copy

Full Screen

1/*2 * ProGuardCORE -- library to process Java bytecode.3 *4 * Copyright (c) 2002-2021 Guardsquare NV5 *6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package proguard.classfile19import io.kotest.core.spec.style.FreeSpec20import io.kotest.matchers.collections.shouldExistInOrder21import io.kotest.matchers.shouldNotBe22import io.mockk.spyk23import io.mockk.verify24import proguard.classfile.attribute.Attribute.PERMITTED_SUBCLASSES25import proguard.classfile.attribute.PermittedSubclassesAttribute26import proguard.classfile.attribute.visitor.AllAttributeVisitor27import proguard.classfile.attribute.visitor.AttributeNameFilter28import proguard.classfile.attribute.visitor.AttributeVisitor29import proguard.classfile.constant.ClassConstant30import proguard.classfile.constant.Constant31import proguard.classfile.constant.visitor.ConstantVisitor32import testutils.ClassPoolBuilder33import testutils.JavaSource34import testutils.RequiresJavaVersion35import testutils.currentJavaVersion36@RequiresJavaVersion(15)37class SealedClassesTest : FreeSpec({38 "Given a Java record class" - {39 val (programClassPool, _) = ClassPoolBuilder.fromSource(40 JavaSource(41 "Test.java",42 """43 public sealed class Test permits A, B, C { }44 final class A extends Test {}45 final class B extends Test {}46 final class C extends Test {}47 """.trimIndent()48 ),49 javacArguments = if (currentJavaVersion == 15 || currentJavaVersion == 16)50 listOf("--enable-preview", "--release", "$currentJavaVersion") else emptyList()51 )52 val clazz = programClassPool.getClass("Test")53 "Then the record class should not be null" {54 clazz shouldNotBe null55 }56 "Then the sealed classes should be listed" {57 val permittedClassVisitor = spyk(object : ConstantVisitor {58 override fun visitAnyConstant(clazz: Clazz, constant: Constant) {}59 })60 programClassPool.classesAccept(61 "Test",62 AllAttributeVisitor(63 AttributeNameFilter(64 PERMITTED_SUBCLASSES,65 object : AttributeVisitor {66 override fun visitPermittedSubclassesAttribute(clazz: Clazz, permittedSubclassesAttribute: PermittedSubclassesAttribute) {67 permittedSubclassesAttribute.permittedSubclassConstantsAccept(clazz, permittedClassVisitor)68 }69 }70 )71 )72 )73 val permittedSubclasses = mutableListOf<ClassConstant>()74 verify(exactly = 3) {75 permittedClassVisitor.visitClassConstant(76 clazz,77 capture(permittedSubclasses)78 )79 }80 permittedSubclasses.map { it.referencedClass }.shouldExistInOrder(81 { it == programClassPool.getClass("A") },82 { it == programClassPool.getClass("B") },83 { it == programClassPool.getClass("C") }84 )85 }86 }87})...

Full Screen

Full Screen

AccountRepositoryTests.kt

Source:AccountRepositoryTests.kt Github

copy

Full Screen

1package micro.apps.service.domain.account2import io.kotest.core.spec.style.FunSpec3import io.kotest.core.test.config.TestCaseConfig4import io.kotest.matchers.collections.shouldExistInOrder5import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields6import io.kotest.matchers.shouldBe7import kotlinx.coroutines.delay8import kotlinx.serialization.ExperimentalSerializationApi9import kotlinx.serialization.json.Json10import micro.apps.core.dateOf11import micro.apps.test.E2E12import micro.apps.test.Slow13import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest14import org.springframework.data.domain.Sort15import org.springframework.data.domain.Sort.Direction.ASC16import org.springframework.data.domain.Sort.Order17@OptIn(ExperimentalSerializationApi::class)18@DataRedisTest19class AccountRepositoryTests(20 private val personRepository: PersonRepository,21 private val addressRepository: AddressRepository22) : FunSpec({23 // defaultTestConfig24 TestCaseConfig(tags = setOf(E2E, Slow))25 val aPersonId = "1073516001"26 lateinit var aPerson: PersonEntity27 beforeSpec {28 println("***DID YOU RUN `FLUSHDB` REDIS COMMAND TO CLEAN THE DATABASE?")29 javaClass.getResourceAsStream("/npidata.jsonl").use {30 it?.bufferedReader()?.forEachLine { line ->31 val person = Json.decodeFromString(PersonEntity.serializer(), line)32 val savedAddresses: MutableSet<AddressEntity> = mutableSetOf()33 person.addresses?.forEach {34 savedAddresses += addressRepository.save(it)35 }36 val personWithSavedAddresses = person.copy(addresses = savedAddresses)37 personRepository.save(personWithSavedAddresses)38 }39 delay(1000L)40 aPerson = personRepository.findById(aPersonId).get()41 }42 }43 afterSpec {44 addressRepository.deleteAll()45 personRepository.deleteAll()46 }47 test("findById returns Person") {48 val actual = personRepository.findById(aPersonId).get()49 actual shouldBe aPerson50 /*51 val actual = personRepository.findById(aPersonId).ifPresent {52 it shouldBe aPerson53 }54 */55 }56 test("count should be one") {57 val actual = personRepository.count()58 actual shouldBe 10059 }60 test("!this test will be ignored") {61 println(aPerson)62 }63 test("update aPerson's dob and email") {64 val savedAPersonUpdated =65 personRepository.save(aPerson.copy(dob = dateOf(1965, 8, 26), email = "me2@demo.com"))66 savedAPersonUpdated.id shouldBe aPerson.id67 savedAPersonUpdated.dob shouldBe dateOf(1965, 8, 26)68 savedAPersonUpdated.email shouldBe "me2@demo.com"69 savedAPersonUpdated.shouldBeEqualToIgnoringFields(aPerson, PersonEntity::dob, PersonEntity::email)70 }71 test("list all") {72 // val sort = Sort.sort(Person::class.java).by(Person::getFirstName).ascending()73 // val sorted = personRepository.findAll(PageRequest.of(0, 5))74 val sorted = personRepository.findAll(Sort.by(Order(ASC, "dob")))75 sorted shouldExistInOrder listOf { it.id != null }76 }77})...

Full Screen

Full Screen

ProcessTest.kt

Source:ProcessTest.kt Github

copy

Full Screen

1package com.jazavac.taskmanager.api2import com.jazavac.taskmanager.api.Process.Companion.comparator3import com.jazavac.taskmanager.api.Process.Companion.leastPriorityComparator4import io.kotest.core.spec.style.ShouldSpec5import io.kotest.matchers.collections.shouldExistInOrder6import io.mockk.mockk7import java.time.Instant8class ProcessTest : ShouldSpec({9 context("sorting Processes") {10 val unsorted = listOf(11 Process(2, Priority.MEDIUM, mockk(), Instant.now().minusSeconds(15)),12 Process(1, Priority.MEDIUM, mockk(), Instant.now().minusSeconds(5)),13 Process(5, Priority.MEDIUM, mockk(), Instant.now().minusSeconds(20)),14 Process(4, Priority.HIGH, mockk(), Instant.now()),15 Process(3, Priority.LOW, mockk(), Instant.now().minusSeconds(10))16 )17 context("by id") {18 should("return a collection sorted by identifiers (ascending)") {19 val sorted = unsorted.sortedWith(comparator(SortOrder.ID))20 sorted shouldExistInOrder listOf(21 { it.identifier == 1L },22 { it.identifier == 2L },23 { it.identifier == 3L },24 { it.identifier == 4L },25 { it.identifier == 5L })26 }27 }28 context("by priority") {29 should("return a collection sorted by priority (descending), then id (ascending)") {30 val sorted = unsorted.sortedWith(comparator(SortOrder.PRIORITY))31 sorted shouldExistInOrder listOf(32 { it.identifier == 4L },33 { it.identifier == 1L },34 { it.identifier == 2L },35 { it.identifier == 5L },36 { it.identifier == 3L })37 }38 }39 context("by creation time") {40 should("return a collection sorted by creation time (ascending)") {41 val sorted = unsorted.sortedWith(comparator(SortOrder.CREATION_TIME))42 sorted shouldExistInOrder listOf(43 { it.identifier == 5L },44 { it.identifier == 2L },45 { it.identifier == 3L },46 { it.identifier == 1L },47 { it.identifier == 4L })48 }49 }50 context("by least priority") {51 should("return a collection sorted by priority (ascending), then creation time (ascending)") {52 val sorted = unsorted.sortedWith(leastPriorityComparator)53 println(sorted)54 sorted shouldExistInOrder listOf(55 { it.identifier == 3L },56 { it.identifier == 5L },57 { it.identifier == 2L },58 { it.identifier == 1L },59 { it.identifier == 4L })60 }61 }62 }63})...

Full Screen

Full Screen

AssertJTest.kt

Source:AssertJTest.kt Github

copy

Full Screen

1package ru.iopump.qa.sample.comment2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FreeSpec5import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder6import io.kotest.matchers.collections.shouldExistInOrder7import io.kotest.matchers.ints.shouldBeInRange8import io.kotest.matchers.shouldBe9import org.assertj.core.api.Assertions.assertThat10import org.assertj.core.api.Assertions.within11import org.assertj.core.api.SoftAssertions12class AssertJTest : FreeSpec() {13 init {14 "assertj and kotest asserts" - {15 "assertj simple assert" {16 assertThat(1).isCloseTo(2, within(1))17 }18 "kotest simple assert" {19 1 shouldBeInRange 1..220 }21 val list = listOf(1, 2, 3)22 "assertj collection" {23 assertThat(list).containsExactlyInAnyOrder(1, 2, 3)24 }25 "kotest collection" {26 list shouldContainExactlyInAnyOrder listOf(1, 2, 3)27 list.shouldExistInOrder({ it >= 1 }, { it >= 2 }, { it >= 3 })28 }29 "assertj - assertion error message" {30 shouldThrow<AssertionError> {31 assertThat(1.0).`as` { "Описание ошибки" }.isEqualTo(2.0)32 }.message.also(::println)33 }34 "kotest - assertion error message" {35 shouldThrow<AssertionError> {36 1.0 shouldBe 2.037 }.message.also(::println)38 }39 "assertj - soft assert" {40 shouldThrow<AssertionError> {41 SoftAssertions().apply {42 assertThat(1).isEqualTo(2)43 assertThat(2).isEqualTo(3)44 }.assertAll()45 }.message.also(::println)46 }47 "kotest - soft assert" {48 shouldThrow<AssertionError> {49 assertSoftly {50 1 shouldBe 251 2 shouldBe 352 }53 }.message.also(::println)54 }55 }56 }57}...

Full Screen

Full Screen

ConfigurationOrderTest.kt

Source:ConfigurationOrderTest.kt Github

copy

Full Screen

1/*2 * ProGuard -- shrinking, optimization, obfuscation, and preverification3 * of Java bytecode.4 *5 * Copyright (c) 2002-2021 Guardsquare NV6 */7package proguard.gradle.plugin.android.dsl8import io.kotest.core.spec.style.FreeSpec9import io.kotest.matchers.collections.shouldExistInOrder10import testutils.AndroidProject11import testutils.SourceFile12import testutils.applicationModule13import testutils.createGradleRunner14import testutils.createTestKitDir15class ConfigurationOrderTest : FreeSpec({16 val testKitDir = createTestKitDir()17 "Given a project with multiple configuration files" - {18 val project = autoClose(AndroidProject().apply {19 addModule(applicationModule("app", buildDotGradle = """20 plugins {21 id 'com.android.application'22 id 'proguard'23 }24 android {25 compileSdkVersion 3026 buildTypes {27 release {28 minifyEnabled false29 }30 }31 }32 proguard {33 configurations {34 release {35 configuration 'proguard-project1.txt'36 defaultConfiguration 'proguard-android.txt'37 configuration 'proguard-project2.txt'38 }39 }40 }""".trimIndent(),41 additionalFiles = listOf(SourceFile("proguard-project1.txt"), SourceFile("proguard-project2.txt"))))42 }.create())43 "When the project is built" - {44 val result = createGradleRunner(project.rootDir, testKitDir, "assembleRelease", "--info").build()45 "The configurations should be included in order" {46 result.output.lines().shouldExistInOrder(47 { it.contains("proguard-project1.txt") },48 { it.contains("proguard-android.txt") },49 { it.contains("proguard-project2.txt") })50 }51 }52 }53})...

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1 val list = listOf(1, 2, 3, 4, 5)2 list.shouldExistInOrder(1, 3, 5)3 list.shouldNotContain(7)4 val map = mapOf(1 to "one", 2 to "two", 3 to "three")5 map.shouldContainKey(1)6 map.shouldContainValue("one")7 map.shouldContain(Pair(1, "one"))8 map.shouldNotContain(Pair(4, "four"))9 map.shouldBeIn(listOf(mapOf(1 to "one", 2 to "two", 3 to "three")))10 map.shouldNotBeIn(listOf(mapOf(1 to "

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1List.shouldExistInOrder(listOf("A", "B", "C"))2List.shouldExistInOrder(listOf("A", "B", "C"))3List.shouldExistInOrder(listOf("A", "B", "C"))4List.shouldExistInOrder(listOf("A", "B", "C"))5List.shouldExistInOrder(listOf("A", "B", "C"))6List.shouldExistInOrder(listOf("A", "B", "C"))7List.shouldExistInOrder(listOf("A", "B", "C"))8List.shouldExistInOrder(listOf("A", "B", "C"))9List.shouldExistInOrder(listOf("A", "B", "C"))10List.shouldExistInOrder(listOf("A", "B", "C"))11List.shouldExistInOrder(listOf("A", "B", "C"))12List.shouldExistInOrder(listOf("A", "B", "C"))13List.shouldExistInOrder(listOf("A", "B", "C"))

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.collections.shouldExistInOrder2 import io.kotest.matchers.shouldBe3 import io.kotest.core.spec.style.StringSpec4 class SampleTest : StringSpec({5 "test" {6 val list = listOf("A", "B", "C")7 list.shouldExistInOrder("A", "B")8 list.shouldExistInOrder("B", "C")9 list.shouldExistInOrder("A", "C")10 list.shouldExistInOrder("A", "C", "B")11 list.shouldExistInOrder("A", "B", "C")12 list.shouldExistInOrder("C", "B", "A")13 list.shouldExistInOrder("B", "A", "C")14 list.shouldExistInOrder("C", "A", "B")15 list.shouldExistInOrder("C", "B", "A", "C", "B", "A")16 list.shouldExistInOrder("C", "B", "A", "C", "B", "A", "C", "B", "A")

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1 fun `test list should exist in order`(){2 val list = listOf(1, 2, 3, 4, 5)3 list.shouldExistInOrder(1, 2, 3)4 }5 fun `test list should not exist in order`(){6 val list = listOf(1, 2, 3, 4, 5)7 list.shouldNotExistInOrder(1, 3, 2)8 }9 fun `test list should be empty`(){10 val list = listOf<Int>()11 list.shouldBeEmpty()12 }13 fun `test list should not be empty`(){14 val list = listOf(1, 2, 3, 4, 5)15 list.shouldNotBeEmpty()16 }17 fun `test list should contain all`(){18 val list = listOf(1, 2, 3, 4, 5)19 list.shouldContainAll(1, 2, 3)20 }21 fun `test list should not contain all`(){22 val list = listOf(1, 2, 3, 4, 5)23 list.shouldNotContainAll(6, 7, 8)24 }25 fun `test list should contain any`(){26 val list = listOf(1, 2, 3, 4, 5)27 list.shouldContainAny(1, 6, 7)28 }29 fun `test list should not contain any`(){30 val list = listOf(1, 2, 3, 4

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1@DisplayName("Test for List.shouldExistInOrder method of io.kotest.matchers.collections.matchers class")2class ListShouldExistInOrderTest {3fun test1() {4val list = listOf(1, 2, 3, 4)5list.shouldExistInOrder(1, 2, 3, 4)6}7fun test2() {8val list = listOf(1, 2, 3, 4)9list.shouldExistInOrder(1, 2, 3)10}11fun test3() {12val list = listOf(1, 2, 3, 4)13list.shouldExistInOrder(1, 2, 4)14}15fun test4() {16val list = listOf(1, 2, 3, 4)17list.shouldExistInOrder(1, 2, 3, 4, 5)18}19}20@DisplayName("Test for List.shouldNotExistInOrder method of io.kotest.matchers.collections.matchers class")21class ListShouldNotExistInOrderTest {22fun test1() {23val list = listOf(1, 2, 3, 4)24list.shouldNotExistInOrder(1, 2, 3, 4, 5)25}26fun test2() {27val list = listOf(1, 2, 3, 4)28list.shouldNotExistInOrder(1, 2, 3, 5)29}30fun test3() {31val list = listOf(1, 2, 3, 4)32list.shouldNotExistInOrder(1, 2, 4, 5)33}34fun test4() {35val list = listOf(1, 2, 3, 4)36list.shouldNotExistInOrder(1, 2, 3, 4)37}38}39@DisplayName("Test for List.shouldBeEmpty method of io.kotest.matchers.collections.matchers class")40class ListShouldBeEmptyTest {41fun test1() {42val list = listOf<Int>()43list.shouldBeEmpty()44}45fun test2() {46val list = listOf(1,

Full Screen

Full Screen

List.shouldExistInOrder

Using AI Code Generation

copy

Full Screen

1 val actual = listOf("a", "b", "c")2 actual.shouldExistInOrder("b", "c")3 }4}5fun <T> Collection<T>.shouldExistInOrder(vararg elements: T)6 val actual = listOf("a", "b", "c")7 actual.shouldExistInOrder("b", "c")8fun <T> Collection<T>.shouldNotExistInOrder(vararg elements: T)9 val actual = listOf("a", "b", "c")10 actual.shouldNotExistInOrder("b", "c")11fun <T> Collection<T>.shouldContainExactly(vararg elements: T)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful