Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing java lesson's test output #277

Merged
merged 11 commits into from
Nov 1, 2024
11 changes: 7 additions & 4 deletions modules/10-basics/10-hello-world/Test.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import org.assertj.core.api.Assertions;
import static org.assertj.core.api.Assertions.assertThat;

class Test {
public static void main(final String[] args) {
final var expected = "Hello, World!";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

Assertions.assertThat(actual).isEqualTo(expected);
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
8 changes: 5 additions & 3 deletions modules/10-basics/40-testing/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -8,17 +10,17 @@ class Test {
public static void main(String[] args) {
final var expected = "420262531";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

assertThat(actual).isEqualTo(expected);
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}

}
7 changes: 5 additions & 2 deletions modules/10-basics/50-syntax-error/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(final String[] args) {
final var expected = "What Is Dead May Never Die";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/20-arithmetics/10-basics/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "9";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
8 changes: 5 additions & 3 deletions modules/20-arithmetics/20-operators/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -8,17 +10,17 @@ class Test {
public static void main(String[] args) {
final var expected = "87";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

assertThat(actual).isEqualTo(expected);
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}

}
7 changes: 5 additions & 2 deletions modules/20-arithmetics/40-composition/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "10";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/20-arithmetics/50-priority/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "49";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/20-arithmetics/60-float/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "0.0858";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/20-arithmetics/80-linting/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "-14";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/25-strings/10-quotes/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "\"Khal Drogo's favorite word is \"athjahakar\"\"";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/25-strings/20-strings-concatenation/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "Winter " + "came " + "for " + "the " + "House " + "of " + "Frey.";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/30-variables/10-definition/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "What Is Dead May Never Die!";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/30-variables/12-change/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "anneirB";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/30-variables/13-variables-naming/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "-110.00000000000001";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
7 changes: 5 additions & 2 deletions modules/30-variables/14-errors/Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,15 +9,16 @@ class Test {
public static void main(String[] args) {
final var expected = "Targaryen and Dragon";

App.main(null);

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
}
}
Loading