Skip to content

Commit

Permalink
refacator: update code using lambda expression
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Nov 12, 2023
1 parent 99c24d0 commit 9e899c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ public static void clearDatabase(String index) {
try (var elasticsearch = INSTANCE.newElasticsearchClient()) {
var response = elasticsearch.client().indices().delete(DeleteIndexRequest.of(d ->
d.index(index)));
assertSoftly(softly -> {
softly.assertThat(response.acknowledged())
.isTrue();
});
assertSoftly(softly -> softly.assertThat(response.acknowledged())
.isTrue());
} catch (Exception e) {
if( !(e instanceof ElasticsearchException)) {
throw new RuntimeException(e);
Expand All @@ -76,10 +74,8 @@ public static void createDatabase(String index) {
try (var elasticsearch = INSTANCE.newElasticsearchClient()) {
CreateIndexResponse response = elasticsearch.client().indices().create(
CreateIndexRequest.of(b -> b.index(index)));
assertSoftly(softly -> {
softly.assertThat(response.acknowledged())
.isTrue();
});
assertSoftly(softly -> softly.assertThat(response.acknowledged())
.isTrue());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -88,10 +84,8 @@ public static void createDatabase(String index) {
public static void updateMapping(String index, Function<PutMappingRequest.Builder, ObjectBuilder<PutMappingRequest>> fn) {
try (var elasticsearch = INSTANCE.newElasticsearchClient()) {
PutMappingResponse response = elasticsearch.client().indices().putMapping(fn);
assertSoftly(softly -> {
softly.assertThat(response.acknowledged())
.isTrue();
});
assertSoftly(softly -> softly.assertThat(response.acknowledged())
.isTrue());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -111,10 +105,8 @@ public static void insertData(String index, Map<String, Object> map) {

IndexResponse response = elasticsearch.client().index(indexRequest);

assertSoftly(softly -> {
softly.assertThat(response.result().jsonValue())
.isEqualTo("created");
});
assertSoftly(softly -> softly.assertThat(response.result().jsonValue())
.isEqualTo("created"));
_id.ifPresent(id -> map.put("_id", id));
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,13 @@ void testSupportTermQuery() throws Exception {
.as("indexMappingRecordWithoutKeywordAttributes wasn't provided")
.isNotNull();

map.keySet().forEach(key -> {
softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithoutKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse();
});

Set.of("doc2.data1", "doc2.data2").forEach(key -> {
softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithoutKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse();
});
map.keySet().forEach(key -> softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithoutKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse());

Set.of("doc2.data1", "doc2.data2").forEach(key -> softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithoutKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse());

});

Expand All @@ -136,12 +132,9 @@ void testSupportTermQuery() throws Exception {

map.keySet().stream()
.filter(anObject -> !"@entity".equals(anObject))
.forEach(key -> {
softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse();

});
.forEach(key -> softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithKeywordAttributes, key))
.as("%s attribute should not support TermQuery".formatted(key))
.isFalse());


softly.assertThat(QueryConverter.supportTermQuery(indexMappingRecordWithKeywordAttributes, "@entity"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,14 @@ public void shouldFindByTitleLike() throws InterruptedException {
return !books.isEmpty();
});

assertSoftly(softly -> {
assertThat(booksWithEffective.get())
.as("returned book list with 'Effective' is not equals to the expected items ")
.containsAll(effectiveBooks);
});
assertSoftly(softly -> assertThat(booksWithEffective.get())
.as("returned book list with 'Effective' is not equals to the expected items ")
.containsAll(effectiveBooks));


assertSoftly(softly -> {
assertThat(booksWithJa.get())
.as("returned book list with 'Ja*' is not equals to the expected items ")
.containsAll(allBooks);
});
assertSoftly(softly -> assertThat(booksWithJa.get())
.as("returned book list with 'Ja*' is not equals to the expected items ")
.containsAll(allBooks));
}


Expand Down

0 comments on commit 9e899c8

Please sign in to comment.