Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .run/java in jaudiotagger.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="java in jaudiotagger" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="jaudiotagger" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="directory" />
<dir value="$PROJECT_DIR$/src/test/java" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
This is a maintained fork of [Kaned1as/jaudiotagger](https://github.com/Kaned1as/jaudiotagger).

# Status

[![CI/CD](https://github.com/sknull/jaudiotagger/actions/workflows/build.yml/badge.svg)](https://github.com/sknull/jaudiotagger/actions/workflows/build.yml)

# Jaudiotagger

Jaudiotagger is a Java library for reading and writing audio metadata. It supports a wide range of audio formats,
Expand Down
49 changes: 48 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
<version>2.0.17</version>
</dependency>

<!-- provide logger implementation for testing only as we do not know what client code wants to use -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.13</version>
<scope>test</scope>
</dependency>

<!-- TESTING -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -77,7 +91,6 @@
<version>3.27.6</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -121,6 +134,40 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
197 changes: 197 additions & 0 deletions src/test/java/org/jaudiotagger/AbstractBaseTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package org.jaudiotagger;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most stuff here moved from AbstractTestCase and deals with resources needed in the tests.


import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class AbstractBaseTestCase {

private static File tempDirectory;
protected final Logger log = LoggerFactory.getLogger(getClass());

@BeforeAll
public static void setUpOnce() throws Exception {
tempDirectory = Files.createTempDirectory("jaudiotagger_").toFile();
}

public boolean executeAlsoWithMissingResources() {
return false;
}

/**
* Copy audiofile to processing dir ready for use in test
*
* @param fileName
* @return
*/
public File copyAudioToTmp(String fileName) {
File inputFile = fileResource("testdata", fileName);
if (inputFile.exists()) {
File outputFile = tempFileResource(fileName);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
boolean result = copy(inputFile, outputFile);
assertTrue(result);
return outputFile;
} else {
log.warn("Sourcefile does not exist '" + inputFile + "'");
return null;
}
}

/**
* Copy a File
*
* @param fromFile The existing File
* @param toFile The new File
* @return <code>true</code> if and only if the renaming succeeded;
* <code>false</code> otherwise
*/
public boolean copy(File fromFile, File toFile) {
try (
FileInputStream fins = new FileInputStream((fromFile));
FileOutputStream fouts = new FileOutputStream((toFile))
) {
fins.transferTo(fouts);
fouts.flush();

// cleanupif files are not the same length
long length1 = fromFile.length();
long length2 = toFile.length();
if (length1 != length2) {
toFile.delete();

return false;
}

return true;
} catch (IOException e) {
return false;
}
}

public File tempFileResource(String fileName) {
File file;
if (fileName == null) {
file = tempDirectory;
} else {
file = new File(tempDirectory, fileName);
}
return file;
}

public File fileResource(String directory, String fileName) {
String dir;
if (!directory.endsWith("/")) {
dir = directory + "/";
} else {
dir = directory;
}
File file = null;
try {
URI resource;
if (fileName == null) {
resource = ClassLoader.getSystemResource(dir).toURI();
} else {
resource = ClassLoader.getSystemResource(dir + fileName).toURI();
}
file = new File(resource);
} catch (Exception e) {
log.error("Could not open resource '" + dir + fileName + "'");
}
return file;
}

/**
* Copy audiofile to processing dir ready for use in test, use this if using
* same file in multiple tests because with junit multithreading can have
* problems otherwise
*
* @param fileName
* @return
*/
public File copyAudioToTmp(String fileName, String newFileName) {
File inputFile = fileResource("testdata", fileName);
File outputFile = tempFileResource(newFileName);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
boolean result = copy(inputFile, outputFile);
assertTrue(result);
return outputFile;
}

/**
* Prepends file with tag file in order to create an mp3 with a valid id3
*
* @param tagfile
* @param fileName
* @return
*/
public File prependAudioToTmp(String tagfile, String fileName) {
File inputTagFile = fileResource("testtagdata", tagfile);
File inputFile = fileResource("testdata", fileName);
File outputFile = tempFileResource(fileName);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
boolean result = append(inputTagFile, inputFile, outputFile);
assertTrue(result);
return outputFile;
}

private boolean append(File fromFile1, File fromFile2, File toFile) {
try {
FileInputStream in = new FileInputStream(fromFile1);
FileInputStream in2 = new FileInputStream(fromFile2);
FileOutputStream out = new FileOutputStream(toFile);
BufferedInputStream inBuffer = new BufferedInputStream(in);
BufferedInputStream inBuffer2 = new BufferedInputStream(in2);
BufferedOutputStream outBuffer = new BufferedOutputStream(out);

int theByte;

while ((theByte = inBuffer.read()) > -1) {
outBuffer.write(theByte);
}

while ((theByte = inBuffer2.read()) > -1) {
outBuffer.write(theByte);
}

outBuffer.close();
inBuffer.close();
inBuffer2.close();
out.close();
in.close();
in2.close();

// cleanupif files are not the same length
if ((fromFile1.length() + fromFile2.length()) != toFile.length()) {
toFile.delete();

return false;
}

return true;
} catch (IOException e) {
return false;
}
}

public File fileResource(String directory) {
return fileResource(directory, null);
}
}
Loading