diff --git a/build.gradle b/build.gradle index 3880e18f1..5d4ed8109 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,8 @@ allprojects { gdxVersion = '1.10.0' visuiVersion = '1.5.0' kryoVersion = '5.2.0' - junitVersion = '4.12' + junitVersion = '4.13.2' + mockitoVersion = '1.10.19' commonsIoVersion = '2.5' commonsLangVersion = '3.12.0' gltfVersion = 'master-SNAPSHOT' @@ -43,6 +44,8 @@ project(":commons") { compile "com.github.mgsx-dev.gdx-gltf:gltf:$gltfVersion" testCompile "junit:junit:$junitVersion" + + testCompile "org.mockito:mockito-all:$mockitoVersion" } } @@ -73,7 +76,9 @@ project(":editor") { compile "com.kotcrab.vis:vis-ui:$visuiVersion" compile "com.esotericsoftware:kryo:$kryoVersion" + // tests testCompile "junit:junit:$junitVersion" + testCompile "org.mockito:mockito-all:$mockitoVersion" } } diff --git a/editor/src/main/com/mbrlabs/mundus/editor/exporter/Exporter.kt b/editor/src/main/com/mbrlabs/mundus/editor/exporter/Exporter.kt index 005e2d648..42ea43eb6 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/exporter/Exporter.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/exporter/Exporter.kt @@ -34,6 +34,7 @@ import com.mbrlabs.mundus.editor.core.project.ProjectManager import com.mbrlabs.mundus.editor.core.scene.SceneManager import org.apache.commons.io.FilenameUtils import java.io.File +import java.io.Writer /** * @author Marcus Brummer @@ -119,9 +120,14 @@ class Exporter(val kryo: KryoManager, val project: ProjectContext) { } private fun exportScene(scene: SceneDTO, file: FileHandle, jsonType: JsonWriter.OutputType) { + val writer = file.writer(false); + exportScene(scene, writer, jsonType); + } + + fun exportScene(scene: SceneDTO, writer: Writer, jsonType: JsonWriter.OutputType) { val json = Json() json.setOutputType(jsonType) - json.setWriter(file.writer(false)) + json.setWriter(writer) json.writeObjectStart() diff --git a/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java b/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java new file mode 100644 index 000000000..48c0191ee --- /dev/null +++ b/editor/src/test/java/com/mbrlabs/mundus/editor/exporter/ExporterTest.java @@ -0,0 +1,43 @@ +package com.mbrlabs.mundus.editor.exporter; + +import com.badlogic.gdx.utils.JsonWriter; +import com.mbrlabs.mundus.commons.dto.SceneDTO; +import com.mbrlabs.mundus.editor.core.kryo.KryoManager; +import com.mbrlabs.mundus.editor.core.project.ProjectContext; +import com.mbrlabs.mundus.editor.history.CommandHistory; +import com.mbrlabs.mundus.editor.history.HistoryTest; +import org.junit.Before; +import org.junit.Test; +import org.lwjgl.system.CallbackI; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +public class ExporterTest { + + private Exporter exporter; + + @Before + public void setUp() { + KryoManager manager = mock(KryoManager.class); + ProjectContext context = mock(ProjectContext.class); + + exporter = new Exporter(manager, context); + } + + @Test + public void testExportEmptyScene() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStreamWriter writer = new OutputStreamWriter(baos); + + SceneDTO scene = new SceneDTO(); + exporter.exportScene(scene, writer, JsonWriter.OutputType.json); + + String result = baos.toString(); + assertEquals("{\"id\":0,\"name\":null,\"gos\":[]}", result); + } + +} diff --git a/editor/src/test/java/com/mbrlabs/mundus/editor/test/HistoryTest.java b/editor/src/test/java/com/mbrlabs/mundus/editor/history/HistoryTest.java similarity index 98% rename from editor/src/test/java/com/mbrlabs/mundus/editor/test/HistoryTest.java rename to editor/src/test/java/com/mbrlabs/mundus/editor/history/HistoryTest.java index aea208ef9..7cbbe1ec2 100644 --- a/editor/src/test/java/com/mbrlabs/mundus/editor/test/HistoryTest.java +++ b/editor/src/test/java/com/mbrlabs/mundus/editor/history/HistoryTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.mbrlabs.mundus.editor.test; +package com.mbrlabs.mundus.editor.history; import static org.junit.Assert.assertEquals;