Guest User

Untitled

a guest
May 8th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.09 KB | None | 0 0
  1. package soundsystem;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Component;
  4. @Component
  5. public class CDPlayer implements MediaPlayer {
  6.     private CompactDisc cd;
  7.  
  8.     @Autowired
  9.     public CDPlayer(CompactDisc cd) {
  10.         this.cd = cd;
  11.     }
  12.  
  13.     @Override
  14.     public void play() {
  15.         cd.play();
  16.     }
  17. }
  18. --------------------------------------------------------------------------------------------------------------------------
  19. package soundsystem;
  20. import org.springframework.context.annotation.ComponentScan;
  21. import org.springframework.context.annotation.Configuration;
  22.  
  23. @Configuration
  24. //@ComponentScan
  25. public class CDPlayerConfig {
  26. }
  27.  
  28. --------------------------------------------------------------------------------------------------------------------------
  29. package soundsystem;
  30. public interface CompactDisc {
  31.     void play();
  32. }
  33. --------------------------------------------------------------------------------------------------------------------------
  34. package soundsystem;
  35. public interface MediaPlayer {
  36.     void play();
  37. }
  38. --------------------------------------------------------------------------------------------------------------------------
  39. package soundsystem;
  40. import org.springframework.stereotype.Component;
  41. @Component
  42. public class SgtPeppers implements CompactDisc {
  43.     private String title = "Sgt. Pepper's Lonely Hearts Club Band";
  44.     private String artist = "The Beatles";
  45.     @Override
  46.     public void play() {
  47.         System.out.println("Odtwarzam utwór " + title + " artysty " + artist);
  48.     }
  49. }
  50.  
  51. --------------------------------------------------------------------------------------------------------------------------
  52. <?xml version="1.0" encoding="UTF-8"?>
  53. <beans xmlns="http://www.springframework.org/schema/beans"
  54.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  55.        xmlns:context="http://www.springframework.org/schema/context"
  56.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  57.   <!--<context:annotation-config />-->
  58.   <context:component-scan base-package="soundsystem"/>
  59.  
  60. </beans>
  61. --------------------------------------------------------------------------------------------------------------------------
  62. package soundsystem;
  63. import org.junit.Test;
  64. import org.junit.runner.RunWith;
  65. import org.springframework.beans.factory.annotation.Autowired;
  66. import org.springframework.test.context.ContextConfiguration;
  67. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  68. import soundsystem.CDPlayerConfig;
  69. import soundsystem.CompactDisc;
  70. import static org.junit.Assert.*;
  71. @RunWith(SpringJUnit4ClassRunner.class)
  72. @ContextConfiguration(classes = CDPlayerConfig.class)//konfiguracja kontekstu ma zostac wczytana z tej klasy
  73. public class CDPlayerTest {
  74.     @Autowired
  75.     private CompactDisc cd;
  76.  
  77.     @Test
  78.     public void cdShouldBeNull() {
  79.         assertNotNull(cd);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment