Skip to content

Commit 091bdd6

Browse files
authored
Update README.md
1 parent 3430a8e commit 091bdd6

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

README.md

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ A full-working demo of the examples below [is available here](https://github.com
1717

1818
You just have to add the @AssertHibernateSQLCount annotation to your test and it will verify the SQL statements (SELECT, UPDATE, INSERT, DELETE) count at the end of the test :
1919

20-
21-
@Test
22-
@Transactional
23-
@AssertHibernateSQLCount(inserts = 6)
24-
void create_two_blog_posts() {
25-
BlogPost post_1 = new BlogPost("Blog post 1");
26-
post_1.addComment(new PostComment("Good article"));
27-
post_1.addComment(new PostComment("Very interesting"));
28-
blogPostRepository.save(post_1);
29-
30-
BlogPost post_2 = new BlogPost("Blog post 2");
31-
post_2.addComment(new PostComment("Nice"));
32-
post_2.addComment(new PostComment("So cool, thanks"));
33-
blogPostRepository.save(post_2);
34-
}
35-
20+
```java
21+
@Test
22+
@Transactional
23+
@AssertHibernateSQLCount(inserts = 6)
24+
void create_two_blog_posts() {
25+
BlogPost post_1 = new BlogPost("Blog post 1");
26+
post_1.addComment(new PostComment("Good article"));
27+
post_1.addComment(new PostComment("Very interesting"));
28+
blogPostRepository.save(post_1);
29+
30+
BlogPost post_2 = new BlogPost("Blog post 2");
31+
post_2.addComment(new PostComment("Nice"));
32+
post_2.addComment(new PostComment("So cool, thanks"));
33+
blogPostRepository.save(post_2);
34+
}
35+
```
3636
If the actual count is different, an exception is thrown with the executed statements:
37-
37+
```
3838
com.mickaelb.assertions.HibernateAssertCountException:
3939
Expected 5 INSERT but got 6:
4040
=> '/* insert com.lemick.demo.entity.BlogPost */ insert into blog_post (id, title) values (default, ?)'
@@ -43,11 +43,11 @@ If the actual count is different, an exception is thrown with the executed state
4343
=> '/* insert com.lemick.demo.entity.BlogPost */ insert into blog_post (id, title) values (default, ?)'
4444
=> '/* insert com.lemick.demo.entity.PostComment */ insert into post_comment (id, blog_post_id, content) values (default, ?, ?)'
4545
=> '/* insert com.lemick.demo.entity.PostComment */ insert into post_comment (id, blog_post_id, content) values (default, ?, ?)'
46-
46+
```
4747
### Assert L2C statistics
4848

4949
It supports assertions on Hibernate level two cache statistics, useful for checking that your entities are cached correctly and that they will stay forever:
50-
50+
```java
5151
@Test
5252
@AssertHibernateL2CCount(misses = 1, puts = 1, hits = 1)
5353
void create_one_post_and_read_it() {
@@ -64,16 +64,16 @@ It supports assertions on Hibernate level two cache statistics, useful for check
6464
blogPostRepository.findById(1L); // 1 HIT
6565
});
6666
}
67-
67+
```
6868
## How to integrate
6969
1. Import the dependency
70-
71-
<dependency>
72-
<groupId>com.mickaelb</groupId>
73-
<artifactId>hibernate-query-asserts</artifactId>
74-
<version>2.0.0</version>
75-
</dependency>
76-
70+
```xml
71+
<dependency>
72+
<groupId>com.mickaelb</groupId>
73+
<artifactId>hibernate-query-asserts</artifactId>
74+
<version>2.0.0</version>
75+
</dependency>
76+
```
7777
2. Register the integration with Hibernate, you just need to add this key in your configuration (here for yml):
7878

7979
spring:
@@ -84,17 +84,18 @@ It supports assertions on Hibernate level two cache statistics, useful for check
8484
3. Register the Spring TestListener that will launch the SQL inspection if the annotation is present:
8585

8686
* By adding the listener on each of your integration test:
87+
```java
88+
@SpringBootTest
89+
@TestExecutionListeners(
90+
listeners = HibernateAssertTestListener.class,
91+
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
92+
)
93+
class MySpringIntegrationTest {
94+
...
95+
}
96+
```
8797

88-
@SpringBootTest
89-
@TestExecutionListeners(
90-
listeners = HibernateAssertTestListener.class,
91-
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
92-
)
93-
class MySpringIntegrationTest {
94-
...
95-
}
96-
9798
* **OR** by adding a **META-INF/spring.factories** file that contains the definition, that will register the listener for all your tests:
98-
99-
org.springframework.test.context.TestExecutionListener=com.mickaelb.integration.spring.HibernateAssertTestListener
100-
99+
```
100+
org.springframework.test.context.TestExecutionListener=com.mickaelb.integration.spring.HibernateAssertTestListener
101+
```

0 commit comments

Comments
 (0)