From c700c0b1c0d5e16312d8039932b6a9c0e0339f67 Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Mon, 26 Jun 2023 17:49:45 +0200 Subject: [PATCH] Cleanup tests - part 5 --- ...rpBreadthFirstTopologicalSortTest.class.st | 44 ++++++++++++------- .../GlorpCommandTest.class.st | 21 ++++----- .../GlorpConstantMappingTest.class.st | 3 +- .../GlorpDatabaseAccessorTest.class.st | 22 +++++----- .../GlorpDatabasePlatformTest.class.st | 19 +++++--- .../GlorpDeleteInUnitOfWorkTest.class.st | 27 ++++++++---- .../ManifestGlorpTests.class.st | 14 ++++++ 7 files changed, 99 insertions(+), 51 deletions(-) diff --git a/src/Glorp-Unit-Tests/GlorpBreadthFirstTopologicalSortTest.class.st b/src/Glorp-Unit-Tests/GlorpBreadthFirstTopologicalSortTest.class.st index 63d1da94..1791c1e4 100644 --- a/src/Glorp-Unit-Tests/GlorpBreadthFirstTopologicalSortTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpBreadthFirstTopologicalSortTest.class.st @@ -11,37 +11,41 @@ Class { #category : #'Glorp-Unit-Tests-Tests' } -{ #category : #support } +{ #category : #asserting } GlorpBreadthFirstTopologicalSortTest >> assertSortOrder: aCollection [ + | ids | - ids := (sorted collect: [:each | each id]) asArray. - self assert: ids = aCollection asArray. + ids := (sorted collect: [ :each | each id ]) asArray. + self assert: ids equals: aCollection asArray ] { #category : #data } GlorpBreadthFirstTopologicalSortTest >> data1 [ + | one two three | one := GlorpBreadthFirstTopologicalSortItem new id: 1. two := GlorpBreadthFirstTopologicalSortItem new id: 2. three := GlorpBreadthFirstTopologicalSortItem new id: 3. one relateTo: two. two relateTo: three. - ^Array with: one with: two with: three. + ^ Array with: one with: two with: three ] { #category : #data } GlorpBreadthFirstTopologicalSortTest >> dataForGroupNamed: aString [ + | one two three four | one := GlorpBreadthFirstTopologicalSortItem new id: aString, '1'. two := GlorpBreadthFirstTopologicalSortItem new id: aString, '2'. three := GlorpBreadthFirstTopologicalSortItem new id: aString, '3'. four := GlorpBreadthFirstTopologicalSortItem new id: aString, '4'. - ^Array with: one with: two with: three with: four. + ^Array with: one with: two with: three with: four ] { #category : #data } GlorpBreadthFirstTopologicalSortTest >> dataForMedium [ "Data to ensure that things tend to stay together. This is a simple grouping a1->b, b->c, b->a2, repeated, with some extra floating b's and c's." + groupA := self dataForGroupNamed: 'a'. groupB := self dataForGroupNamed: 'b'. groupC := self dataForGroupNamed: 'c'. @@ -51,57 +55,63 @@ GlorpBreadthFirstTopologicalSortTest >> dataForMedium [ (groupB at: 3) relateTo: (groupC at: 3). groupB first relateTo: (groupA at: 2). (groupB at: 3) relateTo: (groupA at: 4). - ^groupA, groupB, groupC. + ^groupA, groupB, groupC ] { #category : #data } GlorpBreadthFirstTopologicalSortTest >> dataForNoCyclesMedium [ "Data to ensure that things tend to stay together. This is a simple grouping a->b, b->c repeated" + groupA := self dataForGroupNamed: 'a'. groupB := self dataForGroupNamed: 'b'. groupC := self dataForGroupNamed: 'c'. 1 to: 4 do: [:i | (groupA at: i) relateTo: (groupB at: i). (groupB at: i) relateTo: (groupC at: i)]. - ^groupC, groupB, groupA. + ^groupC, groupB, groupA ] { #category : #data } GlorpBreadthFirstTopologicalSortTest >> dataForNoCyclesMediumPermuted [ "Data to ensure that things tend to stay together. This is a simple grouping a->b, b->c repeated" + groupA := self dataForGroupNamed: 'a'. groupB := self dataForGroupNamed: 'b'. groupC := self dataForGroupNamed: 'c'. 1 to: 4 do: [:i | (groupA at: i) relateTo: (groupB at: i). (groupB at: i) relateTo: (groupC at: i)]. - ^groupB, groupA, groupC. + ^groupB, groupA, groupC ] { #category : #support } GlorpBreadthFirstTopologicalSortTest >> sort [ + | sorter | sorter := GlorpRowSorter new getChildrenVia: #relatedItems. - sorted := sorter sort: unsorted. + sorted := sorter sort: unsorted ] { #category : #support } GlorpBreadthFirstTopologicalSortTest >> sort: aCollection [ + unsorted := aCollection. - self sort. + self sort ] { #category : #tests } GlorpBreadthFirstTopologicalSortTest >> testBasicSort1 [ + self sort: self data1. - self assertSortOrder: #(3 2 1). + self assertSortOrder: #( 3 2 1 ) ] { #category : #tests } GlorpBreadthFirstTopologicalSortTest >> testBasicSort2 [ "Try it with a different initial order. The sort is a convoluted way of writing the questionably-portable reverse" - self sort: (self data1 asSortedCollection: [:a :b | a id >= b id]). - self assertSortOrder: #(3 2 1). + + self sort: (self data1 asSortedCollection: [ :a :b | a id >= b id ]). + self assertSortOrder: #( 3 2 1 ) ] { #category : #tests } @@ -123,14 +133,18 @@ GlorpBreadthFirstTopologicalSortTest >> testBasicSortCompleteGraph [ { #category : #tests } GlorpBreadthFirstTopologicalSortTest >> testMedium1 [ + self sort: self dataForMedium. - self assertSortOrder: #('c1' 'a2' 'b1' 'a1' 'c3' 'a4' 'b3' 'a3' 'b2' 'b4' 'c2' 'c4'). + self assertSortOrder: + #( 'c1' 'a2' 'b1' 'a1' 'c3' 'a4' 'b3' 'a3' 'b2' 'b4' 'c2' 'c4' ) ] { #category : #tests } GlorpBreadthFirstTopologicalSortTest >> testNoCyclesMedium [ + self sort: self dataForNoCyclesMedium. - self assertSortOrder: #('c1' 'c2' 'c3' 'c4' 'b1' 'b2' 'b3' 'b4' 'a1' 'a2' 'a3' 'a4'). + self assertSortOrder: + #( 'c1' 'c2' 'c3' 'c4' 'b1' 'b2' 'b3' 'b4' 'a1' 'a2' 'a3' 'a4' ) ] { #category : #tests } diff --git a/src/Glorp-Unit-Tests/GlorpCommandTest.class.st b/src/Glorp-Unit-Tests/GlorpCommandTest.class.st index b3510d47..378fd084 100644 --- a/src/Glorp-Unit-Tests/GlorpCommandTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpCommandTest.class.st @@ -45,7 +45,7 @@ GlorpCommandTest >> testSplittingInserts1 [ subCommands := command subCommands. self assert: subCommands size equals: 1. self assert: subCommands first allRows size equals: 1. - self assert: subCommands first allRows first == rows first + self assert: subCommands first allRows first identicalTo: rows first ] { #category : #tests } @@ -57,11 +57,12 @@ GlorpCommandTest >> testSplittingInserts1000 [ subCommands := command subCommands. self assert: subCommands size equals: 1. self assert: subCommands first allRows size equals: 1000. - self assert: subCommands first allRows first == rows first + self assert: subCommands first allRows first identicalTo: rows first ] { #category : #tests } GlorpCommandTest >> testSplittingInserts1001 [ + | rows command subCommands | rows := (Array new: 1001) atAllPut: DatabaseRow new. rows at: rows size put: DatabaseRow new. @@ -69,9 +70,9 @@ GlorpCommandTest >> testSplittingInserts1001 [ subCommands := command subCommands. self assert: subCommands size equals: 2. self assert: subCommands first allRows size equals: 1000. - self assert: subCommands first allRows first == rows first. + self assert: subCommands first allRows first identicalTo: rows first. self assert: subCommands last allRows size equals: 1. - self assert:subCommands last allRows first == rows last. + self assert: subCommands last allRows first identicalTo: rows last ] { #category : #tests } @@ -83,11 +84,11 @@ GlorpCommandTest >> testSplittingInserts1003 [ command := InsertCommand forRows: rows useBinding: false session: nil. subCommands := command subCommands. self assert: subCommands size equals: 2. - self assert: subCommands first allRows size = 1000. - self assert: subCommands first allRows first == rows first. + self assert: subCommands first allRows size equals: 1000. + self assert: subCommands first allRows first identicalTo: rows first. self assert: subCommands last allRows size equals: 3. - self assert:subCommands last allRows last == rows last. - self assert: subCommands last allRows first == rows first + self assert: subCommands last allRows last identicalTo: rows last. + self assert: subCommands last allRows first identicalTo: rows first ] { #category : #tests } @@ -99,6 +100,6 @@ GlorpCommandTest >> testSplittingInserts2 [ subCommands := command subCommands. self assert: subCommands size equals: 1. self assert: subCommands first allRows size equals: 2. - self assert: subCommands first allRows first == rows first. - self assert: subCommands first allRows last == rows last. + self assert: subCommands first allRows first identicalTo: rows first. + self assert: subCommands first allRows last identicalTo: rows last ] diff --git a/src/Glorp-Unit-Tests/GlorpConstantMappingTest.class.st b/src/Glorp-Unit-Tests/GlorpConstantMappingTest.class.st index 2b1fff08..1e439f20 100644 --- a/src/Glorp-Unit-Tests/GlorpConstantMappingTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpConstantMappingTest.class.st @@ -49,6 +49,7 @@ GlorpConstantMappingTest >> testGetValue [ { #category : #tests } GlorpConstantMappingTest >> testSessionValue [ + mappingToClass constantValueIsSession. - self assert: (mappingToClass constantValueIn: 38)== 38. + self assert: (mappingToClass constantValueIn: 38) identicalTo: 38 ] diff --git a/src/Glorp-Unit-Tests/GlorpDatabaseAccessorTest.class.st b/src/Glorp-Unit-Tests/GlorpDatabaseAccessorTest.class.st index 3e1430dc..a4e6d454 100644 --- a/src/Glorp-Unit-Tests/GlorpDatabaseAccessorTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpDatabaseAccessorTest.class.st @@ -6,17 +6,19 @@ Class { { #category : #tests } GlorpDatabaseAccessorTest >> testLoggingSwitch [ + | currentSetting accessor | currentSetting := DatabaseAccessor loggingEnabled. accessor := DatabaseAccessor new. - [DatabaseAccessor loggingEnabled: true. - self assert: accessor logging. - DatabaseAccessor loggingEnabled: false. - self deny: accessor logging. - accessor logging: true. - self assert: accessor logging. - accessor logging: false. - self deny: accessor logging. - DatabaseAccessor loggingEnabled: true. - self deny: accessor logging] ensure: [DatabaseAccessor loggingEnabled: currentSetting]. + + [ DatabaseAccessor loggingEnabled: true. + self assert: accessor logging. + DatabaseAccessor loggingEnabled: false. + self deny: accessor logging. + accessor logging: true. + self assert: accessor logging. + accessor logging: false. + self deny: accessor logging. + DatabaseAccessor loggingEnabled: true. + self deny: accessor logging ] ensure: [ DatabaseAccessor loggingEnabled: currentSetting ] ] diff --git a/src/Glorp-Unit-Tests/GlorpDatabasePlatformTest.class.st b/src/Glorp-Unit-Tests/GlorpDatabasePlatformTest.class.st index 03a86b09..db497e99 100644 --- a/src/Glorp-Unit-Tests/GlorpDatabasePlatformTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpDatabasePlatformTest.class.st @@ -4,7 +4,7 @@ Class { #category : #'Glorp-Unit-Tests-Tests' } -{ #category : #tests } +{ #category : #utilities } GlorpDatabasePlatformTest >> addToString: aString [ "Append a couple of special characters. The result will utf-8 encode to be 3 characters longer than its number of characters" ^aString, (String with: (Character value: 16r2022) "bullet point" with: (Character value: 16r0131) "Turkish i with no dot") @@ -16,7 +16,7 @@ double-byte entries. The VA could be implemented as " ] -{ #category : #tests } +{ #category : #utilities } GlorpDatabasePlatformTest >> helpTestPrintTimestamp: aTimestampString [ | aStream ts timestamp | @@ -24,17 +24,21 @@ GlorpDatabasePlatformTest >> helpTestPrintTimestamp: aTimestampString [ aStream := WriteStream on: String new. DatabasePlatform new printDate: ts isoFormatOn: aStream. aStream nextPut: Character space. - DatabasePlatform new printTime: ts isoFormatOn: aStream milliseconds: Dialect supportsMillisecondsInTimes . + DatabasePlatform new + printTime: ts + isoFormatOn: aStream + milliseconds: Dialect supportsMillisecondsInTimes. timestamp := aStream contents. - self assert: timestamp = aTimestampString. + self assert: timestamp equals: aTimestampString ] -{ #category : #tests } +{ #category : #utilities } GlorpDatabasePlatformTest >> string20 [ + | platform | platform := PostgresPlatform new. platform characterEncoding: #'utf-8'. - ^platform varchar: 20. + ^ platform varchar: 20 ] { #category : #tests } @@ -59,7 +63,7 @@ GlorpDatabasePlatformTest >> testPrintTimestamp [ | strings | strings := #( '2005-01-01 21:29:28.337' '2005-01-01 01:02:00.037' '2005-01-01 21:29:28.002' '2005-01-01 21:29:28.001'). strings do: [:each | - self helpTestPrintTimestamp: each]. + self helpTestPrintTimestamp: each] ] { #category : #tests } @@ -159,6 +163,7 @@ GlorpDatabasePlatformTest >> testTrimString1 [ { #category : #tests } GlorpDatabasePlatformTest >> testTrimString2 [ "Some special characters" + | type plat string | type := self string20. diff --git a/src/Glorp-Unit-Tests/GlorpDeleteInUnitOfWorkTest.class.st b/src/Glorp-Unit-Tests/GlorpDeleteInUnitOfWorkTest.class.st index cd598bd0..b2a20eea 100644 --- a/src/Glorp-Unit-Tests/GlorpDeleteInUnitOfWorkTest.class.st +++ b/src/Glorp-Unit-Tests/GlorpDeleteInUnitOfWorkTest.class.st @@ -9,7 +9,9 @@ Class { { #category : #running } GlorpDeleteInUnitOfWorkTest >> setUp [ + | session | + super setUp. session := GlorpMockSession new. session beginUnitOfWork. unitOfWork := session privateGetCurrentUnitOfWork. @@ -40,29 +42,34 @@ GlorpDeleteInUnitOfWorkTest >> testCommit [ unitOfWork delete: GlorpAddress example1. unitOfWork commit. - self assert: (unitOfWork numberOfRows) = 1. + self assert: unitOfWork numberOfRows equals: 1 ] { #category : #tests } GlorpDeleteInUnitOfWorkTest >> testDeleteRegistration [ + | obj | obj := Object new. unitOfWork delete: obj. self assert: (unitOfWork willDelete: obj). - self deny: (unitOfWork willDelete: 3). + self deny: (unitOfWork willDelete: 3) ] { #category : #tests } GlorpDeleteInUnitOfWorkTest >> testDeletesComeAfterUpdates [ + unitOfWork delete: GlorpAddress example1. unitOfWork register: GlorpCustomer example1. unitOfWork commit. - self assert: unitOfWork session rows last table == (self tableNamed: 'GR_ADDRESS'). + self + assert: unitOfWork session rows last table + identicalTo: (self tableNamed: 'GR_ADDRESS') ] { #category : #tests } GlorpDeleteInUnitOfWorkTest >> testDeletesInReverseOrder [ "Not that good a test, because it could be luck with only two tables. Should test this at a lower level" + | cust trans | cust := GlorpCustomer example2. trans := cust transactions first. @@ -71,15 +78,19 @@ GlorpDeleteInUnitOfWorkTest >> testDeletesInReverseOrder [ unitOfWork delete: cust. unitOfWork delete: trans. unitOfWork commit. - self assert: unitOfWork session rows last owner == cust. - self assert: (unitOfWork session rows reverse at: 2) owner == trans. + self assert: unitOfWork session rows last owner identicalTo: cust. + self + assert: (unitOfWork session rows reverse at: 2) owner + identicalTo: trans ] { #category : #tests } GlorpDeleteInUnitOfWorkTest >> testGeneratingDeleteRows [ + unitOfWork delete: GlorpAddress example1. unitOfWork createRows. - self assert: unitOfWork privateGetRowMap numberOfEntries = 1. - unitOfWork rowsForTable: (self tableNamed: 'GR_ADDRESS') - do: [:each | self assert: each forDeletion] + self assert: unitOfWork privateGetRowMap numberOfEntries equals: 1. + unitOfWork + rowsForTable: (self tableNamed: 'GR_ADDRESS') + do: [ :each | self assert: each forDeletion ] ] diff --git a/src/Glorp-Unit-Tests/ManifestGlorpTests.class.st b/src/Glorp-Unit-Tests/ManifestGlorpTests.class.st index 9168afe7..c68f494a 100644 --- a/src/Glorp-Unit-Tests/ManifestGlorpTests.class.st +++ b/src/Glorp-Unit-Tests/ManifestGlorpTests.class.st @@ -14,6 +14,13 @@ ManifestGlorpTests class >> ruleEqualNilRuleV1FalsePositive [ ^ #(#(#(#RGMethodDefinition #(#GlorpExpressionTest #testIsNullPrint #false)) #'2023-06-26T17:18:01.373504+02:00') #(#(#RGMethodDefinition #(#GlorpExpressionTest #testNotNullPrint #false)) #'2023-06-26T17:18:26.409147+02:00') ) ] +{ #category : #'code-critics' } +ManifestGlorpTests class >> ruleLiteralArrayContainsSuspiciousTrueFalseOrNilRuleV1FalsePositive [ + + + ^ #(#(#(#RGMetaclassDefinition #(#'ManifestGlorpTests class' #ManifestGlorpTests)) #'2023-06-26T17:49:36.133076+02:00') ) +] + { #category : #'code-critics' } ManifestGlorpTests class >> ruleSentNotImplementedRuleV1FalsePositive [ @@ -27,3 +34,10 @@ ManifestGlorpTests class >> ruleUncommonMessageSendRuleV1FalsePositive [ ^ #(#(#(#RGMethodDefinition #(#GlorpExpressionTest #testAndOperation2 #false)) #'2023-06-26T17:13:37.574583+02:00') #(#(#RGMethodDefinition #(#GlorpExpressionTest #testOrOperation2 #false)) #'2023-06-26T17:18:49.992423+02:00') ) ] + +{ #category : #'code-critics' } +ManifestGlorpTests class >> ruleUtilityMethodsRuleV1FalsePositive [ + + + ^ #(#(#(#RGClassDefinition #(#GlorpDatabasePlatformTest)) #'2023-06-26T17:48:39.700269+02:00') #(#(#RGMethodDefinition #(#GlorpBreadthFirstTopologicalSortTest #dataForGroupNamed: #false)) #'2023-06-26T17:48:57.821673+02:00') ) +]