Skip to content

Commit 1cc41b3

Browse files
committed
Implement tests for AssertionsOnTableExistence
1 parent 924b5d2 commit 1cc41b3

File tree

7 files changed

+314
-10
lines changed

7 files changed

+314
-10
lines changed

src/main/java/org/assertj/db/api/TableAssert.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
/**
2020
* Assertion methods for a {@link Table}.
21-
*
21+
*
2222
* @author Régis Pouiller
23-
*
23+
*
2424
*/
2525
public class TableAssert
26-
extends AbstractDbAssert<Table, TableAssert, TableColumnAssert, TableColumnValueAssert, TableRowAssert, TableRowValueAssert>
27-
implements AssertOnExistence<TableAssert> {
26+
extends AbstractDbAssert<Table, TableAssert, TableColumnAssert, TableColumnValueAssert, TableRowAssert, TableRowValueAssert>
27+
implements AssertOnExistence<TableAssert> {
2828

2929
/**
3030
* Constructor.
31-
*
31+
*
3232
* @param table Table on which the assertion is.
3333
*/
3434
TableAssert(Table table) {
@@ -66,6 +66,6 @@ public TableAssert exists() {
6666
*/
6767
@Override
6868
public TableAssert doesNotExist() {
69-
return null;
69+
return AssertionsOnTableExistence.doesNotExists(this, info, actual.getName(), actual.getSource(), actual.getDataSource());
7070
}
7171
}

src/main/java/org/assertj/db/api/assertions/AssertOnExistence.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
113
package org.assertj.db.api.assertions;
214

315
/**

src/main/java/org/assertj/db/api/assertions/impl/AssertionsOnTableExistence.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
113
package org.assertj.db.api.assertions.impl;
214

315
import org.assertj.core.api.WritableAssertionInfo;
@@ -18,21 +30,23 @@
1830
import static org.assertj.db.error.ShouldNotExist.shouldNotExist;
1931

2032
/**
21-
* Implements the assertion method on the existence of a table
33+
* Implements the assertion method on the existence of a table.
34+
*
2235
* @author Avinash Ananth Narayan
36+
*
2337
*/
2438
public class AssertionsOnTableExistence {
2539

2640
/**
2741
* To notice failures in the assertion.
2842
*/
29-
private final static Failures failures = Failures.instance();
43+
private static final Failures failures = Failures.instance();
3044

3145
private AssertionsOnTableExistence() {
3246
// Empty
3347
}
3448

35-
public static <A extends AbstractDbAssert> A exists(A assertion, WritableAssertionInfo info,
49+
public static <A extends AbstractDbAssert<?, ?, ?, ?, ?, ?>> A exists(A assertion, WritableAssertionInfo info,
3650
String table, Source source, DataSource dataSource) {
3751
try (Connection connection = getConnection(source, dataSource)) {
3852
DatabaseMetaData metaData = connection.getMetaData();
@@ -47,7 +61,7 @@ public static <A extends AbstractDbAssert> A exists(A assertion, WritableAsserti
4761
return assertion;
4862
}
4963

50-
public static <A extends AbstractDbAssert> A doesNotExists(A assertion, WritableAssertionInfo info,
64+
public static <A extends AbstractDbAssert<?, ?, ?, ?, ?, ?>> A doesNotExists(A assertion, WritableAssertionInfo info,
5165
String table, Source source, DataSource dataSource) {
5266
try (Connection connection = getConnection(source, dataSource)) {
5367
DatabaseMetaData metaData = connection.getMetaData();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.db.api.TableAssert;
17+
import org.assertj.db.common.AbstractTest;
18+
import org.assertj.db.common.NeedReload;
19+
import org.assertj.db.type.Table;
20+
import org.junit.Test;
21+
22+
import static org.assertj.db.api.Assertions.assertThat;
23+
import static org.junit.Assert.fail;
24+
25+
/**
26+
* Tests on {@link AssertOnExistence} class :
27+
* {@link AssertOnExistence#doesNotExist()} method.
28+
*
29+
* @author Julien Roy
30+
*
31+
*/
32+
public class AssertOnExistence_DoesNotExist_Test extends AbstractTest {
33+
34+
/**
35+
* This method tests the {@code doesNotExist} assertion method.
36+
*/
37+
@Test
38+
@NeedReload
39+
public void test_table_does_not_exist() {
40+
Table table = new Table(source, "not-exist-test");
41+
TableAssert tableAssert = assertThat(table);
42+
TableAssert tableAssertExistReturn = tableAssert.doesNotExist();
43+
Assertions.assertThat(tableAssert).isSameAs(tableAssertExistReturn);
44+
}
45+
46+
/**
47+
* This method should fail because the table exist.
48+
*/
49+
@Test
50+
@NeedReload
51+
public void should_fail_because_table_exist() {
52+
Table table = new Table(source, "test");
53+
54+
try {
55+
assertThat(table).doesNotExist();
56+
fail("An exception must be raised");
57+
} catch (AssertionError e) {
58+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[TEST table] %n"
59+
+ "Expecting not exist but exists"));
60+
}
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.db.api.TableAssert;
17+
import org.assertj.db.common.AbstractTest;
18+
import org.assertj.db.common.NeedReload;
19+
import org.assertj.db.type.Table;
20+
import org.junit.Test;
21+
22+
import static org.assertj.db.api.Assertions.assertThat;
23+
import static org.junit.Assert.fail;
24+
25+
/**
26+
* Tests on {@link AssertOnExistence} class :
27+
* {@link AssertOnExistence#exists()} method.
28+
*
29+
* @author Julien Roy
30+
*
31+
*/
32+
public class AssertOnExistence_Exists_Test extends AbstractTest {
33+
34+
/**
35+
* This method tests the {@code exists} assertion method.
36+
*/
37+
@Test
38+
@NeedReload
39+
public void test_table_exists() {
40+
Table table = new Table(source, "test");
41+
TableAssert tableAssert = assertThat(table);
42+
TableAssert tableAssertExistReturn = tableAssert.exists();
43+
Assertions.assertThat(tableAssert).isSameAs(tableAssertExistReturn);
44+
}
45+
46+
/**
47+
* This method should fail because the table not exist.
48+
*/
49+
@Test
50+
@NeedReload
51+
public void should_fail_because_table_not_exist() {
52+
Table table = new Table(source, "not-exist-test");
53+
54+
try {
55+
assertThat(table).exists();
56+
fail("An exception must be raised");
57+
} catch (AssertionError e) {
58+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[not-exist-test table] %n"
59+
+ "Expecting exist but do not exist"));
60+
}
61+
}
62+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions.impl;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.core.api.WritableAssertionInfo;
17+
import org.assertj.db.api.AbstractDbAssert;
18+
import org.assertj.db.api.TableAssert;
19+
import org.assertj.db.common.AbstractTest;
20+
import org.assertj.db.type.Source;
21+
import org.assertj.db.type.Table;
22+
import org.junit.Test;
23+
24+
import javax.sql.DataSource;
25+
26+
import static org.assertj.db.api.Assertions.assertThat;
27+
import static org.junit.Assert.fail;
28+
29+
/**
30+
* Tests on {@link AssertionsOnTableExistence} class :
31+
* {@link AssertionsOnTableExistence#doesNotExists(AbstractDbAssert, WritableAssertionInfo, String, Source, DataSource)} method.
32+
*
33+
* @author Julien Roy
34+
*
35+
*/
36+
public class AssertionsOnTableExistence_DoesNotExist_Test extends AbstractTest {
37+
38+
/**
39+
* This method tests the {@code doesNotExists} assertion method.
40+
*/
41+
@Test
42+
public void test_does_not_exists() {
43+
WritableAssertionInfo info = new WritableAssertionInfo();
44+
Table table = new Table();
45+
TableAssert tableAssert = assertThat(table);
46+
TableAssert tableAssert2 = AssertionsOnTableExistence.doesNotExists(tableAssert, info, "not-exist-test", source, null);
47+
Assertions.assertThat(tableAssert2).isSameAs(tableAssert);
48+
TableAssert tableAssert3 = AssertionsOnTableExistence.doesNotExists(tableAssert, info, "not-exist-test", null, dataSource);
49+
Assertions.assertThat(tableAssert3).isSameAs(tableAssert);
50+
}
51+
52+
/**
53+
* This method should fail because the table exists.
54+
*/
55+
@Test
56+
public void should_fail_because_table_exists() {
57+
WritableAssertionInfo info = new WritableAssertionInfo();
58+
info.description("description");
59+
Table table = new Table();
60+
TableAssert tableAssert = assertThat(table);
61+
try {
62+
AssertionsOnTableExistence.doesNotExists(tableAssert, info, "TEST", source, null);
63+
fail("An exception must be raised");
64+
} catch (AssertionError e) {
65+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n"
66+
+ "Expecting not exist but exists"));
67+
}
68+
69+
try {
70+
AssertionsOnTableExistence.doesNotExists(tableAssert, info, "TEST", null, dataSource);
71+
fail("An exception must be raised");
72+
} catch (AssertionError e) {
73+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n"
74+
+ "Expecting not exist but exists"));
75+
}
76+
}
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2012-2016 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions.impl;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.core.api.WritableAssertionInfo;
17+
import org.assertj.db.api.AbstractDbAssert;
18+
import org.assertj.db.api.TableAssert;
19+
import org.assertj.db.common.AbstractTest;
20+
import org.assertj.db.type.Source;
21+
import org.assertj.db.type.Table;
22+
import org.junit.Test;
23+
24+
import javax.sql.DataSource;
25+
26+
import static org.assertj.db.api.Assertions.assertThat;
27+
import static org.junit.Assert.fail;
28+
29+
/**
30+
* Tests on {@link AssertionsOnTableExistence} class :
31+
* {@link AssertionsOnTableExistence#exists(AbstractDbAssert, WritableAssertionInfo, String, Source, DataSource)} method.
32+
*
33+
* @author Julien Roy
34+
*
35+
*/
36+
public class AssertionsOnTableExistence_Exists_Test extends AbstractTest {
37+
38+
/**
39+
* This method tests the {@code exists} assertion method.
40+
*/
41+
@Test
42+
public void test_exists() {
43+
WritableAssertionInfo info = new WritableAssertionInfo();
44+
Table table = new Table();
45+
TableAssert tableAssert = assertThat(table);
46+
TableAssert tableAssert2 = AssertionsOnTableExistence.exists(tableAssert, info, "TEST", source, null);
47+
Assertions.assertThat(tableAssert2).isSameAs(tableAssert);
48+
TableAssert tableAssert3 = AssertionsOnTableExistence.exists(tableAssert, info, "TEST", null, dataSource);
49+
Assertions.assertThat(tableAssert3).isSameAs(tableAssert);
50+
}
51+
52+
/**
53+
* This method should fail because the table does not exist.
54+
*/
55+
@Test
56+
public void should_fail_because_table_does_not_exist() {
57+
WritableAssertionInfo info = new WritableAssertionInfo();
58+
info.description("description");
59+
Table table = new Table();
60+
TableAssert tableAssert = assertThat(table);
61+
try {
62+
AssertionsOnTableExistence.exists(tableAssert, info, "not-exist-test", source, null);
63+
fail("An exception must be raised");
64+
} catch (AssertionError e) {
65+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n"
66+
+ "Expecting exist but do not exist"));
67+
}
68+
69+
try {
70+
AssertionsOnTableExistence.exists(tableAssert, info, "not-exist-test", null, dataSource);
71+
fail("An exception must be raised");
72+
} catch (AssertionError e) {
73+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n"
74+
+ "Expecting exist but do not exist"));
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)