Skip to content

Commit

Permalink
Allow to set some arbitrary data on Streams
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Sep 13, 2020
1 parent 880ad62 commit 95cea46
Showing 2 changed files with 36 additions and 11 deletions.
18 changes: 17 additions & 1 deletion src/main/java/org/dstadler/audio/stream/Stream.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ public enum StreamType {
private String user;
private long startTimestamp;
private long duration;
private String data;

public String getName() {
return name;
@@ -122,6 +123,20 @@ public void setDuration(long duration) {
this.duration = duration;
}

public String getData() {
return data;
}

/**
* Allows to attach some arbitrary data to a stream, e.g.
* to determine which radio-show was playing.
*
* @param data some application-specific data as string.
*/
public void setData(String data) {
this.data = data;
}

/**
* Verifies if the Stream is valid and throws an exception if not.
*
@@ -157,6 +172,7 @@ public String toString() {
", tempoStrategy=" + tempoStrategy +
", tempo=" + tempo +
", streamType=" + streamType +
", user=" + user;
", user=" + user +
", data=" + data;
}
}
29 changes: 19 additions & 10 deletions src/test/java/org/dstadler/audio/stream/StreamTest.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public void test() throws IOException {
assertNull(stream.getStreamType());
assertNull(stream.getUser());
assertNull(stream.getPassword());
assertNull(stream.getData());
assertEquals(0, stream.getStartTimestamp());
assertEquals(0, stream.getDuration());
TestHelpers.ToStringTest(stream);
@@ -93,20 +94,28 @@ public void test() throws IOException {
assertEquals("", stream.getUser());
assertNull(stream.getPassword());

stream.setUser("someuser");
try {
assertNull(stream.getPassword());

TestHelpers.ToStringTest(stream);
} catch (FileNotFoundException e) {
Assume.assumeNoException("Credentials file not available, cannot test for password",
e);
}

stream.setStartTimestamp(1L);
stream.setDuration(2L);
assertEquals(1L, stream.getStartTimestamp());
assertEquals(2L, stream.getDuration());

stream.setData("123");
assertEquals("123", stream.getData());
}

@Test
public void testCredentials() throws IOException {
Stream stream = new Stream();

stream.setUser("someuser");
try {
assertNull(stream.getPassword());

TestHelpers.ToStringTest(stream);
} catch (FileNotFoundException e) {
Assume.assumeNoException("Credentials file not available, cannot test for password",
e);
}
}

@Test

0 comments on commit 95cea46

Please sign in to comment.