Aiff implements Chunk { public ID getChunkID() { return chunkId; } private  Aiff(); ID getChunkID(); @Override int getPhysicalSize(); SignedLong getChunkSize(); ID getFormType(); Map<ID, List<Chunk>> getChunksMap(); List<Chunk> getChunks(ID chunkId); boolean hasChunk(ChunkType chunkType); Chunk getChunk(ID chunkId); CommonChunk getCommonChunk(); boolean hasCommonChunk(); SoundDataChunk getSoundDataChunk(); boolean hasSoundDataChunk(); @Override String toString();  }
@Test(expected = IllegalStateException.class) public void cannotAddMultipleCommonChunks() throws Exception { CommonChunk commonChunk1 = TestChunks.commonChunkOneSampleFrame16BitMono(); CommonChunk commonChunk2 = TestChunks.commonChunkOneSampleFrame16BitMono(); SoundDataChunk soundDataChunk = TestChunks.soundDataChunkOneSampleFrame16BitMono(); new Aiff.Builder() .withChunkId(new ID("FORM".getBytes())) .withChunkSize(SignedLong.fromInt(42)) .withFormType(new ID("AIFF".getBytes())) .withChunk(COMMON.getChunkId(), commonChunk1) .withChunk(COMMON.getChunkId(), commonChunk2) .withChunk(SOUND_DATA.getChunkId(), soundDataChunk) .build(); }
@Test(expected = IllegalStateException.class) public void cannotAddMultipleSoundDataChunks() throws Exception { CommonChunk commonChunk = TestChunks.commonChunkOneSampleFrame16BitMono(); SoundDataChunk soundDataChunk1 = TestChunks.soundDataChunkOneSampleFrame16BitMono(); SoundDataChunk soundDataChunk2 = TestChunks.soundDataChunkOneSampleFrame16BitMono(); new Aiff.Builder() .withChunkId(new ID("FORM".getBytes())) .withChunkSize(SignedLong.fromInt(42)) .withFormType(new ID("AIFF".getBytes())) .withChunk(COMMON.getChunkId(), commonChunk) .withChunk(SOUND_DATA.getChunkId(), soundDataChunk1) .withChunk(SOUND_DATA.getChunkId(), soundDataChunk2) .build(); }
@Test public void canHaveZeroSoundDataChunksWhenNumSampleFramesIsZero() throws Exception { CommonChunk commonChunk = TestChunks.commonChunkZeroSampleFrames8BitMono(); Aiff aiff = new Aiff.Builder() .withChunkId(new ID("FORM".getBytes())) .withChunkSize(SignedLong.fromInt(22)) .withFormType(new ID("AIFF".getBytes())) .withChunk(COMMON.getChunkId(), commonChunk) .build(); assertThat(aiff, notNullValue()); }
@Test public void canHaveSoundDataChunksEvenWhenNumSampleFramesIsZero() throws Exception { CommonChunk commonChunk = TestChunks.commonChunkZeroSampleFrames8BitMono(); SoundDataChunk soundDataChunk = TestChunks.soundDataChunkOneSampleFrame16BitMono(); Aiff aiff = new Aiff.Builder() .withChunkId(new ID("FORM".getBytes())) .withChunkSize(SignedLong.fromInt(32)) .withFormType(new ID("AIFF".getBytes())) .withChunk(COMMON.getChunkId(), commonChunk) .withChunk(SOUND_DATA.getChunkId(), soundDataChunk) .build(); assertThat(aiff, notNullValue()); }