Commision service tests

This commit is contained in:
Filip Izydorczyk 2020-10-02 17:55:42 +02:00
parent 95fcfc4e06
commit 30222d6856
2 changed files with 35 additions and 6 deletions

View File

@ -32,4 +32,8 @@ public class CommisionService {
public Optional<Commision> getNewestCommision(User user) { public Optional<Commision> getNewestCommision(User user) {
return Optional.of(this.repo.getNewestCommision(user.getId()).get(0)); return Optional.of(this.repo.getNewestCommision(user.getId()).get(0));
} }
public long getCommisionsAmmount() {
return this.repo.count();
}
} }

View File

@ -1,11 +1,15 @@
package com.plannaplan.services; package com.plannaplan.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import com.plannaplan.entities.Commision;
import com.plannaplan.entities.User;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -14,22 +18,43 @@ import org.junit.runner.RunWith;
@ContextConfiguration @ContextConfiguration
public class CommisionServiceTest { public class CommisionServiceTest {
// @Autowired @Autowired
// private CommisionService service; private CommisionService service;
@Autowired
private UserService userService;
@Test @Test
public void shouldSaveCommision() { public void shouldSaveCommision() {
assertTrue("Not implemented", false); long beginState = this.service.getCommisionsAmmount();
this.service.save(new Commision());
assertTrue("Commision ammount should have changed", this.service.getCommisionsAmmount() > beginState);
} }
@Test @Test
public void shouldGetUserCommisions() { public void shouldGetUserCommisions() {
assertTrue("Not implemented", false); User usr = new User();
this.userService.save(usr);
this.service.save(new Commision(usr));
assertTrue("User should have one commision", this.service.getUsersCommisions(usr).size() == 1);
} }
@Test @Test
public void shouldGetNewestCommision() { public void shouldGetNewestCommision() throws NullPointerException, InterruptedException {
assertTrue("Not implemented", false); User usr = new User();
this.userService.save(usr);
this.service.save(new Commision(usr));
Thread.sleep(2000);
final Commision newestCommision = new Commision(usr);
this.service.save(newestCommision);
final Commision result = this.service.getNewestCommision(usr)
.orElseThrow(() -> new NullPointerException("There was no commision"));
assertTrue("Wrong commision was returned", result.getId() == newestCommision.getId());
} }
} }