Skip to content

Commit

Permalink
Merge branch 'pr-30'
Browse files Browse the repository at this point in the history
This closes #30
  • Loading branch information
kinow committed Nov 10, 2019
2 parents 51a40b3 + 4ed1022 commit f2aed4c
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/test/java/org/apache/commons/imaging/color/ColorCmyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
Expand Down Expand Up @@ -56,8 +57,19 @@ public void testToString() throws Exception {
}

@Test
public void testHashCodeAndEquals() throws Exception {
public void testCreatesColorCmy() {
ColorCmy colorCmy = new ColorCmy(0.0, (-1668.733868772), (-1568.733868772));
ColorCmy colorCmyTwo = ColorCmy.YELLOW;

assertFalse(colorCmy.equals(colorCmyTwo));
assertEquals((-1568.733868772), colorCmy.Y, 0.01);
assertEquals((-1668.733868772), colorCmy.M, 0.01);
}

@Test
public void testEquals() {
assertTrue(color.equals(colorCopy) && colorCopy.equals(color));
assertThat(color.hashCode(), is(colorCopy.hashCode()));
}

}
13 changes: 13 additions & 0 deletions src/test/java/org/apache/commons/imaging/color/ColorHslTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
Expand Down Expand Up @@ -60,4 +61,16 @@ public void testHashCodeAndEquals() throws Exception {
assertTrue(color.equals(colorCopy) && colorCopy.equals(color));
assertThat(color.hashCode(), is(colorCopy.hashCode()));
}

