Skip to content

Commit 99aa221

Browse files
authored
Added test for 181.
1 parent 99ef837 commit 99aa221

File tree

2 files changed

+52
-1
lines changed
  • src
    • main/java/g0101_0200/s0181_employees_earning_more_than_their_managers
    • test/java/g0101_0200/s0181_employees_earning_more_than_their_managers

2 files changed

+52
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Write your MySQL query statement below
22
# #Easy #Database
3-
select a.Name as 'Employee' from Employee a left join Employee b on a.ManagerId=b.Id
3+
select a.Name as Employee from Employee a left join Employee b on a.ManagerId=b.Id
44
where a.Salary > b.Salary and a.ManagerId is not null
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package g0101_0200.s0181_employees_earning_more_than_their_managers;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import java.io.BufferedReader;
7+
import java.io.FileNotFoundException;
8+
import java.io.FileReader;
9+
import java.sql.Connection;
10+
import java.sql.ResultSet;
11+
import java.sql.SQLException;
12+
import java.sql.Statement;
13+
import java.util.stream.Collectors;
14+
import javax.sql.DataSource;
15+
import org.junit.jupiter.api.Test;
16+
import org.zapodot.junit.db.annotations.EmbeddedDatabase;
17+
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest;
18+
import org.zapodot.junit.db.common.CompatibilityMode;
19+
20+
@EmbeddedDatabaseTest(
21+
compatibilityMode = CompatibilityMode.MySQL,
22+
initialSqls =
23+
"CREATE TABLE Employee(id INTEGER PRIMARY KEY, name VARCHAR,"
24+
+ " salary INTEGER, managerId INTEGER); "
25+
+ "INSERT INTO Employee(id, name, salary, managerId) VALUES (1, 'Joe', 70000, 3); "
26+
+ "INSERT INTO Employee(id, name, salary, managerId) VALUES (2, 'Henry', 80000, 4); "
27+
+ "INSERT INTO Employee(id, name, salary, managerId) VALUES (3, 'Sam', 60000, NULL); "
28+
+ "INSERT INTO Employee(id, name, salary, managerId) VALUES (4, 'Max', 90000, NULL); ")
29+
class MysqlTest {
30+
@Test
31+
void testScript(@EmbeddedDatabase DataSource dataSource)
32+
throws SQLException, FileNotFoundException {
33+
try (final Connection connection = dataSource.getConnection()) {
34+
try (final Statement statement = connection.createStatement();
35+
final ResultSet resultSet =
36+
statement.executeQuery(
37+
new BufferedReader(
38+
new FileReader(
39+
"src/main/java/g0101_0200/"
40+
+ "s0181_employees_earning"
41+
+ "_more_than_their_managers/script.sql"))
42+
.lines()
43+
.collect(Collectors.joining("\n"))
44+
.replaceAll("#.*?\\r?\\n", ""))) {
45+
assertThat(resultSet.next(), equalTo(true));
46+
assertThat(resultSet.getNString(1), equalTo("Joe"));
47+
assertThat(resultSet.next(), equalTo(false));
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)