Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import org.junit.Test;
  2. import org.junit.runner.RunWith;
  3. import org.springframework.test.context.ContextConfiguration;
  4. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  5.  
  6. import javax.annotation.PostConstruct;
  7.  
  8. import static org.hamcrest.MatcherAssert.assertThat;
  9. import static org.hamcrest.Matchers.equalTo;
  10.  
  11. enum SomeSingletonService {
  12.     INSTANCE;
  13.  
  14.     public int num;
  15.  
  16.     private SomeSingletonService() {
  17.         num = 0;
  18.     }
  19. }
  20.  
  21. @RunWith(SpringJUnit4ClassRunner.class)
  22. @ContextConfiguration(locations = {"classpath:/context.xml"})
  23. public class Example {
  24.  
  25.     private SomeSingletonService s = SomeSingletonService.INSTANCE;
  26.  
  27.     @PostConstruct
  28.     public void init() {
  29.         ++s.num;
  30.     }
  31.  
  32.     @Test
  33.     public void t1() {
  34.         assertThat(s.num, equalTo(1));
  35.     }
  36.  
  37.     @Test
  38.     public void t2() {
  39.         assertThat(s.num, equalTo(2));
  40.     }
  41.  
  42.     @Test
  43.     public void t3() {
  44.         assertThat(s.num, equalTo(3));
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement