Skip to content

Commit

Permalink
Dirties Context fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Philip authored and Jan Philip committed Oct 8, 2021
1 parent 0a9e3f5 commit 1fd4a61
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;

import java.util.*;
import java.util.stream.StreamSupport;
Expand All @@ -33,52 +34,61 @@ void contextLoads() {
}

@Test
@DirtiesContext
void testDataCreated() {
assertEquals(16,StreamSupport.stream(this.repository.findAll().spliterator(), false).count());
}

@Test
@DirtiesContext
void deleteBookTest() {
service.deleteBooks(List.of(new Book("Nina & Tom","Tom Kummer","Blumenbar","978-3-351-05035-1")));
}

@Test
@DirtiesContext
void deleteBookAndSearchTest() {
service.deleteBooks(List.of(new Book("Es existiert","Johannes Huber","Goldmann","978-3-442-22232-2")));
assertEquals(Optional.empty(), service.findBook("978-3-442-22232-2"));
}

@Test
@DirtiesContext
void createBookTest() {
service.createBook(new Book("Star Wars: Das Licht der Jedi", "Charles Soule","Blanvalent","978-0-593-15771-8"));
System.out.println(service.findBook("978-0-593-15771-8").get().getTitle());
}

@Test
@DirtiesContext
void findBookTest() {
assertTrue(service.findBook("978-3-442-22232-2").isPresent());
}

@Disabled @Test
@DirtiesContext
void createFalseBookTest() {
service.createBook(new Book("Star Wars: Das Licht der Jedi", "Charles Soule","Blanvalent","978-0-593-15771-9"));
System.out.println(service.findBook("978-0-593-15771-9").get().getTitle());
}

@Test
@DirtiesContext
void createAndDeleteTest() {
Book b = new Book("SuperSache", "Markus Büning", "Panini", "978-3-442-12345-2");
service.createBook(b);
service.deleteBooks(List.of(b));
}

@Test
@DirtiesContext
void findAndDeleteTest() {
Optional<Book> b = service.findBook("978-3-499-63405-5");
service.deleteBooks(List.of(b.get()));
}

@Disabled @Test
@DirtiesContext
void createExistingBook() {
//assertThrows(BookAlreadyExistsException.class, service.createBook(service.findBook("978-3-499-63405-5").get()));
}
Expand Down

0 comments on commit 1fd4a61

Please sign in to comment.