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