MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected void createTable(TableMetadata tableMetadata, Connection<MongoClient> connection) throws ExecutionException { if (tableMetadata == null) { throw new MongoValidationException("the table metadata is required"); } if (tableMetadata.getName() == null) { throw new MongoValidationException("the table name is required"); } if (ShardUtils.isCollectionSharded(SelectorOptionsUtils.processOptions(tableMetadata.getOptions()))) { ShardUtils.shardCollection((MongoClient) connection.getNativeConnection(), tableMetadata); } } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler);  }
@Test public void createTableTest() throws UnsupportedException, ExecutionException { TableName tableName = new TableName(DB_NAME, TABLE_NAME); TableMetadata tableMetadata = mock(TableMetadata.class); when(tableMetadata.getName()).thenReturn(tableName); mongoMetadataEngine.createTable(tableMetadata, connection); verify(tableMetadata, times(1)).getName(); verify(tableMetadata, times(1)).getOptions(); }
@Test public void createTableWithoutNameTest() throws ExecutionException, UnsupportedException { TableMetadata tableMetadata = mock(TableMetadata.class); when(tableMetadata.getName()).thenReturn(null); try { mongoMetadataEngine.createTable(tableMetadata, connection); fail("the table name is necessary"); } catch (ExecutionException e) { } verify(tableMetadata, times(1)).getName(); }