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; @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration public class CommisionServiceTest { @Autowired private CommisionService service; @Autowired private UserService userService; @Test public void shouldSaveCommision() { long beginState = this.service.getCommisionsAmmount(); this.service.save(new Commision()); assertTrue("Commision ammount should have changed", this.service.getCommisionsAmmount() > beginState); } @Test public void shouldGetUserCommisions() { 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() 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()); } }