### Question:
CassandraUtils { public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; } 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(expected = NullPointerException.class) public void getTableMetadataOnNullSession() { CassandraUtils.getTableMetadata(null, "keyspace", "table"); }
@Test(expected = NullPointerException.class) public void getTableMetadataOnNullKeyspace() { CassandraUtils.getTableMetadata(mock(Session.class), null, "table"); }
@Test(expected = NullPointerException.class) public void getTableMetadataOnNullTable() { CassandraUtils.getTableMetadata(mock(Session.class), "keyspace", null); }
@Test public void getTableMetadataOnUnexistentKeyspace() { final Session session = mock(Session.class); final Cluster cluster = mock(Cluster.class); final Metadata metadata = mock(Metadata.class); when(session.getCluster()).thenReturn(cluster); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getKeyspace("keyspace")).thenReturn(null); thrown.expect(IllegalStateException.class); thrown.expectMessage("Keyspace keyspace does not exist"); CassandraUtils.getTableMetadata(session, "keyspace", "table"); }
@Test public void getTableMetadataOnUnexistentTable() { final Session session = mock(Session.class); final Cluster cluster = mock(Cluster.class); final Metadata metadata = mock(Metadata.class); final KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class); when(session.getCluster()).thenReturn(cluster); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getKeyspace("keyspace")).thenReturn(keyspaceMetadata); when(keyspaceMetadata.getTable("table")).thenReturn(null); thrown.expect(IllegalStateException.class); thrown.expectMessage("Table keyspace.table does not exist"); CassandraUtils.getTableMetadata(session, "keyspace", "table"); }
@Test public void getTableMetadata() { final Session session = mock(Session.class); final Cluster cluster = mock(Cluster.class); final Metadata metadata = mock(Metadata.class); final KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class); final TableMetadata tableMetadata = mock(TableMetadata.class); when(session.getCluster()).thenReturn(cluster); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getKeyspace("keyspace")).thenReturn(keyspaceMetadata); when(keyspaceMetadata.getTable("table")).thenReturn(tableMetadata); assertThat(CassandraUtils.getTableMetadata(session, "keyspace", "table")).isNotNull(); }