Skip to content

Commit cbf85ea

Browse files
committed
Release 0.7.5
Fix getTypedObj for String Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent fbf4210 commit cbf85ea

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* ************************************************************************************************
77
*/
88
const val GROUP_ID = "com.salesforce.revoman"
9-
const val VERSION = "0.7.4.1"
9+
const val VERSION = "0.7.5"
1010
const val ARTIFACT_ID = "revoman"
1111
const val STAGING_PROFILE_ID = "1ea0a23e61ba7d"

src/main/kotlin/com/salesforce/revoman/output/postman/PostmanEnvironment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ constructor(
125125
return when {
126126
value == null -> null
127127
targetType.rawType.isPrimitive && targetType.rawType.isInstance(value) -> value
128+
targetType == String::class.java -> value
128129
else -> {
129130
moshiReVoman.addAdapters(customAdapters, customAdaptersWithType, typesToIgnore)
130131
when (value) {
@@ -145,9 +146,10 @@ constructor(
145146
typesToIgnore: Set<Type> = emptySet(),
146147
): PojoT? {
147148
val value = mutableEnv[key]
148-
return when (value) {
149-
null -> null
150-
is PojoT -> value
149+
return when {
150+
value == null -> null
151+
value is PojoT -> value
152+
PojoT::class == String::class -> value as PojoT
151153
else -> {
152154
moshiReVoman.addAdapters(customAdapters, customAdaptersWithType, typesToIgnore)
153155
when (value) {

src/main/kotlin/com/salesforce/revoman/output/report/TxnInfo.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@ constructor(
2727
val moshiReVoman: MoshiReVoman,
2828
) {
2929
@JvmOverloads
30-
fun <T : Any> getTypedTxnObj(
31-
txnObjType: Type = this.txnObjType ?: Any::class.java,
30+
fun <PojoT : Any> getTypedTxnObj(
31+
targetType: Type = this.txnObjType ?: Any::class.java,
3232
customAdapters: List<Any> = emptyList(),
3333
customAdaptersWithType: Map<Type, Either<JsonAdapter<out Any>, JsonAdapter.Factory>> =
3434
emptyMap(),
3535
typesToIgnore: Set<Type> = emptySet(),
36-
): T? =
36+
): PojoT? =
3737
when {
3838
// ! TODO 15/10/23 gopala.akshintala: xml2Json
39+
txnObj == null -> null
40+
targetType.rawType.isInstance(txnObj) -> txnObj
41+
targetType == String::class.java -> txnObj
3942
!isJson ->
4043
throw IllegalCallerException("Non JSON (like XML) marshalling to POJO is not yet supported")
41-
txnObjType == this.txnObjType -> txnObj
4244
else -> {
4345
moshiReVoman.addAdapters(customAdapters, customAdaptersWithType, typesToIgnore)
44-
moshiReVoman.fromJson(httpMsg.bodyString(), txnObjType)
46+
moshiReVoman.fromJson(httpMsg.bodyString(), targetType)
4547
}
4648
}
47-
as T?
49+
as PojoT?
4850

4951
@JvmOverloads
5052
inline fun <reified PojoT : Any> getTxnObj(
@@ -54,10 +56,11 @@ constructor(
5456
typesToIgnore: Set<Type> = emptySet(),
5557
): PojoT? =
5658
when {
57-
// ! TODO 15/10/23 gopala.akshintala: xml2Json
59+
txnObj == null -> null
60+
txnObj is PojoT -> txnObj
61+
PojoT::class == String::class -> txnObj
5862
!isJson ->
5963
throw IllegalCallerException("Non JSON (like XML) marshalling to POJO is not yet supported")
60-
txnObjType != null && PojoT::class.java == txnObjType.rawType -> txnObj
6164
else -> {
6265
moshiReVoman.addAdapters(customAdapters, customAdaptersWithType, typesToIgnore)
6366
moshiReVoman.fromJson(httpMsg.bodyString())

src/test/java/com/salesforce/revoman/output/postman/PostmanEnvironmentTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void getTypedObj() {
7171
}
7272
""",
7373
"key7",
74+
"some string",
75+
"key8",
7476
null);
7577
final var pm = new PostmanEnvironment<>(env.toJavaMap());
7678
assertThat(pm.<Integer>getTypedObj("key1", Integer.class)).isEqualTo(env.get("key1").get());
@@ -91,6 +93,7 @@ void getTypedObj() {
9193
pm.<Map<String, Object>>getTypedObj(
9294
"key6", Types.newParameterizedType(Map.class, String.class, Object.class)))
9395
.isInstanceOf(Map.class);
94-
assertThat(pm.<Object>getTypedObj("key7", Object.class)).isNull();
96+
assertThat(pm.<String>getTypedObj("key7", String.class)).isEqualTo(env.get("key7"));
97+
assertThat(pm.<Object>getTypedObj("key8", Object.class)).isNull();
9598
}
9699
}

src/test/kotlin/com/salesforce/revoman/output/report/PostmanEnvironmentKtTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class PostmanEnvironmentKtTest {
6464
"Category": "Original"
6565
}
6666
""",
67-
"key7" to null,
67+
"key7" to "some string",
68+
"key8" to null,
6869
)
6970
val pmEnv = PostmanEnvironment(env)
7071
pmEnv.getObj<Int>("key1")!! shouldBeEqual env["key1"] as Int
@@ -73,6 +74,7 @@ class PostmanEnvironmentKtTest {
7374
pmEnv.getObj<Map<String, Int>>("key4")!! shouldContainExactly env["key4"] as Map<String, Int>
7475
pmEnv.getObj<List<String>>("key5")!! shouldContainExactly env["key5"] as List<String>
7576
pmEnv.getObj<Map<String, Any?>>("key6")!!.shouldNotBeEmpty()
76-
pmEnv.getObj<Any>("key7") shouldBe null
77+
pmEnv.getObj<String>("key7") shouldBe env["key7"]
78+
pmEnv.getObj<Any>("key8") shouldBe null
7779
}
7880
}

0 commit comments

Comments
 (0)