-
Notifications
You must be signed in to change notification settings - Fork 0
/
facade_test.go
56 lines (47 loc) · 1.71 KB
/
facade_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package facade_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/marksartdev/go-patterns/pkg/structural/facade"
)
func TestHomeTheaterFacade(t *testing.T) {
homeTheater := facade.NewHomeTheater()
lights := facade.TheaterLights{}
screen := facade.Screen{}
popper := facade.PopcornPopper{}
amp := &facade.Amplifier{}
dvd := &facade.DvdPlayer{}
projector := &facade.Projector{}
t.Run("WatchMovie", func(t *testing.T) {
expected := "Get ready to watch a movie ...\n\n"
expected += fmt.Sprintln(popper.On())
expected += fmt.Sprintf("%s\n\n", popper.Pop())
expected += fmt.Sprintf("%s\n\n", lights.Dim(10))
expected += fmt.Sprintf("%s\n\n", screen.Down())
expected += fmt.Sprintln(projector.On())
expected += fmt.Sprintln(projector.SetInput(dvd))
expected += fmt.Sprintf("%s\n\n", projector.WideScreenMode())
expected += fmt.Sprintln(amp.On())
expected += fmt.Sprintln(amp.SetDvd(dvd))
expected += fmt.Sprintln(amp.SetSurroundSound())
expected += fmt.Sprintf("%s\n\n", amp.SetVolume(5))
expected += fmt.Sprintln(dvd.On())
expected += dvd.Play("The Big Bang Theory")
actual := homeTheater.WatchMovie("The Big Bang Theory")
assert.Equal(t, expected, actual)
})
t.Run("EndMovie", func(t *testing.T) {
expected := "Shutting movie theater down ...\n\n"
expected += fmt.Sprintf("%s\n\n", popper.Off())
expected += fmt.Sprintf("%s\n\n", lights.On())
expected += fmt.Sprintf("%s\n\n", screen.Up())
expected += fmt.Sprintf("%s\n\n", projector.Off())
expected += fmt.Sprintf("%s\n\n", amp.Off())
expected += fmt.Sprintln(dvd.Stop())
expected += fmt.Sprintln(dvd.Eject())
expected += dvd.Off()
actual := homeTheater.EndMovie()
assert.Equal(t, expected, actual)
})
}