Skip to content

Commit

Permalink
feat: cover the case of chunked case for getTotalOffset and getTotalL…
Browse files Browse the repository at this point in the history
…ength on BreakpointInfo

refs #35
  • Loading branch information
Jacksgong committed Apr 26, 2018
1 parent ba0e85a commit 225945c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,14 @@ public long getTotalOffset() {
final int count = list.size();
for (int i = 0; i < count; i++) {
final BlockInfo info = list.get(i);
long cOffset = info.getCurrentOffset();
if (i == 0) {
if (cOffset > info.getContentLength()) {
offset = info.getContentLength();
} else {
offset = cOffset;
}
} else {
offset += cOffset;
}
offset += info.getCurrentOffset();
}
return offset;
}

public long getTotalLength() {
if (isChunked()) return getTotalOffset();

long length = 0;
ArrayList<BlockInfo> list = (ArrayList<BlockInfo>) ((ArrayList) blockInfoList).clone();
for (BlockInfo info : list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.io.File;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

public class BreakpointInfoTest {
Expand Down Expand Up @@ -54,12 +56,20 @@ public void copyNotClone() {
@Test
public void getTotalOffset() {
BreakpointInfo info = new BreakpointInfo(0, "", new File(""), null);
info.addBlock(new BlockInfo(0, 10, 12));
info.addBlock(new BlockInfo(0, 10, 10));
info.addBlock(new BlockInfo(10, 18, 18));
info.addBlock(new BlockInfo(28, 66, 66));
assertThat(info.getTotalOffset()).isEqualTo(94);
}

@Test
public void getTotalLength_chunked() {
BreakpointInfo info = spy(new BreakpointInfo(0, "", new File(""), null));
when(info.isChunked()).thenReturn(true);
doReturn(1L).when(info).getTotalOffset();
assertThat(info.getTotalLength()).isEqualTo(1L);
}

@Test
public void getTotalLength() {
BreakpointInfo info = new BreakpointInfo(0, "", new File(""), null);
Expand Down

0 comments on commit 225945c

Please sign in to comment.