[Major] change DBC to add bad values for better debugging
This commit is contained in:
parent
9e449e56ee
commit
2e58db83fd
|
@ -17,6 +17,7 @@ package ch.eitchnet.utils.dbc;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
@ -38,8 +39,8 @@ public enum DBC {
|
||||||
if (value2 != null && value2.equals(value1))
|
if (value2 != null && value2.equals(value1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String ex = "Values are not equal: {0}"; //$NON-NLS-1$
|
String ex = "{0}: {1} != {2}"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, value1, value2);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +51,8 @@ public enum DBC {
|
||||||
if (value2 != null && !value2.equals(value1))
|
if (value2 != null && !value2.equals(value1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String ex = "Values are equal: {0}"; //$NON-NLS-1$
|
String ex = "{0}: {1} == {2}"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, value1, value2);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +74,8 @@ public enum DBC {
|
||||||
|
|
||||||
public void assertEmpty(String msg, String value) {
|
public void assertEmpty(String msg, String value) {
|
||||||
if (!StringHelper.isEmpty(value)) {
|
if (!StringHelper.isEmpty(value)) {
|
||||||
String ex = "Illegal non-empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal non-empty value: {1}"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, value);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +83,8 @@ public enum DBC {
|
||||||
public void assertEmpty(String msg, Object[] array) {
|
public void assertEmpty(String msg, Object[] array) {
|
||||||
assertNotNull(msg, array);
|
assertNotNull(msg, array);
|
||||||
if (array.length != 0) {
|
if (array.length != 0) {
|
||||||
String ex = "Illegal non-empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal non-empty value: {1}"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, Arrays.toString(array));
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,15 +92,15 @@ public enum DBC {
|
||||||
public void assertEmpty(String msg, Collection<?> collection) {
|
public void assertEmpty(String msg, Collection<?> collection) {
|
||||||
assertNotNull(msg, collection);
|
assertNotNull(msg, collection);
|
||||||
if (!collection.isEmpty()) {
|
if (!collection.isEmpty()) {
|
||||||
String ex = "Illegal non-empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal non-empty value: {1}"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, collection.toString());
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertNotEmpty(String msg, String value) {
|
public void assertNotEmpty(String msg, String value) {
|
||||||
if (StringHelper.isEmpty(value)) {
|
if (StringHelper.isEmpty(value)) {
|
||||||
String ex = "Illegal empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal empty value"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +109,7 @@ public enum DBC {
|
||||||
public void assertNotEmpty(String msg, Object[] array) {
|
public void assertNotEmpty(String msg, Object[] array) {
|
||||||
assertNotNull(msg, array);
|
assertNotNull(msg, array);
|
||||||
if (array.length == 0) {
|
if (array.length == 0) {
|
||||||
String ex = "Illegal empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal empty value"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +118,7 @@ public enum DBC {
|
||||||
public void assertNotEmpty(String msg, Collection<?> collection) {
|
public void assertNotEmpty(String msg, Collection<?> collection) {
|
||||||
assertNotNull(msg, collection);
|
assertNotNull(msg, collection);
|
||||||
if (collection.isEmpty()) {
|
if (collection.isEmpty()) {
|
||||||
String ex = "Illegal empty value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal empty value"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
@ -125,7 +126,7 @@ public enum DBC {
|
||||||
|
|
||||||
public void assertNotNull(String msg, Object value) {
|
public void assertNotNull(String msg, Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
String ex = "Illegal null value: {0}"; //$NON-NLS-1$
|
String ex = "{0}: Illegal null value"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
|
@ -133,8 +134,8 @@ public enum DBC {
|
||||||
|
|
||||||
public void assertNull(String msg, Object value) {
|
public void assertNull(String msg, Object value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
String ex = "Illegal situation as value is not null: {0}"; //$NON-NLS-1$
|
String ex = "{0}: {1} != null"; //$NON-NLS-1$
|
||||||
ex = MessageFormat.format(ex, msg);
|
ex = MessageFormat.format(ex, msg, value);
|
||||||
throw new DbcException(ex);
|
throw new DbcException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package ch.eitchnet.utils.dbc;
|
package ch.eitchnet.utils.dbc;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -64,10 +65,10 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertEquals_2() throws Exception {
|
public void testAssertEquals_2() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Values are not equal:");
|
|
||||||
String msg = "";
|
|
||||||
Object value1 = new Object();
|
Object value1 = new Object();
|
||||||
Object value2 = new Object();
|
Object value2 = new Object();
|
||||||
|
String msg = MessageFormat.format("{0}: {1} != {2}", "", value1, value2);
|
||||||
|
this.exception.expectMessage(msg);
|
||||||
|
|
||||||
DBC.PRE.assertEquals(msg, value1, value2);
|
DBC.PRE.assertEquals(msg, value1, value2);
|
||||||
|
|
||||||
|
@ -87,12 +88,13 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertEquals_3() throws Exception {
|
public void testAssertEquals_3() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Values are not equal:");
|
|
||||||
|
|
||||||
String msg = "";
|
|
||||||
Object value1 = null;
|
Object value1 = null;
|
||||||
Object value2 = new Object();
|
Object value2 = new Object();
|
||||||
|
|
||||||
|
String msg = MessageFormat.format("{0}: {1} != {2}", "", value1, value2);
|
||||||
|
this.exception.expectMessage(msg);
|
||||||
|
|
||||||
DBC.PRE.assertEquals(msg, value1, value2);
|
DBC.PRE.assertEquals(msg, value1, value2);
|
||||||
|
|
||||||
// add additional test code here
|
// add additional test code here
|
||||||
|
@ -108,12 +110,13 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertEquals_4() throws Exception {
|
public void testAssertEquals_4() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Values are not equal:");
|
|
||||||
|
|
||||||
String msg = "";
|
|
||||||
Object value1 = new Object();
|
Object value1 = new Object();
|
||||||
Object value2 = null;
|
Object value2 = null;
|
||||||
|
|
||||||
|
String msg = MessageFormat.format("{0}: {1} != {2}", "", value1, value2);
|
||||||
|
this.exception.expectMessage(msg);
|
||||||
|
|
||||||
DBC.PRE.assertEquals(msg, value1, value2);
|
DBC.PRE.assertEquals(msg, value1, value2);
|
||||||
|
|
||||||
// add additional test code here
|
// add additional test code here
|
||||||
|
@ -150,12 +153,15 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertNotEquals_1() throws Exception {
|
public void testAssertNotEquals_1() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Values are equal:");
|
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
Object value1 = null;
|
Object value1 = null;
|
||||||
Object value2 = null;
|
Object value2 = null;
|
||||||
|
|
||||||
|
String ex = "{0}: {1} == {2}";
|
||||||
|
ex = MessageFormat.format(ex, msg, value1, value2);
|
||||||
|
this.exception.expectMessage(ex);
|
||||||
|
|
||||||
DBC.PRE.assertNotEquals(msg, value1, value2);
|
DBC.PRE.assertNotEquals(msg, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,12 +223,15 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertNotEquals_5() throws Exception {
|
public void testAssertNotEquals_5() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Values are equal:");
|
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
Object value1 = "bla";
|
Object value1 = "bla";
|
||||||
Object value2 = "bla";
|
Object value2 = "bla";
|
||||||
|
|
||||||
|
String ex = "{0}: {1} == {2}";
|
||||||
|
ex = MessageFormat.format(ex, msg, value1, value2);
|
||||||
|
this.exception.expectMessage(ex);
|
||||||
|
|
||||||
DBC.PRE.assertNotEquals(msg, value1, value2);
|
DBC.PRE.assertNotEquals(msg, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,11 +388,14 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertNotNull_1() throws Exception {
|
public void testAssertNotNull_1() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Illegal null value:");
|
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
Object value = null;
|
Object value = null;
|
||||||
|
|
||||||
|
String ex = "{0}: Illegal null value";
|
||||||
|
ex = MessageFormat.format(ex, msg, value);
|
||||||
|
this.exception.expectMessage(ex);
|
||||||
|
|
||||||
DBC.PRE.assertNotNull(msg, value);
|
DBC.PRE.assertNotNull(msg, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,11 +426,12 @@ public class DBCTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAssertNull_1() throws Exception {
|
public void testAssertNull_1() throws Exception {
|
||||||
this.exception.expect(DbcException.class);
|
this.exception.expect(DbcException.class);
|
||||||
this.exception.expectMessage("Illegal situation as value is not null:");
|
|
||||||
|
|
||||||
String msg = "";
|
|
||||||
Object value = new Object();
|
Object value = new Object();
|
||||||
|
|
||||||
|
String msg = MessageFormat.format("{0}: {1} != null", "", value);
|
||||||
|
this.exception.expectMessage(msg);
|
||||||
|
|
||||||
DBC.PRE.assertNull(msg, value);
|
DBC.PRE.assertNull(msg, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue