Skip to content

Commit 33d685b

Browse files
committed
enabling getAsString() to return empty string rather than null
1 parent 7453a3a commit 33d685b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/main/java/datastax/astra/migrate/properties/PropertyHelper.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,28 @@ public List<MigrateDataType> getMigrationTypeList(String propertyName) {
181181
}
182182

183183
public String getAsString(String propertyName) {
184+
String rtn;
184185
if (null == propertyName)
185186
return null;
186187
Object propertyValue = get(propertyName, getType(propertyName));
187188
if (null == propertyValue)
188-
return null;
189+
return "";
189190
switch (getType(propertyName)) {
190191
case STRING:
191-
return (String) propertyValue;
192+
rtn = (String) propertyValue;
193+
break;
192194
case STRING_LIST:
193195
case NUMBER_LIST:
194196
case MIGRATION_TYPE_LIST:
195-
return StringUtils.join((List<?>) propertyValue, ",");
197+
rtn = StringUtils.join((List<?>) propertyValue, ",");
198+
break;
196199
case NUMBER:
197200
case BOOLEAN:
198201
case MIGRATION_TYPE:
199202
default:
200-
return propertyValue.toString();
203+
rtn = propertyValue.toString();
201204
}
205+
return (null == rtn) ? "" : rtn;
202206
}
203207

204208
protected void loadSparkConf() {

src/test/java/datastax/astra/migrate/properties/PropertyHelperTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ public void getAsString_MigrateDataTypeList() {
459459
assertEquals("0,5%0%1", helper.getAsString(KnownProperties.TEST_MIGRATE_TYPE_LIST));
460460
}
461461

462-
// @Test
463-
// public void getAsString_valueNotSet_withDefault() {
464-
// assertEquals(KnownProperties.getDefaultAsString(KnownProperties.TEST_STRING),helper.getAsString(KnownProperties.TEST_STRING));
465-
// }
466-
//
467-
// @Test
468-
// public void getAsString_valueNotSet_noDefault() {
469-
// assertNull(helper.getAsString(KnownProperties.TEST_STRING_NO_DEFAULT));
470-
// }
462+
@Test
463+
public void getAsString_valueNotSet_string() {
464+
assertEquals("",helper.getAsString(KnownProperties.TEST_STRING_NO_DEFAULT));
465+
}
466+
467+
@Test
468+
public void getAsString_valueNotSet_list() {
469+
assertEquals("",helper.getAsString(KnownProperties.TEST_MIGRATE_TYPE_LIST));
470+
}
471471

472472
@Test
473473
public void getAsString_nullArgument() {

0 commit comments

Comments
 (0)