Skip to content

Commit

Permalink
feat: [#129] Rename M3 implementation from RisRecord.typeOfWork to Ri…
Browse files Browse the repository at this point in the history
…sRecord.miscellaneous3
  • Loading branch information
ursjoss committed Feb 26, 2023
1 parent c0c161a commit be9f002
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ public data class RisRecord(
*/
public var miscellaneous2: String? = null,

/** M3 */
/**
* M3 - often used for Type of Work. Alphanumeric field.
*/
public var miscellaneous3: String? = null,

// TODO remove in #132
/** M3 - deprecated */
@Deprecated("Use miscellaneous3 instead", ReplaceWith("miscellaneous3"))
public var typeOfWork: String? = null,

/** N1 */
Expand Down Expand Up @@ -341,8 +348,11 @@ public data class RisRecord(
private var label: String? = null
private var websiteLink: String? = null
private var miscellaneous1: String? = null
// TODO remove in #132
private var number: Long? = null
private var miscellaneous2: String? = null
private var miscellaneous3: String? = null
// TODO remove in #132
private var typeOfWork: String? = null
private var notes: String? = null
private var abstr2: String? = null
Expand Down Expand Up @@ -467,6 +477,9 @@ public data class RisRecord(
@Deprecated("use miscellaneous1(number.toString()) instead", ReplaceWith("miscellaneous1(number.toString())"))
public fun number(number: Long?): Builder = apply { this.number = number }
public fun miscellaneous2(miscellaneous2: String?): Builder = apply { this.miscellaneous2 = miscellaneous2 }
public fun miscellaneous3(miscellaneous3: String?): Builder = apply { this.miscellaneous3 = miscellaneous3 }

@Deprecated("use miscellaneous3(String) instead", ReplaceWith("miscellaneous3(typeOfWork)"))
public fun typeOfWork(typeOfWork: String?): Builder = apply { this.typeOfWork = typeOfWork }
public fun notes(notes: String?): Builder = apply { this.notes = notes }
public fun abstr2(abstr2: String?): Builder = apply { this.abstr2 = abstr2 }
Expand Down Expand Up @@ -557,6 +570,7 @@ public data class RisRecord(
miscellaneous1,
number,
miscellaneous2,
miscellaneous3,
typeOfWork,
notes,
abstr2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,18 @@ public enum class RisTag(
getFrom = { r: RisRecord -> r.miscellaneous2 }
),

/** Type of Work */
/** Miscellaneous 3. Often used for Type of Work */
@Suppress("Deprecation")
M3(
description = "Type of Work",
setInto = { r, v -> r.typeOfWork = v as String? },
getFrom = { r: RisRecord -> r.typeOfWork }
description = "Miscellaneous 3 (often Type of Work)",
setInto = { r, v ->
r.miscellaneous3 = v as String?
r.typeOfWork = v
},
getFrom = { r: RisRecord ->
r.miscellaneous3.takeUnless { it.isNullOrBlank() }
?: r.typeOfWork
}
),

/** Notes */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RisRecordBuilderTest {
.websiteLink("websiteLink")
.miscellaneous1("number")
.miscellaneous2("miscellaneous2")
.typeOfWork("typeOfWork")
.miscellaneous3("typeOfWork")
.notes("notes")
.abstr2("abstr2")
.numberOfVolumes("numberOfVolumes")
Expand Down Expand Up @@ -140,7 +140,7 @@ void canFillAllFieldsIntoDataClassAppropriately() {
assertThat(risRecord.getWebsiteLink()).isEqualTo("websiteLink");
assertThat(risRecord.getMiscellaneous1()).isEqualTo("number");
assertThat(risRecord.getMiscellaneous2()).isEqualTo("miscellaneous2");
assertThat(risRecord.getTypeOfWork()).isEqualTo("typeOfWork");
assertThat(risRecord.getMiscellaneous3()).isEqualTo("typeOfWork");
assertThat(risRecord.getNotes()).isEqualTo("notes");
assertThat(risRecord.getAbstr2()).isEqualTo("abstr2");
assertThat(risRecord.getNumberOfVolumes()).isEqualTo("numberOfVolumes");
Expand Down Expand Up @@ -224,7 +224,7 @@ void emptyRecord() {
assertThat(risRecord.getWebsiteLink()).isNull();
assertThat(risRecord.getMiscellaneous1()).isNull();
assertThat(risRecord.getMiscellaneous2()).isNull();
assertThat(risRecord.getTypeOfWork()).isNull();
assertThat(risRecord.getMiscellaneous3()).isNull();
assertThat(risRecord.getNotes()).isNull();
assertThat(risRecord.getAbstr2()).isNull();
assertThat(risRecord.getNumberOfVolumes()).isNull();
Expand Down Expand Up @@ -276,4 +276,24 @@ public void givenRisRecordWithNumber_providesNumberButNotMisc1() {
assertThat(risRecord.getMiscellaneous1()).isNull();
assertThat(risRecord.getNumber()).isEqualTo(1234L);
}

@SuppressWarnings("deprecation")
@Test
public void givenRisRecordWithMisc3_providesMisc3ButNotTypeOfWork() {
RisRecord risRecord = new RisRecord.Builder()
.miscellaneous3("misc3")
.build();
assertThat(risRecord.getMiscellaneous3()).isEqualTo("misc3");
assertThat(risRecord.getTypeOfWork()).isNull();
}

@SuppressWarnings("deprecation")
@Test
public void givenRisRecordWithTypeOfWork_providesTypeOfWorkButNotMisc3() {
RisRecord risRecord = new RisRecord.Builder()
.typeOfWork("misc3")
.build();
assertThat(risRecord.getMiscellaneous3()).isNull();
assertThat(risRecord.getTypeOfWork()).isEqualTo("misc3");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class KRisProcessFromListTest {
websiteLink = "websiteLink",
miscellaneous1 = "number",
miscellaneous2 = "miscellaneous2",
typeOfWork = "typeOfWork",
miscellaneous3 = "typeOfWork",
notes = "notes",
abstr2 = "abstr2",
numberOfVolumes = "numberOfVolumes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object RisRecordSpec : DescribeSpec({
websiteLink = null,
miscellaneous1 = null,
miscellaneous2 = null,
typeOfWork = null,
miscellaneous3 = null,
notes = null,
abstr2 = null,
numberOfVolumes = null,
Expand Down Expand Up @@ -161,7 +161,7 @@ object RisRecordSpec : DescribeSpec({
websiteLink = "websiteLink",
miscellaneous1 = "number",
miscellaneous2 = "miscellaneous2",
typeOfWork = "typeOfWork",
miscellaneous3 = "typeOfWork",
notes = "notes",
abstr2 = "abstr2",
numberOfVolumes = "numberOfVolumes",
Expand Down Expand Up @@ -246,7 +246,7 @@ object RisRecordSpec : DescribeSpec({
.websiteLink("websiteLink")
.miscellaneous1("number")
.miscellaneous2("miscellaneous2")
.typeOfWork("typeOfWork")
.miscellaneous3("typeOfWork")
.notes("notes")
.abstr2("abstr2")
.numberOfVolumes("numberOfVolumes")
Expand Down Expand Up @@ -285,22 +285,34 @@ object RisRecordSpec : DescribeSpec({
@Suppress("DEPRECATION")
describe("Deprecated fields") {
describe("with RisRecord constructed with new properties") {
val record = RisRecord(miscellaneous1 = "1234")
val record = RisRecord(miscellaneous1 = "1234", miscellaneous3 = "foo")
it("should return null as Number") {
record.number.shouldBeNull()
}
it("should return null as typeOfWork") {
record.typeOfWork.shouldBeNull()
}
it("should return '1234' as miscellaneous1") {
record.miscellaneous1 shouldBeEqualTo "1234"
}
it("should return 'foo'' as miscellaneous3") {
record.miscellaneous3 shouldBeEqualTo "foo"
}
}
describe("with RisRecord constructed with deprecated properties") {
val record = RisRecord(number = 1234L)
val record = RisRecord(number = 1234L, typeOfWork = "foo")
it("should return 1234 as Number") {
record.number shouldBeEqualTo 1234L
}
it("should return 'foo' as typeOfWork") {
record.typeOfWork shouldBeEqualTo "foo"
}
it("should return null as miscellaneous1") {
record.miscellaneous1.shouldBeNull()
}
it("should return null as miscellaneous3") {
record.miscellaneous3.shouldBeNull()
}
}
}
})
Expand Down Expand Up @@ -346,7 +358,7 @@ private suspend fun DescribeSpecContainerScope.assertDefaultValues(record: RisRe
"websiteLink" to record.websiteLink,
"number" to record.miscellaneous1,
"miscellaneous2" to record.miscellaneous2,
"typeOfWork" to record.typeOfWork,
"typeOfWork" to record.miscellaneous3,
"notes" to record.notes,
"abstr2" to record.abstr2,
"numberOfVolumes" to record.numberOfVolumes,
Expand Down Expand Up @@ -442,7 +454,7 @@ private suspend fun DescribeSpecContainerScope.assertSpecifiedValues(record: Ris
"websiteLink" to record.websiteLink,
"number" to record.miscellaneous1,
"miscellaneous2" to record.miscellaneous2,
"typeOfWork" to record.typeOfWork,
"typeOfWork" to record.miscellaneous3,
"notes" to record.notes,
"abstr2" to record.abstr2,
"numberOfVolumes" to record.numberOfVolumes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class RisTagTest {
"Website Link",
"Miscellaneous 1 (often Number)",
"Miscellaneous 2.",
"Type of Work",
"Miscellaneous 3 (often Type of Work)",
"Notes",
"Abstract.",
"Number of Volumes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,42 @@ object KRisUsageSpec : DescribeSpec({
risRecords.first().number.shouldBeNull()
}
}
describe("given M3") {
val risLines: List<String> = listOf(
"M3 - typeOfWork",
"ER - "
)
it("can be processed") {
val risRecords = risLines.toRisRecords()
risRecords.shouldHaveSize(1)
}
it("can retrieve it with new property miscellaneous3") {
val risRecords = risLines.toRisRecords()
risRecords.first().miscellaneous3 shouldBeEqualTo "typeOfWork"
}
it("can retrieve it with deprecated property typeOfWork") {
val risRecords = risLines.toRisRecords()
risRecords.first().typeOfWork shouldBeEqualTo "typeOfWork"
}
}
}
describe("exporting to RIS") {
describe("using new properties miscellaneous1") {
describe("using new properties miscellaneous1 and miscellaneous 3") {
val risRecord1 = RisRecord(
miscellaneous1 = "1234-5678",
miscellaneous3 = "typeOfWork",
)
val risRecord2 = RisRecord(
number = 4567L,
typeOfWork = "tow",
)
it("should export to M1") {
it("should export both to M1 and M3") {
listOf(risRecord1, risRecord2).toRisLines().joinToString(separator = "") shouldBeEqualTo """M1 - 1234-5678
|M3 - typeOfWork
|ER -
|
|M1 - 4567
|M3 - tow
|ER -
|""".trimMargin()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object KRisIoUsageSpec : DescribeSpec({
val records = listOf(
RisRecord(
type = RisType.ABST,
typeOfWork = "tow",
miscellaneous3 = "tow",
abstr = "abstr",
language = "lang",
databaseProvider = "dp"
Expand Down

0 comments on commit be9f002

Please sign in to comment.