add some generics (removes warnings) and bump junit to 4.11
This commit is contained in:
parent
053d532655
commit
12945ed615
3 changed files with 41 additions and 24 deletions
2
pom.xml
2
pom.xml
|
|
@ -133,7 +133,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.7</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,13 @@ public class FlvMetadata {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void merge(Attr<?> other) {
|
||||||
|
if (other != null && other.getClass() == getClass()) {
|
||||||
|
set((T)other.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void write(OutputStream out) throws IOException;
|
public abstract void write(OutputStream out) throws IOException;
|
||||||
|
|
||||||
public boolean isPresent() {
|
public boolean isPresent() {
|
||||||
|
|
@ -249,7 +256,7 @@ public class FlvMetadata {
|
||||||
|
|
||||||
private LinkedList<Keyframe> keyframes = new LinkedList<Keyframe>();
|
private LinkedList<Keyframe> keyframes = new LinkedList<Keyframe>();
|
||||||
|
|
||||||
private ArrayList<Attr> attrs = new ArrayList<Attr>();
|
private ArrayList<Attr<?>> attrs = new ArrayList<Attr<?>>();
|
||||||
|
|
||||||
public FlvMetadata() {
|
public FlvMetadata() {
|
||||||
|
|
||||||
|
|
@ -304,7 +311,7 @@ public class FlvMetadata {
|
||||||
|
|
||||||
private int length() {
|
private int length() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Attr a : attrs) {
|
for (Attr<?> a : attrs) {
|
||||||
if (a.isPresent()) {
|
if (a.isPresent()) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
@ -355,7 +362,7 @@ public class FlvMetadata {
|
||||||
out.write(2); // string
|
out.write(2); // string
|
||||||
writeFlvString(out, "onMetaData");
|
writeFlvString(out, "onMetaData");
|
||||||
writeFlvEcmaArray(out, length());
|
writeFlvEcmaArray(out, length());
|
||||||
for (Attr a : attrs) {
|
for (Attr<?> a : attrs) {
|
||||||
if (a.isPresent()) {
|
if (a.isPresent()) {
|
||||||
if (a.name != null) {
|
if (a.name != null) {
|
||||||
writeFlvString(out, a.name);
|
writeFlvString(out, a.name);
|
||||||
|
|
@ -499,10 +506,10 @@ public class FlvMetadata {
|
||||||
public void merge(FlvMetadata other) {
|
public void merge(FlvMetadata other) {
|
||||||
|
|
||||||
for (int i = 0; i < attrs.size(); i++) {
|
for (int i = 0; i < attrs.size(); i++) {
|
||||||
Attr their = other.attrs.get(i);
|
Attr<?> their = other.attrs.get(i);
|
||||||
if (their.isPresent()) {
|
if (their.isPresent()) {
|
||||||
Attr our = this.attrs.get(i);
|
Attr<?> our = this.attrs.get(i);
|
||||||
our.set(their.value);
|
our.merge(their);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +519,7 @@ public class FlvMetadata {
|
||||||
if (prop == null) {
|
if (prop == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Attr a : attrs) {
|
for (Attr<?> a : attrs) {
|
||||||
if (prop.equals(a.name) && a.isPresent()) {
|
if (prop.equals(a.name) && a.isPresent()) {
|
||||||
return a.value;
|
return a.value;
|
||||||
}
|
}
|
||||||
|
|
@ -637,7 +644,7 @@ public class FlvMetadata {
|
||||||
protected void readProperty(InputStream in) throws FlvFormatException, IOException {
|
protected void readProperty(InputStream in) throws FlvFormatException, IOException {
|
||||||
|
|
||||||
String name = readString(in);
|
String name = readString(in);
|
||||||
Attr attr = findAttrByName(name);
|
Attr<?> attr = findAttrByName(name);
|
||||||
if (attr != null) {
|
if (attr != null) {
|
||||||
attr.read(in);
|
attr.read(in);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -660,8 +667,8 @@ public class FlvMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Attr findAttrByName(String name) {
|
private Attr<?> findAttrByName(String name) {
|
||||||
for (Attr a : this.attrs) {
|
for (Attr<?> a : this.attrs) {
|
||||||
if (name.equals(a.name)) {
|
if (name.equals(a.name)) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
@ -716,8 +723,8 @@ public class FlvMetadata {
|
||||||
}
|
}
|
||||||
FlvMetadata other = (FlvMetadata)o;
|
FlvMetadata other = (FlvMetadata)o;
|
||||||
for (int i = 0; i < attrs.size(); i++) {
|
for (int i = 0; i < attrs.size(); i++) {
|
||||||
Attr their = other.attrs.get(i);
|
Attr<?> their = other.attrs.get(i);
|
||||||
Attr our = this.attrs.get(i);
|
Attr<?> our = this.attrs.get(i);
|
||||||
if (our.isPresent() && their.isPresent()) {
|
if (our.isPresent() && their.isPresent()) {
|
||||||
if (!our.value.equals(their.value)) {
|
if (!our.value.equals(their.value)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -733,7 +740,7 @@ public class FlvMetadata {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (Attr a : attrs) {
|
for (Attr<?> a : attrs) {
|
||||||
x *= 13;
|
x *= 13;
|
||||||
x += a.present ? a.value.hashCode() : 7;
|
x += a.present ? a.value.hashCode() : 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,14 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.forkalsrud.album.exif.Dimension;
|
import org.forkalsrud.album.exif.Dimension;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
|
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||||
|
|
||||||
public class FlvMetadataTest extends TestCase {
|
public class FlvMetadataTest {
|
||||||
|
|
||||||
private ByteArrayOutputStream out = new ByteArrayOutputStream();
|
private ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
private ByteArrayInputStream in;
|
private ByteArrayInputStream in;
|
||||||
|
|
@ -19,6 +23,7 @@ public class FlvMetadataTest extends TestCase {
|
||||||
out.reset();
|
out.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMerge() throws Exception {
|
public void testMerge() throws Exception {
|
||||||
|
|
||||||
FlvMetadata md1 = new FlvMetadata();
|
FlvMetadata md1 = new FlvMetadata();
|
||||||
|
|
@ -27,19 +32,20 @@ public class FlvMetadataTest extends TestCase {
|
||||||
|
|
||||||
FlvMetadata md2 = new FlvMetadata();
|
FlvMetadata md2 = new FlvMetadata();
|
||||||
md2.merge(md1);
|
md2.merge(md1);
|
||||||
assertEquals(Double.valueOf("3.14"), md2.get("duration"));
|
assertEquals(3.14d, md2.get("duration"));
|
||||||
assertEquals(Double.valueOf("5"), md2.get("width"));
|
assertEquals(5d, md2.get("width"));
|
||||||
assertEquals(Double.valueOf("6"), md2.get("height"));
|
assertEquals(6d, md2.get("height"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadWriteDouble() throws Exception {
|
public void testReadWriteDouble() throws Exception {
|
||||||
|
|
||||||
double value = 3.14;
|
double value = 3.14;
|
||||||
md0.writeDouble(out, value);
|
md0.writeDouble(out, value);
|
||||||
flip();
|
flip();
|
||||||
assertEquals(value, md0.readDouble(in));
|
assertThat(md0.readDouble(in), equalTo(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadWriteInt() throws Exception {
|
public void testReadWriteInt() throws Exception {
|
||||||
int value = 45;
|
int value = 45;
|
||||||
// uint16
|
// uint16
|
||||||
|
|
@ -63,6 +69,7 @@ public class FlvMetadataTest extends TestCase {
|
||||||
assertEquals(value, md0.readTimestamp(in));
|
assertEquals(value, md0.readTimestamp(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadWriteString() throws Exception {
|
public void testReadWriteString() throws Exception {
|
||||||
String value = "awsome";
|
String value = "awsome";
|
||||||
md0.writeFlvString(out, value);
|
md0.writeFlvString(out, value);
|
||||||
|
|
@ -70,6 +77,7 @@ public class FlvMetadataTest extends TestCase {
|
||||||
assertEquals(value, md0.readString(in));
|
assertEquals(value, md0.readString(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWriteReadMetadata() throws Exception {
|
public void testWriteReadMetadata() throws Exception {
|
||||||
|
|
||||||
FlvMetadata md1 = new FlvMetadata();
|
FlvMetadata md1 = new FlvMetadata();
|
||||||
|
|
@ -88,6 +96,7 @@ public class FlvMetadataTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadWriteMetadata() throws Exception {
|
public void testReadWriteMetadata() throws Exception {
|
||||||
|
|
||||||
InputStream is = getClass().getResourceAsStream("/VideoAd.flv");
|
InputStream is = getClass().getResourceAsStream("/VideoAd.flv");
|
||||||
|
|
@ -105,12 +114,13 @@ public class FlvMetadataTest extends TestCase {
|
||||||
assertEquals(md1, md2);
|
assertEquals(md1, md2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetDuration() {
|
public void testSetDuration() {
|
||||||
FlvMetadata m = new FlvMetadata();
|
FlvMetadata m = new FlvMetadata();
|
||||||
m.setDuration("1:02:03");
|
m.setDuration("1:02:03");
|
||||||
Object o = m.get("duration");
|
Object o = m.get("duration");
|
||||||
assertTrue(o.getClass() == Double.class);
|
assertThat(o, instanceOf(Double.class));
|
||||||
Double durationSeconds = (Double) o;
|
Double durationSeconds = (Double) o;
|
||||||
assertEquals(3600 + 2*60 + 3, durationSeconds.intValue());
|
assertThat(durationSeconds.intValue(), equalTo(3600 + 2*60 + 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue