+ protected operator fun SimpleFieldSet.plusAssign(keyValue: Pair<String, String?>) = putSingle(keyValue.first, keyValue.second)
+ protected fun SimpleFieldSet.parsePost(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Recipient", "Time", "Text")
+ protected fun SimpleFieldSet.parseReply(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Time", "Text")
+ protected fun SimpleFieldSet.parseSone(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Name", "NiceName", "LastUpdated", "Followed") +
+ (0 until this["${prefix}Field.Count"].toInt()).map {
+ ("Field." + this["${prefix}Field.$it.Name"]) to this["${prefix}Field.$it.Value"]
+ }
+
+ private fun SimpleFieldSet.parseFromSimpleFieldSet(prefix: String, vararg fields: String): Map<String, String?> = fields
+ .associate { it to get(prefix + it) }
+
+ protected fun matchesPost(post: Post) = OneByOneMatcher<Map<String, String?>>().apply {
+ expect("ID", post.id) { it["ID"] }
+ expect("Sone", post.sone.id) { it["Sone"] }
+ expect("recipient", post.recipientId.orNull()) { it["Recipient"] }
+ expect("time", post.time.toString()) { it["Time"] }
+ expect("text", post.text.replace("\\", "\\\\").replace("\r", "\\r").replace("\n", "\\n")) { it["Text"] }
+ }
+
+ protected fun matchesReply(reply: PostReply) = OneByOneMatcher<Map<String, String?>>().apply {
+ expect("ID", reply.id) { it["ID"] }
+ expect("Sone", reply.sone.id) { it["Sone"] }
+ expect("time", reply.time.toString()) { it["Time"] }
+ expect("text", reply.text.replace("\\", "\\\\").replace("\r", "\\r").replace("\n", "\\n")) { it["Text"] }
+ }
+
+ protected fun matchesSone(sone: Sone) = OneByOneMatcher<Map<String, String?>>().apply {
+ expect("ID", sone.id) { it["ID"] }
+ expect("name", sone.name) { it["Name"] }
+ expect("last updated", sone.time.toString()) { it["LastUpdated"] }
+ expect("nice name", SoneAccessor.getNiceName(sone)) { it["NiceName"] }
+ sone.profile.fields.forEach { field ->
+ expect("field: ${field.name}", field.value) { it["Field.${field.name}"] }
+ }
+ }
+