@Test
public void testCreatesColorHslOne() {
ColorHsl colorHsl = ColorHsl.BLUE;
ColorHsl colorHslTwo = new ColorHsl(100.0, 667.226, (-687.72287636));

assertEquals(667.226, colorHslTwo.S, 0.01);
assertEquals(100.0, colorHslTwo.H, 0.01);
assertEquals((-687.72287636), colorHslTwo.L, 0.01);
assertFalse(colorHsl.equals(colorHslTwo));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.jpeg.decoder;

import java.io.IOException;

import org.apache.commons.imaging.ImageReadException;
import org.junit.Test;

/**
* Unit tests for class {@link JpegInputStream}.
* @see JpegInputStream
**/
public class JpegInputStreamTest {

@Test(expected = ImageReadException.class)
public void testNextBitThrowsImageReadExceptionOne() throws IOException, ImageReadException {
int[] byteArray = new int[6];
byteArray[0] = (byte) (-1);
byteArray[1] = (byte) 74;
JpegInputStream jpegInputStream = new JpegInputStream(byteArray);

jpegInputStream.nextBit();

}

@Test(expected = IllegalStateException.class)
public void testNextBitThrowsImageReadExceptionTwo() throws IOException, ImageReadException {
int[] byteArray = new int[0];
JpegInputStream jpegInputStream = new JpegInputStream(byteArray);

jpegInputStream.nextBit();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.jpeg.segments;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.apache.commons.imaging.ImageReadException;
import org.junit.Test;

/**
* Unit tests for class {@link App2Segment}.
* @see App2Segment
**/
public class App2SegmentTest {

@Test
public void testEqualsReturningTrue() throws IOException, ImageReadException {
App2Segment app2Segment = new App2Segment(0, 0, null);

assertTrue(app2Segment.equals(app2Segment));
}

@Test
public void testEqualsReturningFalse() throws IOException, ImageReadException {
byte[] byteArray = new byte[3];
App2Segment app2Segment = new App2Segment(65475, byteArray);

assertFalse(app2Segment.equals(byteArray));
}

@Test
public void testCompareTo() throws IOException, ImageReadException {
App2Segment app2Segment = new App2Segment(0, 0, null);

assertEquals(0, app2Segment.compareTo(app2Segment));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.pnm;

import static org.junit.Assert.assertEquals;

import org.apache.commons.imaging.ImageReadException;
import org.junit.Test;

public class PgmFileInfoTest {

@Test(expected = ImageReadException.class)
public void testCreateThrowsImageReadExceptionOne() throws ImageReadException {
new PgmFileInfo(16711680, 16711680, false, 16711680);
}

@Test(expected = ImageReadException.class)
public void testCreateThrowsImageReadExceptionTwo() throws ImageReadException {
new PgmFileInfo(0, 0, true, 0);
}

@Test
public void testGetBitDepth() throws ImageReadException {
PgmFileInfo pgmFileInfo = new PgmFileInfo(65535, 65535, false, 65535);

assertEquals(65535, pgmFileInfo.getBitDepth());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.pnm;

import org.apache.commons.imaging.ImageReadException;
import org.junit.Test;

/**
* Unit tests for class {@link PpmFileInfo}.
* @see PpmFileInfo
*
**/
public class PpmFileInfoTest {

@Test(expected = ImageReadException.class)
public void testCreatesPpmFileInfoOne() throws ImageReadException {
new PpmFileInfo(0, 0, false, 16711680);
}

@Test(expected = ImageReadException.class)
public void testCreatesPpmFileInfoThree() throws ImageReadException {
new PpmFileInfo(0, 0, true, 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.tiff.fieldtypes;

import static org.junit.Assert.assertArrayEquals;

import java.nio.ByteOrder;

import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.formats.tiff.TiffField;
import org.junit.Test;

/**
* Unit tests for class {@link FieldTypeAscii}.
* @see FieldTypeAscii
*
**/
public class FieldTypeAsciiTest {

@Test(expected = ImageWriteException.class)
public void testCreatesFieldTypeAsciiAndCallsWriteData() throws ImageWriteException {
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1");
byte[] byteArray = new byte[1];
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
TiffField tiffField = new TiffField(0, 0, fieldTypeAscii, 0L, 0, byteArray, byteOrder, 1);

fieldTypeAscii.writeData(tiffField, byteOrder);

}

@Test
public void testCreatesFieldTypeAsciiAndWriteDataUsingByteArray() throws ImageWriteException {
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1");
byte[] byteArray = new byte[1];
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
byte[] byteArrayTwo = fieldTypeAscii.writeData(byteArray, byteOrder);

assertArrayEquals(new byte[] {(byte)0, (byte)0}, byteArrayTwo);
}

@Test
public void testCreatesFieldTypeAsciiAndWriteDataUsingString() throws ImageWriteException {
FieldTypeAscii fieldTypeAscii = new FieldTypeAscii(0, "1");
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
byte[] byteArrayTwo = fieldTypeAscii.writeData("asdf", byteOrder);

assertArrayEquals(new byte[] {(byte)97, (byte)115, (byte)100, (byte)102, (byte)0}, byteArrayTwo);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.tiff.fieldtypes;

import static org.junit.Assert.assertArrayEquals;

import java.nio.ByteOrder;

import org.apache.commons.imaging.ImageWriteException;
import org.junit.Test;

/**
* Unit tests for class {@link FieldTypeRational}.
* @see FieldTypeRational
*
**/
public class FieldTypeRationalTest {

@Test
public void testWriteDataWithNull() throws ImageWriteException {
FieldTypeRational fieldTypeRational = new FieldTypeRational(9, null);
Double doubleOne = new Double(2.2);
byte[] byteArray = fieldTypeRational.writeData(doubleOne, null);

assertArrayEquals(new byte[] {(byte)11, (byte)0, (byte)0, (byte)0, (byte)5, (byte)0, (byte)0, (byte)0}, byteArray);
}

@Test(expected = ImageWriteException.class)
public void testWriteDataWithNonNull() throws ImageWriteException {
FieldTypeRational fieldTypeRational = new FieldTypeRational((-922), "z_AX");
ByteOrder byteOrder = ByteOrder.nativeOrder();

fieldTypeRational.writeData("z_AX", byteOrder);

}

}

0 comments on commit f2aed4c

Please sign in to comment.