Skip to content

Commit 8dbed66

Browse files
authored
Merge pull request eugenp#4068 from michael-pratt/BAEL-1738
Demonstration of Java assert
2 parents 274745e + 79fa459 commit 8dbed66

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.assertion;
2+
3+
/**
4+
* Simple demonstration of using Java assert keyword.
5+
*/
6+
public class Assertion {
7+
8+
public static void main(String[] args) {
9+
Assertion assertion = new Assertion();
10+
assertion.setup();
11+
}
12+
13+
public void setup() {
14+
Object conn = getConnection();
15+
assert conn != null : "Connection is null";
16+
17+
// continue with other setup ...
18+
}
19+
20+
// Simulate failure to get a connection; using Object
21+
// to avoid dependencies on JDBC or some other heavy
22+
// 3rd party library
23+
public Object getConnection() {
24+
return null;
25+
}
26+
}

0 commit comments

Comments
 (0)