1 package org.dbunit.assertion.comparer.value;
2
3 import org.dbunit.DatabaseUnitException;
4 import org.dbunit.dataset.ITable;
5 import org.dbunit.dataset.datatype.DataType;
6 import org.dbunit.dataset.datatype.TypeCastException;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10
11
12
13
14
15
16
17
18
19 public class IsActualContainingExpectedStringValueComparer
20 extends ValueComparerTemplateBase
21 {
22 private final Logger log = LoggerFactory.getLogger(getClass());
23
24 @Override
25 protected boolean isExpected(final ITable expectedTable,
26 final ITable actualTable, final int rowNum, final String columnName,
27 final DataType dataType, final Object expectedValue,
28 final Object actualValue) throws DatabaseUnitException
29 {
30 final boolean isExpected;
31
32
33 if (expectedValue == null && actualValue == null)
34 {
35
36 isExpected = true;
37 } else if (expectedValue == null || actualValue == null)
38 {
39
40 isExpected = false;
41 } else
42 {
43
44 isExpected = isContaining(expectedValue, actualValue);
45 }
46
47 return isExpected;
48 }
49
50 protected boolean isContaining(final Object expectedValue,
51 final Object actualValue) throws TypeCastException
52 {
53 final String expectedValueString = DataType.asString(expectedValue);
54 final String actualValueString = DataType.asString(actualValue);
55 log.debug("isContaining: expectedValueString={}, actualValueString={}",
56 expectedValueString, actualValueString);
57
58 return actualValueString.contains(expectedValueString);
59 }
60
61 @Override
62 protected String getFailPhrase()
63 {
64 return "not containing";
65 }
66 }