001: package org.drools.base.extractors;
002:
003: import junit.framework.Assert;
004:
005: import org.drools.base.ClassFieldExtractorCache;
006: import org.drools.base.TestBean;
007: import org.drools.spi.Extractor;
008:
009: public class IntClassFieldExtractorTest extends
010: BaseClassFieldExtractorsTest {
011: private static final int VALUE = 4;
012:
013: Extractor extractor = ClassFieldExtractorCache.getExtractor(
014: TestBean.class, "intAttr", getClass().getClassLoader());
015: TestBean bean = new TestBean();
016:
017: protected void setUp() throws Exception {
018: super .setUp();
019: }
020:
021: public void testGetBooleanValue() {
022: try {
023: this .extractor.getBooleanValue(null, this .bean);
024: fail("Should have throw an exception");
025: } catch (final Exception e) {
026: // success
027: }
028: }
029:
030: public void testGetByteValue() {
031: try {
032: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
033: this .extractor.getByteValue(null, this .bean));
034: } catch (final Exception e) {
035: fail("Should not throw an exception");
036: }
037: }
038:
039: public void testGetCharValue() {
040: try {
041: this .extractor.getCharValue(null, this .bean);
042: fail("Should have throw an exception");
043: } catch (final Exception e) {
044: // success
045: }
046: }
047:
048: public void testGetDoubleValue() {
049: try {
050: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
051: this .extractor.getDoubleValue(null, this .bean),
052: 0.01);
053: } catch (final Exception e) {
054: fail("Should not throw an exception");
055: }
056: }
057:
058: public void testGetFloatValue() {
059: try {
060: Assert
061: .assertEquals(IntClassFieldExtractorTest.VALUE,
062: this .extractor.getFloatValue(null,
063: this .bean), 0.01);
064: } catch (final Exception e) {
065: fail("Should not throw an exception");
066: }
067: }
068:
069: public void testGetIntValue() {
070: try {
071: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
072: this .extractor.getIntValue(null, this .bean));
073: } catch (final Exception e) {
074: fail("Should not throw an exception");
075: }
076: }
077:
078: public void testGetLongValue() {
079: try {
080: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
081: this .extractor.getLongValue(null, this .bean));
082: } catch (final Exception e) {
083: fail("Should not throw an exception");
084: }
085: }
086:
087: public void testGetShortValue() {
088: try {
089: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
090: this .extractor.getShortValue(null, this .bean));
091: } catch (final Exception e) {
092: fail("Should not throw an exception");
093: }
094: }
095:
096: public void testGetValue() {
097: try {
098: Assert.assertEquals(IntClassFieldExtractorTest.VALUE,
099: ((Number) this .extractor.getValue(null, this .bean))
100: .intValue());
101: } catch (final Exception e) {
102: fail("Should not throw an exception");
103: }
104: }
105:
106: public void testIsNullValue() {
107: try {
108: Assert.assertFalse(this .extractor.isNullValue(null,
109: this .bean));
110: } catch (final Exception e) {
111: fail("Should not throw an exception");
112: }
113: }
114: }
|