1
+ import com.nhaarman.mockitokotlin2.mock
2
+ import com.nhaarman.mockitokotlin2.whenever
1
3
import fr.free.nrw.commons.category.CategoryItem
4
+ import fr.free.nrw.commons.location.LatLng
5
+ import fr.free.nrw.commons.nearby.Label
6
+ import fr.free.nrw.commons.nearby.Place
7
+ import fr.free.nrw.commons.nearby.Sitelinks
2
8
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
9
+ import org.wikipedia.wikidata.*
3
10
4
11
fun depictedItem (
5
12
name : String = "label",
@@ -21,3 +28,59 @@ fun depictedItem(
21
28
22
29
fun categoryItem (name : String = "name", selected : Boolean = false) =
23
30
CategoryItem (name, selected)
31
+
32
+ fun place (
33
+ name : String = "name",
34
+ label : Label ? = null,
35
+ longDescription : String = "longDescription",
36
+ latLng : LatLng ? = null,
37
+ category : String = "category",
38
+ siteLinks : Sitelinks ? = null,
39
+ pic : String = "pic",
40
+ destroyed : String = "destroyed"
41
+ ): Place {
42
+ return Place (name, label, longDescription, latLng, category, siteLinks, pic, destroyed)
43
+ }
44
+
45
+ fun entityId (wikiBaseEntityValue : WikiBaseEntityValue = wikiBaseEntityValue()) =
46
+ DataValue .EntityId (wikiBaseEntityValue)
47
+
48
+ fun wikiBaseEntityValue (
49
+ entityType : String = "type",
50
+ id : String = "id",
51
+ numericId : Long = 0
52
+ ) = WikiBaseEntityValue (entityType, id, numericId)
53
+
54
+ fun statement (
55
+ mainSnak : Snak_partial = snak(),
56
+ rank : String = "rank",
57
+ type : String = "type"
58
+ ) = Statement_partial (mainSnak, type, rank)
59
+
60
+ fun snak (
61
+ snakType : String = "type",
62
+ property : String = "property",
63
+ dataValue : DataValue = valueString("")
64
+ ) = Snak_partial (snakType, property, dataValue)
65
+
66
+ fun valueString (value : String ) = DataValue .ValueString (value)
67
+
68
+ fun entity (
69
+ labels : Map <String , String > = emptyMap(),
70
+ descriptions : Map <String , String > = emptyMap(),
71
+ statements : Map <String , List <Statement_partial >>? = emptyMap(),
72
+ id : String = "id"
73
+ ) = mock<Entities .Entity >().apply {
74
+ val mockedLabels = labels.mockLabels()
75
+ whenever(labels()).thenReturn(mockedLabels)
76
+ val mockedDescriptions = descriptions.mockLabels()
77
+ whenever(descriptions()).thenReturn(mockedDescriptions)
78
+ whenever(this .statements).thenReturn(statements)
79
+ whenever(id()).thenReturn(id)
80
+ }
81
+
82
+ private fun Map <String , String >.mockLabels (): Map <String , Entities .Label > {
83
+ return mapValues { entry ->
84
+ mock<Entities .Label >().also { whenever(it.value()).thenReturn(entry.value) }
85
+ }
86
+ }
0 commit comments