Skip to content

Commit ccfb670

Browse files
authored
Add files via upload
1 parent a1c5131 commit ccfb670

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014-2016 Ilkka Seppälä
4+
* <p>
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
* <p>
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
* <p>
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.iluwatar.dependency.injection;
24+
25+
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
26+
import org.junit.After;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
30+
import static org.junit.Assert.assertEquals;
31+
32+
/**
33+
* Date: 28/04/17 - 7:40 AM
34+
*
35+
* @author Stanislav Kapinus
36+
*/
37+
38+
public class AdvancedSorceressTest {
39+
40+
private InMemoryAppender appender;
41+
42+
@Before
43+
public void setUp() {
44+
appender = new InMemoryAppender(Tobacco.class);
45+
}
46+
47+
@After
48+
public void tearDown() {
49+
appender.stop();
50+
}
51+
52+
/**
53+
* Test if the {@link AdvancedSorceress} smokes whatever instance of {@link Tobacco} is passed to her
54+
* through the setter's parameter
55+
*/
56+
@Test
57+
public void testSmokeEveryThing() throws Exception {
58+
59+
final Tobacco[] tobaccos = {
60+
new OldTobyTobacco(), new RivendellTobacco(), new SecondBreakfastTobacco()
61+
};
62+
63+
for (final Tobacco tobacco : tobaccos) {
64+
final AdvancedSorceress advancedSorceress = new AdvancedSorceress();
65+
advancedSorceress.setTobacco(tobacco);
66+
advancedSorceress.smoke();
67+
// Verify if the sorceress is smoking the correct tobacco ...
68+
assertEquals("AdvancedSorceress smoking " + tobacco.getClass().getSimpleName(), appender.getLastMessage());
69+
70+
}
71+
72+
// ... and nothing else is happening.
73+
assertEquals(tobaccos.length, appender.getLogSize());
74+
75+
}
76+
77+
}

0 commit comments

Comments
 (0)