forked from MinecraftTAS/TASmod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PlaybackMetadata] Adding handleOnLoad and handleOnSave
Changed constructor of PlaybackMetadata to accept PlaybackMetadataExtension. This is to encourage users to write `new PlaybackMetadata(this)` to ensure, that the metadata extension name is also in the PlaybackMetadata. - Added PlaybackMetadata and PlaybackMetadataRegistry tests
- Loading branch information
1 parent
f8cf266
commit be74f5e
Showing
6 changed files
with
204 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/test/java/tasmod/playback/metadata/PlaybackMetadataRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package tasmod.playback.metadata; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadata; | ||
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadataRegistry; | ||
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadataRegistry.PlaybackMetadataExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class PlaybackMetadataRegistryTest { | ||
|
||
class Test1 implements PlaybackMetadataExtension{ | ||
|
||
private String actual; | ||
|
||
public String getActual() { | ||
return actual; | ||
} | ||
|
||
@Override | ||
public String getExtensionName() { | ||
return "Test1"; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
} | ||
|
||
@Override | ||
public PlaybackMetadata onStore() { | ||
PlaybackMetadata data = new PlaybackMetadata(this); | ||
data.setValue("Test", "Testing 1"); | ||
return data; | ||
} | ||
|
||
@Override | ||
public void onLoad(PlaybackMetadata metadata) { | ||
actual = metadata.getValue("Test"); | ||
} | ||
|
||
} | ||
|
||
File file = new File("src/test/resources/run/MetadataRegistry.txt"); | ||
|
||
void store() { | ||
List<PlaybackMetadata> list = PlaybackMetadataRegistry.handleOnStore(); | ||
List<String> out = new ArrayList<>(); | ||
|
||
list.forEach(data -> { | ||
out.addAll(data.toStringList()); | ||
}); | ||
|
||
try { | ||
FileUtils.writeLines(file, out); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
void load() { | ||
List<String> loaded = null; | ||
try { | ||
loaded = FileUtils.readLines(file, StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
List<PlaybackMetadata> meta = new ArrayList<>(); | ||
|
||
meta.add(PlaybackMetadata.fromStringList("Test1", loaded)); | ||
|
||
PlaybackMetadataRegistry.handleOnLoad(meta); | ||
} | ||
|
||
/** | ||
* Register, store and read metadata | ||
*/ | ||
@Test | ||
void testRegistry() { | ||
Test1 actual = new Test1(); | ||
PlaybackMetadataRegistry.register(actual); | ||
|
||
store(); | ||
load(); | ||
|
||
assertEquals("Testing 1", actual.getActual()); | ||
if(file.exists()) { | ||
file.delete(); | ||
} | ||
} | ||
} |
Oops, something went wrong.