Commision service tests
This commit is contained in:
parent
95fcfc4e06
commit
30222d6856
@ -32,4 +32,8 @@ public class CommisionService {
|
||||
public Optional<Commision> getNewestCommision(User user) {
|
||||
return Optional.of(this.repo.getNewestCommision(user.getId()).get(0));
|
||||
}
|
||||
|
||||
public long getCommisionsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -14,22 +18,43 @@ import org.junit.runner.RunWith;
|
||||
@ContextConfiguration
|
||||
public class CommisionServiceTest {
|
||||
|
||||
// @Autowired
|
||||
// private CommisionService service;
|
||||
@Autowired
|
||||
private CommisionService service;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
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
|
||||
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
|
||||
public void shouldGetNewestCommision() {
|
||||
assertTrue("Not implemented", false);
|
||||
public void shouldGetNewestCommision() throws NullPointerException, InterruptedException {
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user