|
| 1 | +package com.sk89q.worldedit.extent.clipboard.io; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Assertions; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import java.io.File; |
| 7 | +import java.io.InputStream; |
| 8 | +import java.io.OutputStream; |
| 9 | +import java.nio.file.Path; |
| 10 | +import java.util.Set; |
| 11 | + |
| 12 | +class ClipboardFormatsTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + void findByFile() { |
| 16 | + Assertions.assertSame( |
| 17 | + BuiltInClipboardFormat.SPONGE_V1_SCHEMATIC, |
| 18 | + ClipboardFormats.findByFile(getTestSchematic("sponge1.schem")) |
| 19 | + ); |
| 20 | + Assertions.assertSame( |
| 21 | + BuiltInClipboardFormat.FAST_V2, |
| 22 | + ClipboardFormats.findByFile(getTestSchematic("sponge2.schem")) |
| 23 | + ); |
| 24 | + Assertions.assertSame( |
| 25 | + BuiltInClipboardFormat.FAST_V3, |
| 26 | + ClipboardFormats.findByFile(getTestSchematic("sponge3.schem")) |
| 27 | + ); |
| 28 | + Assertions.assertSame( |
| 29 | + BuiltInClipboardFormat.MCEDIT_SCHEMATIC, |
| 30 | + ClipboardFormats.findByFile(getTestSchematic("mcedit.mce")) |
| 31 | + ); |
| 32 | + Assertions.assertSame( |
| 33 | + BuiltInClipboardFormat.MINECRAFT_STRUCTURE, |
| 34 | + ClipboardFormats.findByFile(getTestSchematic("minecraft_structure.nbt")) |
| 35 | + ); |
| 36 | + Assertions.assertSame( |
| 37 | + BuiltInClipboardFormat.PNG, |
| 38 | + ClipboardFormats.findByFile(getTestSchematic("1x1.png")) |
| 39 | + ); |
| 40 | + |
| 41 | + Assertions.assertNull( |
| 42 | + ClipboardFormats.findByFile(getTestSchematic("custom_format.xyz")) |
| 43 | + ); |
| 44 | + ClipboardFormats.registerClipboardFormat(new CustomTestingClipboardFormat()); |
| 45 | + Assertions.assertInstanceOf( |
| 46 | + CustomTestingClipboardFormat.class, |
| 47 | + ClipboardFormats.findByFile(getTestSchematic("custom_format.xyz")) |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + private static File getTestSchematic(String name) { |
| 52 | + return Path.of("src", "test", "resources", "fastasyncworldedit", "schematics", name).toFile(); |
| 53 | + } |
| 54 | + |
| 55 | + private static final class CustomTestingClipboardFormat implements ClipboardFormat { |
| 56 | + |
| 57 | + @Override |
| 58 | + public String getName() { |
| 59 | + return "Custom Testing Format"; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean isFormat(final File file) { |
| 64 | + return file.getName().endsWith(".xyz"); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Set<String> getAliases() { |
| 69 | + return Set.of(); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public ClipboardReader getReader(final InputStream inputStream) { |
| 74 | + return null; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public ClipboardWriter getWriter(final OutputStream outputStream) { |
| 79 | + return null; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String getPrimaryFileExtension() { |
| 84 | + return ""; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public Set<String> getFileExtensions() { |
| 89 | + return Set.of(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public Set<String> getExplicitFileExtensions() { |
| 94 | + return Set.of(); |
| 95 | + } |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments