MaskStrings implements ColumnMapper { @Override public ValueConverter create(Column column) { switch (column.jdbcType()) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: case Types.NCLOB: case Types.DATALINK: return converterFromColumn.apply(column); default: return ValueConverter.passthrough(); } } MaskStrings(String maskValue);  MaskStrings(byte[] salt, String hashAlgorithm); @Override ValueConverter create(Column column); @Override void alterFieldSchema(Column column, SchemaBuilder schemaBuilder);  }
@Test public void shouldMaskStringsWithAsterisks() { String maskValue = "*****"; converter = new MaskStrings(maskValue).create(column); assertThat(converter.convert("1234567890").toString()).isEqualTo(maskValue); assertThat(converter.convert("123456").toString()).isEqualTo(maskValue); assertThat(converter.convert("12345").toString()).isEqualTo(maskValue); assertThat(converter.convert("1234").toString()).isEqualTo(maskValue); assertThat(converter.convert("123").toString()).isEqualTo(maskValue); assertThat(converter.convert("12").toString()).isEqualTo(maskValue); assertThat(converter.convert("1").toString()).isEqualTo(maskValue); assertThat(converter.convert(null).toString()).isEqualTo(maskValue); }
@Test public void shouldTransformSameInputsToSameResultsForCharsetType() { converter = new MaskStrings("salt".getBytes(), "SHA-256").create(column); assertThat(converter.convert("hello")).isEqualTo("af5843a0f0e728ab0332c8888b6e1190bfb79e584f0d40538de8f10df6ef29c6"); assertThat(converter.convert("hello")).isEqualTo("af5843a0f0e728ab0332c8888b6e1190bfb79e584f0d40538de8f10df6ef29c6"); assertThat(converter.convert("world")).isEqualTo("4588e1f2dcdc7fefc1515d3acd5acb9033478eace68286f383c337b9ff4464a3"); assertThat(converter.convert("world")).isEqualTo("4588e1f2dcdc7fefc1515d3acd5acb9033478eace68286f383c337b9ff4464a3"); }