assertFalse() is a built in JUint function to test your java programs before deploying the application on your production environment/server.
assertFalse() method checks whether the expected value is true or not.
Example 1. assertFalse() Function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package com.java2novice.junit.tests; import org.junit.Test; import static org.junit.Assert.*; public class MyAssertFalseTest { public boolean isEvenNumber(int number){ boolean result = false; if(number%2 == 0){ result = true; } return result; } @Test public void evenNumberTest(){ MyAssertFalseTest asft = new MyAssertFalseTest(); assertFalse(asft.isEvenNumber(3)); } } |
Example 2. assertFalse() Function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
@Test public void testAutoCommitFalse() throws Exception { DataSourceProxy d1 = this.createDefaultDataSource(); d1.setMaxActive(1); d1.setMinIdle(1); d1.setMaxIdle(1); d1.setJdbcInterceptors(ConnectionState.class.getName()); d1.setDefaultAutoCommit(Boolean.FALSE); Connection c1 = d1.getConnection(); Assert.assertFalse("Auto commit should be false",c1.getAutoCommit()); c1.setAutoCommit(true); Assert.assertTrue("Auto commit should be true",c1.getAutoCommit()); c1.close(); c1 = d1.getConnection(); Assert.assertFalse("Auto commit should be false for a reused connection",c1.getAutoCommit()); d1.close(true); Assert.assertTrue("Connection should be closed",c1.isClosed()); } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.