Skip to content
Permalink
Browse files
Replace assert by simpler but equivalent calls. (#139)
  • Loading branch information
arturobernalg committed Mar 3, 2022
1 parent 8d36e71 commit e4fff0ef324003f9c1912ff59132820e0f3f4398
Showing 29 changed files with 78 additions and 70 deletions.
@@ -93,7 +93,7 @@ public void testIntegerDefaultValue() throws Exception {
}

public void testIsEmpty() throws Exception {
Assert.assertTrue("Configuration should not be empty", !configuration.isEmpty());
Assert.assertFalse("Configuration should not be empty", configuration.isEmpty());
}

public void testListMissing() throws Exception {
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -418,7 +419,7 @@ public void testGetInterpolatedPrimitives() {
config.addProperty("booleanValue", "${boolean}");

// primitive types
assertEquals("boolean interpolation", true, config.getBoolean("booleanValue"));
assertTrue("boolean interpolation", config.getBoolean("booleanValue"));
assertEquals("byte interpolation", 1, config.getByte("value"));
assertEquals("short interpolation", 1, config.getShort("value"));
assertEquals("int interpolation", 1, config.getInt("value"));
@@ -483,7 +484,7 @@ public void testGetLongUnknown() {
@Test
public void testGetProperty() {
/* should be empty and return null */
assertEquals("This returns null", config.getProperty("foo"), null);
assertNull("This returns null", config.getProperty("foo"));

/* add a real value, and get it two different ways */
config.setProperty("number", "1");
@@ -240,7 +240,7 @@ public void testGetLongUnknown() {
@Test
public void testGetProperty() {
/* should be empty and return null */
assertEquals("This returns null", config.getProperty("foo"), null);
assertNull("This returns null", config.getProperty("foo"));

/* add a real value, and get it two different ways */
config.setProperty("number", "1");
@@ -697,10 +697,10 @@ public void testGetConfigurationNameList() throws Exception {
config.addConfiguration(pc, "props");
final List<String> list = config.getConfigurationNameList();
assertNotNull("No list of configurations returned", list);
assertTrue("Incorrect number of configurations", list.size() == 3);
assertEquals("Incorrect number of configurations", 3, list.size());
final String name = list.get(1);
assertNotNull("No name returned", name);
assertTrue("Incorrect configuration name", TEST_NAME.equals(name));
assertEquals("Incorrect configuration name", TEST_NAME, name);
}

/**
@@ -733,9 +733,9 @@ public void testGetConfigurations() throws Exception {
config.addConfiguration(pc, "props");
final List<Configuration> list = config.getConfigurations();
assertNotNull("No list of configurations returned", list);
assertTrue("Incorrect number of configurations", list.size() == 3);
assertEquals("Incorrect number of configurations", 3, list.size());
final Configuration c = list.get(2);
assertTrue("Incorrect configuration", c == pc);
assertSame("Incorrect configuration", c, pc);
}

/**
@@ -240,7 +240,7 @@ public void testClearingProperty() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(xmlConf);
cc.clearProperty("test.short");
assertTrue("Make sure test.short is gone!", !cc.containsKey("test.short"));
assertFalse("Make sure test.short is gone!", cc.containsKey("test.short"));
}

@Test
@@ -294,8 +294,8 @@ public void testDefaultValueWhenKeyMissing() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(xmlConf);
assertEquals("default", cc.getString("bogus", "default"));
assertTrue(1.4 == cc.getDouble("bogus", 1.4));
assertTrue(1.4 == cc.getDouble("bogus", 1.4));
assertEquals(1.4, cc.getDouble("bogus", 1.4), 0.0);
assertEquals(1.4, cc.getDouble("bogus", 1.4), 0.0);
}

/**
@@ -483,7 +483,7 @@ public void testGetPropertyMissing() throws Exception {
assertTrue(nsee.getMessage().contains("bogus.property"));
}

assertTrue("Should be false", !cc.getBoolean("test.missing.boolean", false));
assertFalse("Should be false", cc.getBoolean("test.missing.boolean", false));
assertTrue("Should be true", cc.getBoolean("test.missing.boolean.true", true));
}

@@ -19,6 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import javax.sql.DataSource;
@@ -436,7 +437,7 @@ public void testGetPropertyDirectMultiple() throws ConfigurationException {

assertEquals("property1", "value1", config.getProperty("key1"));
assertEquals("property2", "value2", config.getProperty("key2"));
assertEquals("unknown property", null, config.getProperty("key3"));
assertNull("unknown property", config.getProperty("key3"));
}

@Test
@@ -445,7 +446,7 @@ public void testGetPropertyDirectSingle() throws ConfigurationException {

assertEquals("property1", "value1", config.getProperty("key1"));
assertEquals("property2", "value2", config.getProperty("key2"));
assertEquals("unknown property", null, config.getProperty("key3"));
assertNull("unknown property", config.getProperty("key3"));
}

/**
@@ -479,6 +479,6 @@ public void testUpdateConfiguration() throws ConfigurationException {

private void verify(final String key, final DynamicCombinedConfiguration config, final int rows) {
System.setProperty("Id", key);
assertTrue(config.getInt("rowsPerPage") == rows);
assertEquals(config.getInt("rowsPerPage"), rows);
}
}
@@ -19,6 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.util.Iterator;
@@ -202,7 +203,7 @@ public void testSettingExisting() throws Exception {
final String value = "new value";

assertTrue(simple.containsKey(key));
assertFalse(simple.getString(key).equals(value));
assertNotEquals(value, simple.getString(key));
assertEquals(simple.containsKey(key), composite.containsKey(key));

simple.setProperty(key, value);
@@ -190,7 +190,7 @@ private void checkContent(final INIConfiguration instance) {
assertEquals("var2", 451, instance.getInt("section1.var2"));
assertEquals("section2.var1", 123.45, instance.getDouble("section2.var1"), .001);
assertEquals("section2.var2", "bar", instance.getString("section2.var2"));
assertEquals("section3.var1", true, instance.getBoolean("section3.var1"));
assertTrue("section3.var1", instance.getBoolean("section3.var1"));
assertEquals("Wrong number of sections", 3, instance.getSections().size());
assertTrue("Wrong sections", instance.getSections().containsAll(Arrays.asList("section1", "section2", "section3")));
}
@@ -168,7 +168,7 @@ public void testUnmodifiableConfigurationNull() {
public void testUnmodifiableConfigurationOtherTypes() throws ConfigurationException {
final ImmutableConfiguration conf = ConfigurationUtils.unmodifiableConfiguration(createTestConfig());
assertEquals("Wrong byte", (byte) 10, conf.getByte("test.byte"));
assertEquals("Wrong boolean", true, conf.getBoolean("test.boolean"));
assertTrue("Wrong boolean", conf.getBoolean("test.boolean"));
assertEquals("Wrong double", 10.25, conf.getDouble("test.double"), .05);
assertEquals("Wrong float", 20.25f, conf.getFloat("test.float"), .05);
assertEquals("Wrong int", 10, conf.getInt("test.integer"));
@@ -164,11 +164,11 @@ public void testByte() throws Exception {
@Test
public void testChangePrefix() {
assertEquals("'test.boolean' property", "true", conf.getString("test.boolean"));
assertEquals("'boolean' property", null, conf.getString("boolean"));
assertNull("'boolean' property", conf.getString("boolean"));

// change the prefix
conf.setPrefix("test");
assertEquals("'test.boolean' property", null, conf.getString("test.boolean"));
assertNull("'test.boolean' property", conf.getString("test.boolean"));
assertEquals("'boolean' property", "true", conf.getString("boolean"));
}

@@ -319,7 +319,7 @@ public void testResetRemovedProperties() throws Exception {

// remove the property
conf.clearProperty("test.boolean");
assertEquals("'test.boolean' property", null, conf.getString("test.boolean"));
assertNull("'test.boolean' property", conf.getString("test.boolean"));

// change the context
conf.setContext(new InitialContext());
@@ -50,7 +50,7 @@ public void testClearProperty() {
@Test
public void testContainsKey() throws Exception {
assertTrue(conf.containsKey("test.key"));
assertTrue(!conf.containsKey("test.imaginarykey"));
assertFalse(conf.containsKey("test.imaginarykey"));
}

@Test
@@ -147,7 +147,7 @@ public void testClearingProperty() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(xmlConf);
cc.clearProperty("test.short");
assertTrue("Make sure test.short is gone!", !cc.containsKey("test.short"));
assertFalse("Make sure test.short is gone!", cc.containsKey("test.short"));
}

/**
@@ -158,8 +158,8 @@ public void testDefaultValueWhenKeyMissing() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(xmlConf);
assertEquals("default", cc.getString("bogus", "default"));
assertTrue(1.4 == cc.getDouble("bogus", 1.4));
assertTrue(1.4 == cc.getDouble("bogus", 1.4));
assertEquals(1.4, cc.getDouble("bogus", 1.4), 0.0);
assertEquals(1.4, cc.getDouble("bogus", 1.4), 0.0);
}

/**
@@ -253,7 +253,7 @@ public void testGetPropertyMissing() throws Exception {

assertNull("Bogus property is not null!", cc.getString("bogus.property"));

assertTrue("Should be false", !cc.getBoolean("test.missing.boolean", false));
assertFalse("Should be false", cc.getBoolean("test.missing.boolean", false));
assertTrue("Should be true", cc.getBoolean("test.missing.boolean.true", true));
}

@@ -49,7 +49,7 @@ public void testClearProperty() {
@Test
public void testContainsKey() throws Exception {
assertTrue(conf.containsKey("test.key"));
assertTrue(!conf.containsKey("test.imaginarykey"));
assertFalse(conf.containsKey("test.imaginarykey"));
}

@Test
@@ -17,7 +17,7 @@

package org.apache.commons.configuration2;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.StringWriter;
@@ -53,13 +53,13 @@ public void testMultiConfiguration() {
config.setExpressionEngine(new XPathExpressionEngine());

System.setProperty("Id", "1001");
assertTrue(config.getInt("rowsPerPage") == 15);
assertEquals(15, config.getInt("rowsPerPage"));

System.setProperty("Id", "1002");
assertTrue(config.getInt("rowsPerPage") == 25);
assertEquals(25, config.getInt("rowsPerPage"));

System.setProperty("Id", "1003");
assertTrue(config.getInt("rowsPerPage") == 35);
assertEquals(35, config.getInt("rowsPerPage"));
}

/**
@@ -936,7 +936,7 @@ public void testLineSeparator() throws ConfigurationException {
final StringWriter out = new StringWriter();
new FileHandler(conf).save(out);
final String content = out.toString();
assertTrue("Header could not be found", content.indexOf("# My header" + EOL + EOL) == 0);
assertEquals("Header could not be found", 0, content.indexOf("# My header" + EOL + EOL));
assertTrue("Property could not be found", content.indexOf("prop = value" + EOL) > 0);
}

@@ -1102,7 +1102,7 @@ public void testMultipleIncludeFiles() throws ConfigurationException {
handler.load(ConfigurationAssert.getTestFile("config/testMultiInclude.properties"));
assertEquals("Wrong top-level property", "topValue", conf.getString("top"));
assertEquals("Wrong included property (1)", 100, conf.getInt("property.c"));
assertEquals("Wrong included property (2)", true, conf.getBoolean("include.loaded"));
assertTrue("Wrong included property (2)", conf.getBoolean("include.loaded"));
}

/**
@@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -467,7 +468,7 @@ public void testInitCopyModify() {
layout.setComment(TEST_KEY, "A new comment");
assertEquals("Comment was changed", TEST_COMMENT, l2.getCanonicalComment(TEST_KEY, false));
l2.setBlankLinesBefore(TEST_KEY, l2.getBlankLinesBefore(TEST_KEY) + 1);
assertFalse("Blanc lines do not differ", layout.getBlankLinesBefore(TEST_KEY) == l2.getBlankLinesBefore(TEST_KEY));
assertNotEquals("Blanc lines do not differ", layout.getBlankLinesBefore(TEST_KEY), l2.getBlankLinesBefore(TEST_KEY));
}

/**
@@ -608,8 +609,8 @@ public void testSaveCommentForUnexistingProperty() throws ConfigurationException
fillLayout();
layout.setComment("NonExistingKey", "NonExistingComment");
final String output = getLayoutString();
assertTrue("Non existing key was found", !output.contains("NonExistingKey"));
assertTrue("Non existing comment was found", !output.contains("NonExistingComment"));
assertFalse("Non existing key was found", output.contains("NonExistingKey"));
assertFalse("Non existing comment was found", output.contains("NonExistingComment"));
}

/**
@@ -591,7 +591,7 @@ public void testConcurrentGetAndReload() throws ConfigurationException, Interrup
final FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class);
builder.configure(new FileBasedBuilderParametersImpl().setFileName(testProperties));
XMLConfiguration config = builder.getConfiguration();
assertTrue("Property not found", config.getProperty("test.short") != null);
assertNotNull("Property not found", config.getProperty("test.short"));

final Thread testThreads[] = new Thread[THREAD_COUNT];
for (int i = 0; i < testThreads.length; ++i) {
@@ -601,7 +601,7 @@ public void testConcurrentGetAndReload() throws ConfigurationException, Interrup

for (int i = 0; i < LOOP_COUNT; i++) {
config = builder.getConfiguration();
assertTrue("Property not found", config.getProperty("test.short") != null);
assertNotNull("Property not found", config.getProperty("test.short"));
}

for (final Thread testThread : testThreads) {
@@ -437,7 +437,7 @@ public void testGetSimpleString() {
@Test
public void testMappedContains() {
assertTrue("Can't see first key", bean.contains("mappedProperty", "key1"));
assertTrue("Can see unknown key", !bean.contains("mappedProperty", "Unknown Key"));
assertFalse("Can see unknown key", bean.contains("mappedProperty", "Unknown Key"));
}

/**
@@ -447,11 +447,11 @@ public void testMappedContains() {
public void testMappedRemove() {
assertTrue("Can see first key", bean.contains("mappedProperty", "key1"));
bean.remove("mappedProperty", "key1");
assertTrue("Can not see first key", !bean.contains("mappedProperty", "key1"));
assertFalse("Can not see first key", bean.contains("mappedProperty", "key1"));

assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
assertFalse("Can not see unknown key", bean.contains("mappedProperty", "key4"));
bean.remove("mappedProperty", "key4");
assertTrue("Can not see unknown key", !bean.contains("mappedProperty", "key4"));
assertFalse("Can not see unknown key", bean.contains("mappedProperty", "key4"));
}

/**
@@ -564,7 +564,7 @@ public void testSetSimpleBoolean() {
final boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
final boolean newValue = !oldValue;
bean.set("booleanProperty", Boolean.valueOf(newValue));
assertTrue("Matched new value", newValue == ((Boolean) bean.get("booleanProperty")).booleanValue());
assertEquals("Matched new value", newValue, ((Boolean) bean.get("booleanProperty")).booleanValue());
}

/**
@@ -345,7 +345,7 @@ public void testSchemaValidationError() {
while (cause != null && !(cause instanceof SAXParseException)) {
cause = cause.getCause();
}
assertTrue("SAXParseException was not thrown", cause != null);
assertNotNull("SAXParseException was not thrown", cause);
}
}
}
@@ -236,7 +236,7 @@ public void testConcurrentGetAndReload() throws Exception {
testThreads[i].join();
totalFailures += failures[i];
}
assertTrue(totalFailures + " failures Occurred", totalFailures == 0);
assertEquals(totalFailures + " failures Occurred", 0, totalFailures);
}

/**
@@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;

import java.util.LinkedList;
@@ -92,7 +93,7 @@ public void onEvent(final T event) {
public void skipToLast(final EventType<?> type) {
while (events.size() > 1) {
final T e = events.remove(0);
assertTrue("Found end event in details", type != e.getEventType());
assertNotSame("Found end event in details", type, e.getEventType());
}
}
}

0 comments on commit e4fff0e

Please sign in to comment.