summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-02-03 22:43:12 +0100
committerByteHamster <info@bytehamster.com>2020-02-04 00:02:15 +0100
commitc524d20cc900104093696c1064f46ad8e4c4bdad (patch)
treecfcc429150ce499a89bdc46ef28a89e2f79a4bb5 /app/src/androidTest/java
parent6a327f252c2074de39841522272ed9448df46443 (diff)
downloadAntennaPod-c524d20cc900104093696c1064f46ad8e4c4bdad.zip
Do not add timecode link if timecode equals duration
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java84
1 files changed, 54 insertions, 30 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java b/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java
index ab049a8e5..59b9ceaca 100644
--- a/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/util/playback/TimelineTest.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
- * Test class for timeline
+ * Test class for timeline.
*/
@SmallTest
public class TimelineTest {
@@ -34,7 +34,7 @@ public class TimelineTest {
private Context context;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
context = InstrumentationRegistry.getTargetContext();
}
@@ -49,128 +49,151 @@ public class TimelineTest {
}
@Test
- public void testProcessShownotesAddTimecodeHHMMSSNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeHHMMSSNoChapters() {
final String timeStr = "10:11:12";
final long time = 3600 * 1000 * 10 + 60 * 1000 * 11 + 12 * 1000;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeHHMMSSMoreThen24HoursNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeHHMMSSMoreThen24HoursNoChapters() {
final String timeStr = "25:00:00";
final long time = 25 * 60 * 60 * 1000;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeHHMMNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeHHMMNoChapters() {
final String timeStr = "10:11";
final long time = 3600 * 1000 * 10 + 60 * 1000 * 11;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeMMSSNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeMMSSNoChapters() {
final String timeStr = "10:11";
final long time = 10 * 60 * 1000 + 11 * 1000;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 11 * 60 * 1000);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", 11 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeHMMSSNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeHMMSSNoChapters() {
final String timeStr = "2:11:12";
final long time = 2 * 60 * 60 * 1000 + 11 * 60 * 1000 + 12 * 1000;
-
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeMSSNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeMSSNoChapters() {
final String timeStr = "1:12";
final long time = 60 * 1000 + 12 * 1000;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 2 * 60 * 1000);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStr + " here.</p>", 2 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeMultipleFormatsNoChapters() throws Exception {
+ public void testProcessShownotesAddNoTimecodeDuration() {
+ final String timeStr = "2:11:12";
+ final int time = 2 * 60 * 60 * 1000 + 11 * 60 * 1000 + 12 * 1000;
+ String originalText = "<p> Some test text with a timecode " + timeStr + " here.</p>";
+ Playable p = newTestPlayable(null, originalText, time);
+ Timeline t = new Timeline(context, p);
+ String res = t.processShownotes();
+ Document d = Jsoup.parse(res);
+ assertEquals("Should not parse time codes that equal duration", 0, d.body().getElementsByTag("a").size());
+ }
+
+ @Test
+ public void testProcessShownotesAddTimecodeMultipleFormatsNoChapters() {
final String[] timeStrings = new String[]{ "10:12", "1:10:12" };
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 2 * 60 * 60 * 1000);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 2 * 60 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
- checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 60 * 60 * 1000 + 10 * 60 * 1000 + 12 * 1000 }, timeStrings);
+ checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000,
+ 60 * 60 * 1000 + 10 * 60 * 1000 + 12 * 1000 }, timeStrings);
}
@Test
- public void testProcessShownotesAddTimecodeMultipleShortFormatNoChapters() throws Exception {
+ public void testProcessShownotesAddTimecodeMultipleShortFormatNoChapters() {
// One of these timecodes fits as HH:MM and one does not so both should be parsed as MM:SS.
final String[] timeStrings = new String[]{ "10:12", "2:12" };
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 3 * 60 * 60 * 1000);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode "
+ + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 3 * 60 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 2 * 60 * 1000 + 12 * 1000 }, timeStrings);
}
@Test
- public void testProcessShownotesAddTimecodeParentheses() throws Exception {
+ public void testProcessShownotesAddTimecodeParentheses() {
final String timeStr = "10:11";
final long time = 3600 * 1000 * 10 + 60 * 1000 * 11;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode (" + timeStr + ") here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode ("
+ + timeStr + ") here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeBrackets() throws Exception {
+ public void testProcessShownotesAddTimecodeBrackets() {
final String timeStr = "10:11";
final long time = 3600 * 1000 * 10 + 60 * 1000 * 11;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode [" + timeStr + "] here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode ["
+ + timeStr + "] here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAddTimecodeAngleBrackets() throws Exception {
+ public void testProcessShownotesAddTimecodeAngleBrackets() {
final String timeStr = "10:11";
final long time = 3600 * 1000 * 10 + 60 * 1000 * 11;
- Playable p = newTestPlayable(null, "<p> Some test text with a timecode <" + timeStr + "> here.</p>", Integer.MAX_VALUE);
+ Playable p = newTestPlayable(null, "<p> Some test text with a timecode <"
+ + timeStr + "> here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@Test
- public void testProcessShownotesAndInvalidTimecode() throws Exception {
+ public void testProcessShownotesAndInvalidTimecode() {
final String[] timeStrs = new String[] {"2:1", "0:0", "000", "00", "00:000"};
StringBuilder shownotes = new StringBuilder("<p> Some test text with timecodes ");
@@ -197,14 +220,15 @@ public class TimelineTest {
assertTrue(href.endsWith(String.valueOf(timecodes[countedLinks])));
assertEquals(timecodeStr[countedLinks], text);
countedLinks++;
- assertTrue("Contains too many links: " + countedLinks + " > " + timecodes.length, countedLinks <= timecodes.length);
+ assertTrue("Contains too many links: " + countedLinks + " > "
+ + timecodes.length, countedLinks <= timecodes.length);
}
}
assertEquals(timecodes.length, countedLinks);
}
@Test
- public void testIsTimecodeLink() throws Exception {
+ public void testIsTimecodeLink() {
assertFalse(Timeline.isTimecodeLink(null));
assertFalse(Timeline.isTimecodeLink("http://antennapod/timecode/123123"));
assertFalse(Timeline.isTimecodeLink("antennapod://timecode/"));
@@ -215,7 +239,7 @@ public class TimelineTest {
}
@Test
- public void testGetTimecodeLinkTime() throws Exception {
+ public void testGetTimecodeLinkTime() {
assertEquals(-1, Timeline.getTimecodeLinkTime(null));
assertEquals(-1, Timeline.getTimecodeLinkTime("http://timecode/123"));
assertEquals(123, Timeline.getTimecodeLinkTime("antennapod://timecode/123"));