package app;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import app.AppConfig;
import app.Event;
import app.EventRepository;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {AppConfig.class, App.class})
public class EventTest {

	@Autowired
	EventRepository repository;

	@Test
	public void contextLoads() {
	}

	@Test
	public void save() {

		Event expected = new Event("ERROR");

		repository.save(expected);
		Event actual = repository.findAll().get(0);
		
		assertThat(actual).isEqualTo(expected);
	}
	
	@Test
	public void valueOf() {
		
		Event expected = new Event();
		String eventStr = expected.toString();
		Event actual = Event.valueOf(eventStr);
		
		assertThat(actual).isEqualTo(expected);
		
		System.out.println("actual: " + actual);
	}
	
	@Test
	public void findByType() {
		List<Event> events = new ArrayList<>();
		
		for(int i=0; i<10; i++) {
			events.add(new Event("INFO"));
		}
		
		for(int i=0; i<5; i++) {
			events.add(new Event("ERROR"));
		}
		
		repository.save(events);
		repository.flush();
		
		List<Event> infos = repository.findByType("INFO");
		List<Event> errors = repository.findByType("ERROR");
		
		assertThat(10).isEqualTo(infos.size());
		assertThat(5).isEqualTo(errors.size());
	}
}

@@ -114,24 +114,49 @@
 util.List;%0A%0A
+import org.junit.Before;%0A
 import org.j
@@ -162,24 +162,24 @@
 junit.Test;%0A
-
 import org.j
@@ -510,16 +510,17 @@
 sses = %7B
+ 
 AppConfi
@@ -537,16 +537,17 @@
 pp.class
+ 
 %7D)%0Apubli
@@ -609,16 +609,107 @@
 itory;%0A%0A
+%09@Before%0A%09public void setup() %7B%0A%09%09repository.deleteAllInBatch();%0A%09%09repository.flush();%0A%09%7D%0A%0A
 %09@Test%0A%09
@@ -886,19 +886,17 @@
 get(0);%0A
-%09%09
 %0A
+
 %09%09assert
@@ -928,26 +928,25 @@
 pected);%0A%09%7D%0A
-%09
 %0A
+
 %09@Test%0A%09publ
@@ -965,19 +965,17 @@
 eOf() %7B%0A
-%09%09
 %0A
+
 %09%09Event 
@@ -1081,19 +1081,17 @@
 ntStr);%0A
-%09%09
 %0A
+
 %09%09assert
@@ -1124,19 +1124,17 @@
 ected);%0A
-%09%09
 %0A
+
 %09%09System
@@ -1171,18 +1171,17 @@
 al);%0A%09%7D%0A
-%09
 %0A
+
 %09@Test%0A%09
@@ -1249,36 +1249,39 @@
 st%3C%3E();%0A
-%09%09
 %0A%09%09for
+ 
 (int i
-=
+ = 
 0; i
-%3C
+ %3C 
 10; i++)
@@ -1325,28 +1325,31 @@
 %09%09%7D%0A
-%09%09
 %0A%09%09for
+ 
 (int i
-=
+ = 
 0; i
-%3C
+ %3C 
 5; i
@@ -1393,19 +1393,17 @@
 ));%0A%09%09%7D%0A
-%09%09
 %0A
+
 %09%09reposi
@@ -1443,19 +1443,17 @@
 lush();%0A
-%09%09
 %0A
+
 %09%09List%3CE
@@ -1552,18 +1552,16 @@
 RROR%22);%0A
-%09%09
 %0A%09%09asser

Update EventTest.java