# Output Tests

This is an example of how you can test the output stream of student code.&#x20;

This test makes sure the student's code prints `"Hello World"`.  It assumes the student's file name is `Example.java`.  Replace the `Example.main(null)` call with whatever you student's file name is.&#x20;

*Note:  This code converts the output to all lowercase and removes spaces to compare against the correct value.*

#### **Grading Tests:**

```java
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import java.io.*;


public class CodingRoomsUnitTests {
    
    private final PrintStream standardOut = System.out;
    private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();

    @Before
    public void setUp() {
        System.setOut(new PrintStream(outputStreamCaptor));
    }

    @After
    public void tearDown() {
        System.setOut(standardOut);
    }

    @Test
    public void testDefaultCase() {
        Example.main(null);
        assertEquals("Hello World".toLowerCase().trim().replace(" ", ""), outputStreamCaptor.toString().toLowerCase().trim().replace(" ", ""));
    }    
}
```

#### Sample Solution:

{% code title="Example.java" %}

```java
public class Example
{
    public static void main(String[] args)
    {
        System.out.println("Hello World");
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auto-grade.joemazzone.net/java/output-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
