|
30 | 30 | import com.sandwich.koan.ui.SuitePresenter; |
31 | 31 |
|
32 | 32 | /** |
33 | | - * Anything that absoutely has to happen before bundling client jar - to be sure: |
34 | | - * - all koans fail by default |
35 | | - * - necessary aspects of app presentation are preserved |
36 | | - * - progression through koans (the sequence of koans) is consistent |
| 33 | + * Anything that absoutely has to happen before bundling client jar - to be |
| 34 | + * sure: - all koans fail by default - necessary aspects of app presentation are |
| 35 | + * preserved - progression through koans (the sequence of koans) is consistent |
37 | 36 | */ |
38 | 37 | public class AppReadinessForDeploymentTest extends CommandLineTestCase { |
39 | | - |
| 38 | + |
40 | 39 | @Test |
41 | | - public void testMainMethodWithClassNameArg_qualifiedWithPkgName() throws Throwable { |
| 40 | + public void testMainMethodWithClassNameArg_qualifiedWithPkgName() |
| 41 | + throws Throwable { |
42 | 42 | stubAllKoans(Arrays.asList(new OnePassingKoan())); |
43 | 43 | new KoanSuiteRunner().run(); |
44 | | - assertSystemOutContains(KoanConstants.PASSING_SUITES+" "+OnePassingKoan.class.getSimpleName()); |
| 44 | + assertSystemOutContains(KoanConstants.PASSING_SUITES + " " |
| 45 | + + OnePassingKoan.class.getSimpleName()); |
45 | 46 | } |
46 | 47 |
|
47 | 48 | @Test |
48 | | - public void testMainMethodWithClassNameArg_classSimpleName() throws Throwable { |
| 49 | + public void testMainMethodWithClassNameArg_classSimpleName() |
| 50 | + throws Throwable { |
49 | 51 | stubAllKoans(Arrays.asList(new OnePassingKoan())); |
50 | 52 | new KoanSuiteRunner().run(); |
51 | | - assertSystemOutContains(KoanConstants.PASSING_SUITES+" "+OnePassingKoan.class.getSimpleName()); |
| 53 | + assertSystemOutContains(KoanConstants.PASSING_SUITES + " " |
| 54 | + + OnePassingKoan.class.getSimpleName()); |
52 | 55 | } |
53 | | - |
| 56 | + |
54 | 57 | @Test |
55 | | - public void testMainMethodWithClassNameArg_classNameAndMethod() throws Throwable { |
56 | | - String failingKoanMethodName = TwoFailingKoans.class.getDeclaredMethod("koanTwo").getName(); |
| 58 | + public void testMainMethodWithClassNameArg_classNameAndMethod() |
| 59 | + throws Throwable { |
| 60 | + String failingKoanMethodName = TwoFailingKoans.class.getDeclaredMethod( |
| 61 | + "koanTwo").getName(); |
57 | 62 | stubAllKoans(Arrays.asList(new TwoFailingKoans())); |
58 | 63 | new KoanSuiteRunner().run(); |
59 | 64 | assertSystemOutContains(failingKoanMethodName); |
60 | | - assertSystemOutDoesntContain(OneFailingKoan.class.getDeclaredMethods()[0].getName()); |
| 65 | + assertSystemOutDoesntContain(OneFailingKoan.class.getDeclaredMethods()[0] |
| 66 | + .getName()); |
61 | 67 | } |
62 | | - |
| 68 | + |
63 | 69 | public static class TwoFailingKoans extends OneFailingKoan { |
64 | 70 | @Koan |
65 | | - public void koanTwo(){assertEquals(true, false);} |
| 71 | + public void koanTwo() { |
| 72 | + assertEquals(true, false); |
| 73 | + } |
66 | 74 | } |
67 | | - |
| 75 | + |
68 | 76 | @Test |
69 | 77 | public void testGetKoans() throws Exception { |
70 | 78 | stubAllKoans(Arrays.asList(new OnePassingKoan())); |
71 | | - Map<Object, List<KoanMethod>> koans = PathToEnlightenment.getPathToEnlightment() |
72 | | - .iterator().next().getValue(); |
| 79 | + Map<Object, List<KoanMethod>> koans = PathToEnlightenment |
| 80 | + .getPathToEnlightment().iterator().next().getValue(); |
73 | 81 | assertEquals(1, koans.size()); |
74 | | - Entry<Object, List<KoanMethod>> entry = koans.entrySet().iterator().next(); |
| 82 | + Entry<Object, List<KoanMethod>> entry = koans.entrySet().iterator() |
| 83 | + .next(); |
75 | 84 | assertEquals(OnePassingKoan.class, entry.getKey().getClass()); |
76 | | - assertEquals(OnePassingKoan.class.getDeclaredMethod("koan"), entry.getValue().get(0).getMethod()); |
| 85 | + assertEquals(OnePassingKoan.class.getDeclaredMethod("koan"), entry |
| 86 | + .getValue().get(0).getMethod()); |
77 | 87 | } |
78 | | - |
79 | | - @Test /** Ensures that koans are ready for packaging & distribution */ |
| 88 | + |
| 89 | + @Test |
| 90 | + /** Ensures that koans are ready for packaging & distribution */ |
80 | 91 | public void testKoanSuiteRunner_firstKoanFail() throws Exception { |
81 | | - final KoanSuiteResult[] result = new KoanSuiteResult[]{null}; |
82 | | - final SuitePresenter presenter = new SuitePresenter(){ |
| 92 | + final KoanSuiteResult[] result = new KoanSuiteResult[] { null }; |
| 93 | + final SuitePresenter presenter = new SuitePresenter() { |
83 | 94 | public void displayResult(KoanSuiteResult actualAppResult) { |
84 | | - // don't display, capture them so we can analyze and ensure first failure is reported |
| 95 | + // don't display, capture them so we can analyze and ensure |
| 96 | + // first failure is reported |
85 | 97 | result[0] = actualAppResult; |
86 | 98 | } |
87 | 99 | }; |
88 | | - new RunKoans(presenter, PathToEnlightenment.getPathToEnlightment()).run(null); |
89 | | - assertEquals(result[0].getFailingCase(), PathToEnlightenment.getPathToEnlightment() |
90 | | - .iterator().next().getValue().entrySet().iterator().next().getKey().getClass()); |
| 100 | + new RunKoans(presenter, PathToEnlightenment.getPathToEnlightment()) |
| 101 | + .run(null); |
| 102 | + assertEquals(result[0].getFailingCase(), PathToEnlightenment |
| 103 | + .getPathToEnlightment().iterator().next().getValue().entrySet() |
| 104 | + .iterator().next().getKey().getClass()); |
91 | 105 | } |
92 | | - |
93 | | - @Test /** Ensures that koans are ready for packaging & distribution */ |
| 106 | + |
| 107 | + @Test |
| 108 | + /** Ensures that koans are ready for packaging & distribution */ |
94 | 109 | public void testKoanSuiteRunner_allKoansFail() throws Exception { |
95 | | - final KoanSuiteResult[] result = new KoanSuiteResult[]{null}; |
96 | | - final SuitePresenter presenter = new SuitePresenter(){ |
| 110 | + final KoanSuiteResult[] result = new KoanSuiteResult[] { null }; |
| 111 | + final SuitePresenter presenter = new SuitePresenter() { |
97 | 112 | public void displayResult(KoanSuiteResult actualAppResult) { |
98 | | - // don't display, capture them so we can analyze and ensure first failure is reported |
| 113 | + // don't display, capture them so we can analyze and ensure |
| 114 | + // first failure is reported |
99 | 115 | result[0] = actualAppResult; |
100 | 116 | } |
101 | 117 | }; |
102 | | - new RunKoans(presenter, PathToEnlightenment.getPathToEnlightment()).run(null); |
| 118 | + new RunKoans(presenter, PathToEnlightenment.getPathToEnlightment()) |
| 119 | + .run(null); |
103 | 120 | String message = "Not all koans need solving! Each should ship in a failing state."; |
104 | 121 | assertEquals(message, 0, result[0].getNumberPassing()); |
105 | 122 | // make sure test was actually useful (ie something actually failed) |
106 | 123 | assertNotNull(result[0].getFailingCase()); |
107 | 124 | } |
108 | | - |
109 | | - @Test |
| 125 | + |
| 126 | + @Test |
110 | 127 | public void testLineExceptionIsThrownAtIsHintedAt() throws Exception { |
111 | 128 | stubAllKoans(Arrays.asList(new BlowUpOnLineTen())); |
112 | 129 | new KoanSuiteRunner(new CommandLineArgumentBuilder()).run(); |
113 | 130 | assertSystemOutContains("Line 10"); |
114 | 131 | assertSystemOutDoesntContain("Line 11"); |
115 | 132 | } |
116 | | - |
117 | | - @Test |
118 | | - public void testLineExceptionIsThrownAtIsHintedAtEvenIfThrownFromSuperClass() throws Exception { |
| 133 | + |
| 134 | + @Test |
| 135 | + public void testLineExceptionIsThrownAtIsHintedAtEvenIfThrownFromSuperClass() |
| 136 | + throws Exception { |
119 | 137 | stubAllKoans(Arrays.asList(new BlowUpOnLineEleven())); |
120 | 138 | new KoanSuiteRunner(new CommandLineArgumentBuilder()).run(); |
121 | 139 | assertSystemOutContains("Line 11"); |
122 | 140 | assertSystemOutDoesntContain("Line 10"); |
123 | 141 | } |
124 | | - |
| 142 | + |
125 | 143 | @Test |
126 | 144 | public void testWarningFromPlacingExpecationOnWrongSide() throws Throwable { |
127 | 145 | final String[] message = new String[1]; |
128 | 146 | stubAllKoans(Arrays.asList(new WrongExpectationOrderKoan())); |
129 | | - Logger.getLogger(KoanSuiteRunner.class.getSimpleName()).addHandler(new Handler(){ |
130 | | - @Override public void close() throws SecurityException {} |
131 | | - @Override public void flush() {} |
132 | | - @Override public void publish(LogRecord arg0) { |
133 | | - message[0] = arg0.getMessage(); |
134 | | - } |
135 | | - }); |
| 147 | + Logger.getLogger(KoanSuiteRunner.class.getSimpleName()).addHandler( |
| 148 | + new Handler() { |
| 149 | + @Override |
| 150 | + public void close() throws SecurityException { |
| 151 | + } |
| 152 | + |
| 153 | + @Override |
| 154 | + public void flush() { |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public void publish(LogRecord arg0) { |
| 159 | + message[0] = arg0.getMessage(); |
| 160 | + } |
| 161 | + }); |
136 | 162 | new KoanSuiteRunner(new CommandLineArgumentBuilder()).run(); |
137 | | - assertEquals(new StringBuilder( |
138 | | - WrongExpectationOrderKoan.class.getSimpleName()).append( |
139 | | - ".expectationOnLeft ").append( |
140 | | - EXPECTATION_LEFT_ARG).toString() |
141 | | - , message[0]); |
| 163 | + assertEquals( |
| 164 | + new StringBuilder( |
| 165 | + WrongExpectationOrderKoan.class.getSimpleName()) |
| 166 | + .append(".expectationOnLeft ") |
| 167 | + .append(EXPECTATION_LEFT_ARG).toString(), message[0]); |
142 | 168 | } |
143 | | - |
| 169 | + |
144 | 170 | @Test |
145 | | - public void testNoWarningFromPlacingExpecationOnRightSide() throws Throwable { |
| 171 | + public void testNoWarningFromPlacingExpecationOnRightSide() |
| 172 | + throws Throwable { |
146 | 173 | stubAllKoans(Arrays.asList(new OnePassingKoan())); |
147 | | - Logger.getLogger(KoanSuiteRunner.class.getSimpleName()).addHandler(new Handler(){ |
148 | | - @Override public void close() throws SecurityException {} |
149 | | - @Override public void flush() {} |
150 | | - @Override public void publish(LogRecord arg0) { |
151 | | - fail("No logging necessary when koan passes, otherwise - logging is new, adjust accordingly."); |
152 | | - } |
153 | | - }); |
| 174 | + Logger.getLogger(KoanSuiteRunner.class.getSimpleName()).addHandler( |
| 175 | + new Handler() { |
| 176 | + @Override |
| 177 | + public void close() throws SecurityException { |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public void flush() { |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public void publish(LogRecord arg0) { |
| 186 | + fail("No logging necessary when koan passes, otherwise - logging is new, adjust accordingly."); |
| 187 | + } |
| 188 | + }); |
154 | 189 | new KoanSuiteRunner().run(); |
155 | 190 | } |
156 | | - |
| 191 | + |
157 | 192 | public static class WrongExpectationOrderKoan { |
158 | | - @Koan |
159 | | - public void expectationOnLeft(){ |
| 193 | + @Koan |
| 194 | + public void expectationOnLeft() { |
160 | 195 | com.sandwich.util.Assert.assertEquals(__, false); |
161 | 196 | } |
162 | 197 | } |
|
0 commit comments