@@ -11,7 +11,9 @@ assistance!
1111* [ Introduction] ( #introduction )
1212* [ Exercise Structure] ( #exercise-structure )
1313* [ Solving "Hello, World!"] ( #solving-hello-world )
14- * [ Submitting your first iteration] ( #submitting-your-first-iteration )
14+ * [ Step 1: Replace the ` UnsupportedOperationException ` ] ( #step-1-replace-the-unsupportedoperationexception )
15+ [ Step 2: Run the Tests] ( #step-2-run-the-tests )
16+ * [ Step 3: Submitting your first iteration] ( #step-3-submitting-your-first-iteration )
1517* [ Next Steps] ( #next-steps )
1618
1719# Introduction
@@ -39,99 +41,17 @@ in order to solve the current problem.
3941
4042# Solving "Hello, World!"
4143
42- Before proceeding any further, make sure you have completed the required setup
43- steps described by the links below:
44- * [ Installing Java and Gradle] ( https://exercism.org/docs/tracks/java/installation ) ;
45- * [ Running the Tests (in Java)] ( https://exercism.org/docs/tracks/java/tests ) .
46-
47-
48- ## Step 1: Run the tests against the starter solution
49-
50- Use Gradle to run the tests:
51-
52- ```
53- $ gradle test
54- ```
55-
56- This command does a lot and displays a bunch of stuff. Let's break it down...
57-
58- ```
59- :compileJava
60- :processResources UP-TO-DATE
61- :classes
62- ```
63-
64- Each line that begins with a colon (like ` :compileJava ` ) is Gradle telling
65- us that it's starting that task. The first three tasks are about compiling
66- the source code of our _ solution_ . This exercise contains starter files with
67- just enough code for the solution to compile without requiring modification.
68-
69- When a task is successful, it generally does not output anything. This is
70- why ` :compileJava ` and ` :classes ` do not produce any additional output.
71- ` :processResources ` reports that it had nothing to do.
72-
73- So far, so good...
74-
75- The next three tasks are about compiling source code of the _ tests_ .
76-
77- ```
78- :compileTestJava
79- :processTestResources UP-TO-DATE
80- :testClasses
81- ```
82-
83- ... with both sets of source code successfully compiled, Gradle turns to
84- running the task you asked it to: executing the tests against the solution.
85-
86- ```
87- :test
88- GreeterTest > testThatGreeterReturnsTheCorrectGreeting FAILED
89- java.lang.UnsupportedOperationException: Delete this statement and write your own implementation.
90- at getGreeting(Greeter.java:4)
91- at GreeterTest.testThatGreeterReturnsTheCorrectGreeting(GreeterTest.java:9)
92- 1 tests completed, 1 failed
93- :test FAILED
94- FAILURE: Build failed with an exception.
95- * What went wrong:
96- Execution failed for task ':test'.
97- > There were failing tests. See the report at: file:///home/<username>/hello-world/build/reports/tests/index.html
98- * Try:
99- Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
100- BUILD FAILED
101- Total time: 12.361 secs
102- ```
44+ You can use our online editor to solve your solution and run the tests, but
45+ if you want to solve the problem and run tests locally check these links below:
10346
104- Seeing the word "FAILED" might give you the impression you've done
105- something wrong. You haven't. This output is just a very verbose way of
106- telling us that the included test did not pass. This is expected - we haven't
107- written any code to help it pass yet!
108-
109- Let's focus in on the important bits:
110-
111- ```
112- GreeterTest > testThatGreeterReturnsTheCorrectGreeting FAILED
113- java.lang.UnsupportedOperationException: Delete this statement and write your own implementation.
114- ```
115-
116- ...is read: "Within the test class named ` GreeterTest ` , the test method
117- ` testThatGreeterReturnsTheCorrectGreeting ` did not pass because an
118- ` UnsupportedOperationException ` was thrown with the message `Delete this
119- statement and write your own implementation.`."
120-
121- The next line of the [ stack trace] ( https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors )
122- tells us where this ` UnsupportedOperationException ` was thrown:
123-
124- ```
125- at getGreeting(Greeter.java:4)
126- ```
47+ * [ Installing Java and Gradle] ( https://exercism.org/docs/tracks/java/installation ) ;
48+ * [ Working Locally] ( https://exercism.org/docs/using/solving-exercises/working-locally ) ;
49+ * [ Testing locally on the java track] ( https://exercism.org/docs/tracks/java/tests ) ;
12750
128- Looks like it was on line 4 in the ` Greeter.java ` file. Let's update that line
129- as instructed, and try running the tests again.
13051
131- ## Step 2 : Replace the ` UnsupportedOperationException `
52+ ## Step 1 : Replace the ` UnsupportedOperationException `
13253
133- In your favorite text editor, open ` src/main/java/Greeter.java ` . You should
134- find the source of the exception encountered above on line 4:
54+ Either working locally or using the online editor, you should find an exception on line 4:
13555
13656``` java
13757throw new UnsupportedOperationException (" Delete this statement and write your own implementation." );
@@ -145,100 +65,36 @@ solution yet! The use of an
14565in this situation is designed to remind us of exactly this fact. It effectively
14666says: "Your Code Goes Here!".
14767
148- Delete the contents of line 4 and replace it with the following :
68+ Delete the contents of line 4 and replace it with:
14969
15070``` java
151- return null ;
152- ```
153-
154- Now run ` gradle test ` again.
155-
156- You should see a new error this time. Don't worry though, that still
157- represents forward progress!
158-
159- ```
160- GreeterTest > testThatGreeterReturnsTheCorrectGreeting FAILED
161- java.lang.AssertionError: expected:<Hello, World!> but was:<null>
162- ```
163-
164- ...is read: "Within the test class named ` GreeterTest ` ,
165- the test method ` testThatGreeterReturnsTheCorrectGreeting ` did not pass because
166- the solution did not satisfy an assertion."
167-
168- Apparently, our test was expecting to see the string "Hello, World!", but it
169- received the value ` null ` instead.
170-
171- The last line of the stack trace tells us exactly where this "unsatisfied
172- assertion" lives:
173-
174- ```
175- at testThatGreeterReturnsTheCorrectGreeting(GreeterTest.java:9)
176- ```
177- Looks like the mismatch was discovered on line 9 in the test file.
178-
179- Knowing these two facts:
180-
181- 1 . that the return value was not what was expected, and
182- 2 . that the failure was on line 9 of the test file,
183-
184- we can turn this failure into success.
185-
186- ## Step 3: Fix the test!
187-
188- Open ` src/test/java/GreeterTest.java ` and go to line 9. It reads:
189-
190- ``` java
191- assertEquals(" Hello, World!" , new Greeter (). getGreeting());
192- ```
193-
194- The test is expecting that the method ` getGreeting() ` returns "Hello, World!".
195- Instead, ` getGreeting() ` is returning ` null ` . Let's fix that.
196-
197- Open ` src/main/java/Greeter.java ` . It should look like this:
198-
199- ``` java
200- class Greeter {
201- String getGreeting () {
202- return null ;
71+ public String getGreeting() {
72+ return " Hello, World!" ;
20373 }
204- }
20574```
20675
207- Remove the ` return null ` that we previously added, and instead return the
208- string our test was expecting:
76+ ## Step 2: Run the Tests
20977
210- ``` java
211- String getGreeting() {
212- return " Hello, World!" ;
213- }
214- ```
78+ After making corrections and implementing your solution, run the tests again.
79+ You can run the tests using the online editor or locally on your machine:
80+ - To run the tests in the online editor, click the "Run Tests" button.
81+ - To run the tests locally, check [ Testing on the Java track] ( https://exercism.org/docs/tracks/java/tests )
82+ If the tests fails, that's ok! See what the error message is telling you, change your code and test again.
83+ When your tests pass, move on to the next step.
21584
216- Save the file and run the tests again:
85+ # Step 3: Submitting your first iteration
21786
218- ```
219- $ gradle test
220- :compileJava
221- :processResources UP-TO-DATE
222- :classes
223- :compileTestJava
224- :processTestResources UP-TO-DATE
225- :testClasses
226- :test
227- GreeterTest > testThatGreeterReturnsTheCorrectGreeting PASSED
228- BUILD SUCCESSFUL
229- Total time: 11.717 secs
230- ```
87+ With a working solution that we've reviewed, we're ready to submit it to
88+ exercism.org.
89+ You can submit the solution using the online editor or locally using the [ Exercism CLI] ( https://exercism.org/docs/using/solving-exercises/working-locally ) :
90+ - To submit the exercise locally, first [ install the exercism CLI] ( https://exercism.org/docs/using/solving-exercises/working-locally ) if you haven't already and then submit the files of your solution, e.g:
23191
232- Success! Our solution passes the only test case supplied. We're good to go !
92+ - If you want to use the online editor to submit your solution, just click the "Submit" button !
23393
234- # Submitting your first iteration
94+ For a closer look at submitting a solution locally:
23595
236- With a working solution that we've reviewed, we're ready to submit it to
237- exercism.io.
96+ * [ Submitting locally] ( https://exercism.org/docs/using/solving-exercises/working-locally ) ;
23897
239- ```
240- $ exercism submit src/main/java/Greeter.java
241- ```
24298
24399# Next Steps
244100
0 commit comments