### Question:
CassandraUtils { public static Object parseValue(final DataType type, final String value) { if (value == null) { return null; } switch (type.getName()) { case TEXT: case VARCHAR: case ASCII: return value; case INET: return type.parse("'" + value + "'"); case INT: case VARINT: case BIGINT: case FLOAT: case DOUBLE: case DECIMAL: case BOOLEAN: return type.parse(value.replaceAll("\\s+", "")); default: return type.parse(value); } } private  CassandraUtils(); static void executeCqlScript(final Session session, final String script); static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table); static Object parseValue(final DataType type, final String value);  }### Answer:
@Test public void parseValueNull() { for (final DataType dataType : DataType.allPrimitiveTypes()) { assertThat(CassandraUtils.parseValue(dataType, null)).isNull(); } }
@Test public void parseValueText() { for (final DataType dataType : textualTypes) { assertThat(CassandraUtils.parseValue(dataType, "unquoted_text")) .isEqualTo("unquoted_text"); assertThat(CassandraUtils.parseValue(dataType, "'quoted_text'")) .isEqualTo("'quoted_text'"); assertThat(CassandraUtils.parseValue(dataType, "'unescaped_'quoted_text'")) .isEqualTo("'unescaped_'quoted_text'"); } }
@Test public void parseInet() throws UnknownHostException { assertThat(CassandraUtils.parseValue(DataType.inet(), "127.0.0.1")) .isEqualTo(InetAddress.getByName("127.0.0.1")); }
@Test public void parseSpacedInt() throws UnknownHostException { assertThat(CassandraUtils.parseValue(DataType.cint(), " 1 2 ")) .isEqualTo(12); }
@Test public void parseQuotedInetFails() throws UnknownHostException { thrown.expect(InvalidTypeException.class); thrown.expectMessage("Cannot parse inet value"); CassandraUtils.parseValue(DataType.inet(), "'127.0.0.1'"); }
@Test public void parseBlob() { final ByteBuffer buffer = ByteBuffer.allocate(2); buffer.put(new byte[] { (byte) 0xF1, 0x56 }); buffer.flip(); assertThat(CassandraUtils.parseValue(DataType.blob(), "0xF156")) .isEqualTo(buffer); }