Skip to content

Commit

Permalink
Merge pull request #277 from unsigable/test
Browse files Browse the repository at this point in the history
Fixing java lesson's test output
  • Loading branch information
Malcom1986 authored Nov 1, 2024
2 parents 6d7c86a + 88765ac commit a477387
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 55 deletions.
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

0 comments on commit a477387

Please sign in to comment.