@Test public void visitsInOrder() throws Exception { CentralDirectoryVisitor visitor = mock(TestCentralDirectoryVisitor.class); CentralDirectoryParser parser = new CentralDirectoryParser(); parser.addVisitor(visitor); parser.parse(this.jarData, false); InOrder ordered = inOrder(visitor); ordered .verify(visitor) .visitStart(any(CentralDirectoryEndRecord.class), any(RandomAccessData.class)); ordered .verify(visitor, atLeastOnce()) .visitFileHeader(any(CentralDirectoryFileHeader.class), anyInt()); ordered.verify(visitor).visitEnd(); }
@Test public void visitRecords() throws Exception { Collector collector = new Collector(); CentralDirectoryParser parser = new CentralDirectoryParser(); parser.addVisitor(collector); parser.parse(this.jarData, false); Iterator<CentralDirectoryFileHeader> headers = collector.getHeaders().iterator(); assertThat(headers.next().getName().toString()).isEqualTo("META-INF/"); assertThat(headers.next().getName().toString()).isEqualTo("META-INF/MANIFEST.MF"); assertThat(headers.next().getName().toString()).isEqualTo("1.dat"); assertThat(headers.next().getName().toString()).isEqualTo("2.dat"); assertThat(headers.next().getName().toString()).isEqualTo("d/"); assertThat(headers.next().getName().toString()).isEqualTo("d/9.dat"); assertThat(headers.next().getName().toString()).isEqualTo("special/"); assertThat(headers.next().getName().toString()).isEqualTo("special/\u00EB.dat"); assertThat(headers.next().getName().toString()).isEqualTo("nested.jar"); assertThat(headers.next().getName().toString()).isEqualTo("another-nested.jar"); assertThat(headers.hasNext()).isFalse(); }