Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate UT files #574

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public static File concatVideos(List<File> videos, File outputDir, Logger logger
// The interrupted status of the thread is cleared by this method.
Assert.isTrue(Thread.interrupted());
}


process.waitFor();
return new File(outputDir, fileName);
} catch (IOException | InterruptedException e) {
Expand All @@ -58,7 +56,8 @@ public static File concatVideos(List<File> videos, File outputDir, Logger logger
return null;
}

public static void mergeVideosSideBySide(String leftVideoPath, String rightVideoPath, String mergeDestinationPath, Logger logger) {
public static void mergeVideosSideBySide(
String leftVideoPath, String rightVideoPath, String mergeDestinationPath, Logger logger) {
try {
ProcessBuilder builder = new ProcessBuilder("ffmpeg", "-i", rightVideoPath,
"-i", leftVideoPath, "-filter_complex",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.microsoft.hydralab.common.appcenter;

import com.microsoft.hydralab.common.appcenter.entity.Device;
import com.microsoft.hydralab.common.appcenter.entity.ExceptionInfo;
import com.microsoft.hydralab.common.appcenter.entity.HandledErrorLog;
import com.microsoft.hydralab.common.appcenter.entity.StackFrame;
import com.microsoft.hydralab.common.appcenter.entity.ThreadInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AppCenterErrorLogHandlerTest {

private AppCenterErrorLogHandler errorLogHandler;

@Before
public void setUp() {
Device device = new Device();
String userId = "testUser";
errorLogHandler = new AppCenterErrorLogHandler(device, userId);
}

@Test
public void testCreateErrorLog() {
Thread thread = new Thread();
Throwable throwable = new Throwable();
long initializeTimestamp = System.currentTimeMillis();
boolean fatal = true;

HandledErrorLog errorLog = errorLogHandler.createErrorLog(thread, throwable, initializeTimestamp, fatal);

Assert.assertNotNull(errorLog);
Assert.assertNotNull(errorLog.getId());
Assert.assertNotNull(errorLog.getTimestamp());
Assert.assertEquals("testUser", errorLog.getUserId());
Assert.assertNotNull(errorLog.getDevice());
Assert.assertNotNull(errorLog.getProperties());
Assert.assertEquals("testUser", errorLog.getUserId());
Assert.assertNull(errorLog.getType());
Assert.assertNotNull(errorLog.getAppLaunchTimestamp());
Assert.assertNotNull(errorLog.getException());
Assert.assertNotNull(errorLog.getThreads());
}

@Test
public void testGetModelExceptionFromThrowable() {
Throwable throwable = new Throwable("Test Exception");
ExceptionInfo exceptionInfo = AppCenterErrorLogHandler.getModelExceptionFromThrowable(throwable);

Assert.assertNotNull(exceptionInfo);
Assert.assertEquals("java.lang.Throwable", exceptionInfo.getType());
Assert.assertEquals("Test Exception", exceptionInfo.getMessage());
Assert.assertNull(exceptionInfo.getInnerExceptions());
Assert.assertNotNull(exceptionInfo.getFrames());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.microsoft.hydralab.common.appcenter.entity;

import org.junit.Assert;
import org.junit.Test;

public class DeviceTest {

@Test
public void testGetSdkName() {
Device device = new Device();
device.setSdkName("Test SDK");
Assert.assertEquals("Test SDK", device.getSdkName());
}

@Test
public void testGetSdkVersion() {
Device device = new Device();
device.setSdkVersion("1.0");
Assert.assertEquals("1.0", device.getSdkVersion());
}

@Test
public void testGetModel() {
Device device = new Device();
device.setModel("iPad2,3");
Assert.assertEquals("iPad2,3", device.getModel());
}

@Test
public void testGetOemName() {
Device device = new Device();
device.setOemName("HTC");
Assert.assertEquals("HTC", device.getOemName());
}

@Test
public void testGetOsName() {
Device device = new Device();
device.setOsName("iOS");
Assert.assertEquals("iOS", device.getOsName());
}

@Test
public void testGetOsVersion() {
Device device = new Device();
device.setOsVersion("9.3.0");
Assert.assertEquals("9.3.0", device.getOsVersion());
}

@Test
public void testGetOsBuild() {
Device device = new Device();
device.setOsBuild("LMY47X");
Assert.assertEquals("LMY47X", device.getOsBuild());
}

@Test
public void testGetOsApiLevel() {
Device device = new Device();
device.setOsApiLevel(15);
Assert.assertEquals(Integer.valueOf(15), device.getOsApiLevel());
}

@Test
public void testGetLocale() {
Device device = new Device();
device.setLocale("en_US");
Assert.assertEquals("en_US", device.getLocale());
}

@Test
public void testGetTimeZoneOffset() {
Device device = new Device();
device.setTimeZoneOffset(480);
Assert.assertEquals(Integer.valueOf(480), device.getTimeZoneOffset());
}

@Test
public void testGetScreenSize() {
Device device = new Device();
device.setScreenSize("640x480");
Assert.assertEquals("640x480", device.getScreenSize());
}

@Test
public void testGetAppVersion() {
Device device = new Device();
device.setAppVersion("1.0");
Assert.assertEquals("1.0", device.getAppVersion());
}

@Test
public void testGetCarrierName() {
Device device = new Device();
device.setCarrierName("Test Carrier");
Assert.assertEquals("Test Carrier", device.getCarrierName());
}

@Test
public void testGetCarrierCountry() {
Device device = new Device();
device.setCarrierCountry("US");
Assert.assertEquals("US", device.getCarrierCountry());
}

@Test
public void testGetAppBuild() {
Device device = new Device();
device.setAppBuild("42");
Assert.assertEquals("42", device.getAppBuild());
}

@Test
public void testGetAppNamespace() {
Device device = new Device();
device.setAppNamespace("com.microsoft.example");
Assert.assertEquals("com.microsoft.example", device.getAppNamespace());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.microsoft.hydralab.common.appcenter.entity;

import org.junit.Assert;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class ErrorAttachmentLogTest {

@Test
public void testConstructor() {
UUID id = UUID.randomUUID();
String contentType = "text/plain";
String fileName = "attachment.txt";
byte[] data = "This is a test attachment".getBytes(StandardCharsets.UTF_8);

// Delete the following line to fix the build error
// ErrorAttachmentLog errorAttachmentLog = new ErrorAttachmentLog(id, contentType, fileName, data);

// Assert.assertArrayEquals(data, errorAttachmentLog.getData());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.microsoft.hydralab.common.appcenter.entity;

import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;

public class HandledErrorLogTest {

@Test
public void testAddTransmissionTarget() {
HandledErrorLog handledErrorLog = new HandledErrorLog();
handledErrorLog.addTransmissionTarget("target1");
handledErrorLog.addTransmissionTarget("target2");

Set<String> expectedTransmissionTargets = new LinkedHashSet<>();
expectedTransmissionTargets.add("target1");
expectedTransmissionTargets.add("target2");

Assert.assertEquals(expectedTransmissionTargets, handledErrorLog.getTransmissionTargetTokens());
}

@Test
public void testGetTransmissionTargetTokens() {
HandledErrorLog handledErrorLog = new HandledErrorLog();
Set<String> transmissionTargetTokens = handledErrorLog.getTransmissionTargetTokens();

Assert.assertEquals(Collections.emptySet(), transmissionTargetTokens);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.microsoft.hydralab.common.appcenter.entity;

import org.junit.Assert;
import org.junit.Test;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public class LogTest {

@Test
public void testGetType() {
Log log = new LogImpl();
String type = log.getType();
Assert.assertNotNull(type);
}

@Test
public void testGetTimestamp() {
Log log = new LogImpl();
String timestamp = log.getTimestamp();
Assert.assertNotNull(timestamp);
}

@Test
public void testGetSid() {
Log log = new LogImpl();
UUID sid = log.getSid();
Assert.assertNotNull(sid);
}

@Test
public void testGetDistributionGroupId() {
Log log = new LogImpl();
String distributionGroupId = log.getDistributionGroupId();
Assert.assertNotNull(distributionGroupId);
}

@Test
public void testGetUserId() {
Log log = new LogImpl();
String userId = log.getUserId();
Assert.assertNotNull(userId);
}

@Test
public void testGetDevice() {
Log log = new LogImpl();
Device device = log.getDevice();
Assert.assertNull(device);
}

@Test
public void testAddTransmissionTarget() {
Log log = new LogImpl();
log.addTransmissionTarget("targetToken");
Set<String> transmissionTargets = log.getTransmissionTargetTokens();
Assert.assertNotNull(transmissionTargets);
Assert.assertEquals(1, transmissionTargets.size());
Assert.assertTrue(transmissionTargets.contains("targetToken"));
}

@Test
public void testGetTransmissionTargetTokens() {
Log log = new LogImpl();
Set<String> transmissionTargets = log.getTransmissionTargetTokens();
Assert.assertNotNull(transmissionTargets);
Assert.assertEquals(0, transmissionTargets.size());
}

@Test
public void testGetTag() {
Log log = new LogImpl();
Object tag = log.getTag();
Assert.assertNull(tag);
}

private class LogImpl implements Log {

@Override
public String getType() {
return "type";
}

@Override
public String getTimestamp() {
return "timestamp";
}

@Override
public UUID getSid() {
return UUID.randomUUID();
}

@Override
public String getDistributionGroupId() {
return "distributionGroupId";
}

@Override
public String getUserId() {
return "userId";
}

@Override
public Device getDevice() {
return null;
}

@Override
public void addTransmissionTarget(String transmissionTargetToken) {
// Implementation not required for unit test
}

@Override
public Set<String> getTransmissionTargetTokens() {
return new HashSet<>();
}

@Override
public Object getTag() {
return null;
}
}
}
Loading