This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FYI: Patch: javax.print.attribute.standard - first bunch of classes


--- Michael Koch <konqueror@gmx.de> wrote: 

> I commited the first bunch of classes for javax.print.attribute.standard. Ten 
> classes commited, 62 to finish the package.
> 
> Jörg: Can you please have a look at them again ?

Yes, fortunately today I've got some spare time ;-) Although I would like to
review your code more frequently I can't promise to do so because of time 
restrictions. Please don't rely on my review. The code looks ok, though. 
It doesn't contain much logic. But you might want to change the error message 

      throw new IllegalArgumentException("value may not be less then 1");

and use 'than' rather than 'then'.

1. Is it possible to disable the compilation of the javax.print.* package in 
order to shrink compilation time and library size?

2. Did you ever consider to write test cases for your code? Running test cases 
without errors gives you confidence in your own code during initial checkin and 
after code changes in the future. You might even want to start writing test code 
first against an api specification and then start the api implementation. As an 
example how to achieve this I wrote the following two JUnit-Tests against Copies.java 
and HashAttributeSet.java. Please find them below.

Thanks for your work, Jörg

------------------------------------------------------------------

import javax.print.attribute.IntegerSyntax;
import javax.print.attribute.PrintJobAttribute;
import javax.print.attribute.PrintRequestAttribute;

import junit.framework.TestCase;

public class CopiesTest extends TestCase {

    private Copies copies;
    
    public CopiesTest(String name) {
        super(name);
    }
    
    public void setUp(){
        copies = new Copies(1);
    }

    public void testHierarchy() {
        assertEquals(true, copies instanceof PrintJobAttribute);
        assertEquals(true, copies instanceof PrintRequestAttribute);
        assertEquals(true, copies instanceof IntegerSyntax);
    }
    
    public void testGetName() {
        assertEquals("copies", copies.getName());
    }

    public void testGetCateory() {
        assertEquals(Copies.class, copies.getCategory());
    }

    public void testNotEqualsSameObject() {
        assertEquals(false, copies.equals(new Copies(2)));
    }

    public void testNotEqualsNotSameObject() {
        assertEquals(false, copies.equals(new Object()));
    }

    public void testNotEqualsNull() {
        assertEquals(false, copies.equals(null));
    }
    
    public void testEqualsSameObject() {
        assertEquals(true, copies.equals(copies));
    }

    public void testEqualsNotSameObject() {
        assertEquals(true, copies.equals(new Copies(1)));
    }

    public void testHashcode() {
        assertEquals(1, copies.hashCode());
    }

    public void testGetValue() {
        assertEquals(1, copies.getValue());
    }

    public void testToString() {
        assertEquals("1", copies.toString());
    }

    public void testConstructor() {
        try {
            new Copies(-1);
            fail("Should throw an exception");
        } catch (IllegalArgumentException e) {
            // ok
        }
    }

    public static void main (String[] args) {
        junit.textui.TestRunner.run (
            new junit.framework.TestSuite(CopiesTest.class)
        );
    }

}

-----------------------------------------------------------------

import javax.print.attribute.Attribute;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;

import junit.framework.TestCase;

public class AttributeSetTest extends TestCase {
    
    HashAttributeSet attributeSet = new HashAttributeSet();
    
    private static class DummyAttribute implements Attribute {
        public final Class getCategory() {
          return DummyAttribute.class;
        }

        public final String getName() {
          return "dummy";
        }
    }
    
    private static class DummyAttribute1 implements Attribute {
        public final Class getCategory() {
          return DummyAttribute1.class;
        }

        public final String getName() {
          return "dummy1";
        }
    }
    
    public AttributeSetTest(String name) {
        super(name);
    }
    
    public void setUp(){
        attributeSet = new HashAttributeSet();
    }

    public void testContainsKey1() {
        assertEquals(false, attributeSet.containsKey(DummyAttribute.class));
    }

    public void testContainsKey2() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(true, set.containsKey(a.getClass()));
    }

    public void testContainsValue1() {
        assertEquals(false, attributeSet.containsValue(new DummyAttribute()));
    }

    public void testContainsValue2() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(true, set.containsValue(a));
        assertEquals(false, set.containsValue(new DummyAttribute()));
        assertEquals(false, set.containsValue(new DummyAttribute1()));
    }

    public void testGet() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(a, set.get(a.getClass()));
    }

    public void testIsEmpty1() {
        assertEquals(true, attributeSet.isEmpty());
    }

    public void testIsEmpty2() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(false, set.isEmpty());
    }
    
    public void testConstructors() {
        try {
            new HashAttributeSet((Attribute)null);
            new HashAttributeSet((Attribute[])null);
            new HashAttributeSet((AttributeSet)null);
            fail("Should throw an exception");
        } catch (NullPointerException e) {
            // ok
        }
    }

    public void testAddAndClear() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(1, set.size());
        boolean b = set.add(a);
        assertEquals(1, set.size());
        assertEquals(false, b);
        b = set.add(new DummyAttribute());
        assertEquals(1, set.size());
        assertEquals(true, b);
        set.clear();
        assertEquals(0, set.size());
    }

    public void testAddAndRemove() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        assertEquals(1, set.size());
        set.remove(a);
        assertEquals(0, set.size());
    }

    public void testAdd() {
        HashAttributeSet set = new HashAttributeSet(new DummyAttribute1());
        assertEquals(1, set.size());
        boolean b = set.add(new DummyAttribute());
        assertEquals(2, set.size());
        assertEquals(true, b);
    }

    public void testAdd3() {
        try {
            HashAttributeSet set = new HashAttributeSet(new DummyAttribute1());
            set.add((Attribute) null);
            fail("Should throw an exception");
        } catch (NullPointerException e) {
            // ok
        }
    }

    public void testToArray() {
        DummyAttribute a = new DummyAttribute();
        HashAttributeSet set = new HashAttributeSet(a);
        Attribute [] array = set.toArray();
        assertEquals(1, array.length);
        assertEquals(true, array[0] instanceof DummyAttribute);
    }

}

  

__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]