Browse Source

Add system-indepentant FileTypeDetector for tests

tags/v1.6.0^0
parent
commit
51079f2092
3 changed files with 28 additions and 1 deletions
  1. +1
    -1
      src/test/java/org/perfectable/repositable/AbstractServerTest.java
  2. +26
    -0
      src/test/java/org/perfectable/repositable/ExtensionOnlyFileTypeDetector.java
  3. +1
    -0
      src/test/resources/META-INF/services/java.nio.file.spi.FileTypeDetector

+ 1
- 1
src/test/java/org/perfectable/repositable/AbstractServerTest.java View File

@@ -33,7 +33,7 @@ public abstract class AbstractServerTest {

private static final MediaType METADATA_MEDIA_TYPE = MediaType.XML_UTF_8;
private static final MediaType HASH_MEDIA_TYPE = MediaType.create("text", "plain");
private static final MediaType SIGNATURE_MEDIA_TYPE = MediaType.create("text", "plain");
private static final MediaType SIGNATURE_MEDIA_TYPE = MediaType.create("application", "pgp-signature");

private static final String UPLOAD_METHOD = "PUT";



+ 26
- 0
src/test/java/org/perfectable/repositable/ExtensionOnlyFileTypeDetector.java View File

@@ -0,0 +1,26 @@
package org.perfectable.repositable;

import java.nio.file.Path;
import java.nio.file.spi.FileTypeDetector;

import com.google.common.collect.ImmutableMap;
import org.checkerframework.checker.nullness.qual.Nullable;

public class ExtensionOnlyFileTypeDetector extends FileTypeDetector {
private static final ImmutableMap<String, String> REGISTERED_EXTENSIONS = ImmutableMap.<String, String>builder()
.put("jar", "application/java-archive")
.put("asc", "application/pgp-signature")
.build();

@SuppressWarnings("override.return.invalid")
@Override
public @Nullable String probeContentType(Path path) {
String fileName = path.getFileName().toString();
int extensionSeparator = fileName.lastIndexOf(".");
if (extensionSeparator < 0) {
return null;
}
String extension = fileName.substring(extensionSeparator + 1);
return REGISTERED_EXTENSIONS.get(extension);
}
}

+ 1
- 0
src/test/resources/META-INF/services/java.nio.file.spi.FileTypeDetector View File

@@ -0,0 +1 @@
org.perfectable.repositable.ExtensionOnlyFileTypeDetector

Loading…
Cancel
Save