-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #474 from szprutamich/master
Version 3.17
- Loading branch information
Showing
5 changed files
with
204 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
/** | ||
* @author Michał Szpruta <[email protected]> | ||
*/ | ||
public class APIDeviceCleanupConfiguration extends APIEntity implements Cloneable { | ||
public class APIDeviceCleanupConfiguration extends APIEntity { | ||
|
||
private String content; | ||
|
||
|
@@ -138,11 +138,6 @@ public <T extends APIEntity> void clone(T from) { | |
this.discriminator = deviceCleanupConfiguration.discriminator; | ||
} | ||
|
||
@Override | ||
public APIDeviceCleanupConfiguration clone() throws CloneNotSupportedException { | ||
return (APIDeviceCleanupConfiguration) super.clone(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
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
158 changes: 158 additions & 0 deletions
158
src/test/java/com/testdroid/api/util/TypeReferenceFactoryTest.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,158 @@ | ||
package com.testdroid.api.util; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.testdroid.api.*; | ||
import com.testdroid.api.model.*; | ||
import com.testdroid.api.model.capabilities.APIDesktopBrowserCapabilities; | ||
import com.testdroid.api.model.devicetime.APIBasicDeviceTime; | ||
import com.testdroid.api.model.notification.APINotification; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
import org.reflections.Reflections; | ||
|
||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import static com.testdroid.cloud.test.categories.TestTags.UNIT; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* @author Michał Szpruta <[email protected]> | ||
*/ | ||
@Tag(UNIT) | ||
class TypeReferenceFactoryTest { | ||
|
||
static class ExplicitTypeProvider implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | ||
Stream<Class<?>> stream = Stream.of(APIAccessGroup.class, | ||
APIAccount.class, | ||
APIAccountConcurrencyStatus.class, | ||
APIAccountConcurrencyStatusMap.class, | ||
APIAccountPreference.class, | ||
APIAccountService.class, | ||
APIAccountServicePayment.class, | ||
APIAdminDevice.class, | ||
APIAdminDeviceSessionStatistics.class, | ||
APIAdminDeviceType.class, | ||
APIAdminEmail.class, | ||
APIAdminOverview.class, | ||
APIAdminTestRun.class, | ||
APIBasicDeviceTime.class, | ||
APIBillingPeriod.class, | ||
APIBillingPeriodUsage.class, | ||
APIBrowser.class, | ||
APICloudInfo.class, | ||
APICluster.class, | ||
APIConnection.class, | ||
APIDesktopBrowserCapabilities.class, | ||
APIDevice.class, | ||
APIDeviceCleanupConfiguration.class, | ||
APIDeviceGroup.class, | ||
APIDeviceModelCriterion.class, | ||
APIDeviceModelPool.class, | ||
APIDeviceModelPoolStatistics.class, | ||
APIDevicePicker.class, | ||
APIDeviceProperty.class, | ||
APIDeviceSession.class, | ||
APIDeviceSessionStep.class, | ||
APIExceptionMessage.class, | ||
APIFramework.class, | ||
APIHealthCheck.class, | ||
APILabelGroup.class, | ||
APILicense.class, | ||
APIMaintenance.class, | ||
APIMessage.class, | ||
APINotification.class, | ||
APIProject.class, | ||
APIProjectJobConfig.class, | ||
APIProperty.class, | ||
APIRole.class, | ||
APIS3Url.class, | ||
APIService.class, | ||
APIServicePaymentStatus.class, | ||
APISharedResource.class, | ||
APITag.class, | ||
APITestRun.class, | ||
APITestRunConfig.class, | ||
APITestRunDataAvailability.class, | ||
APITestRunParameter.class, | ||
APIUser.class, | ||
APIUserDeviceTimeSummary.class, | ||
APIUserFile.class, | ||
APIUserFileProperty.class, | ||
APIUserPreference.class, | ||
APIUserStatistics.class, | ||
Properties.class, | ||
String.class, | ||
APIVisualTestAccess.class); | ||
return stream.distinct().map(Arguments::of); | ||
} | ||
} | ||
|
||
static class APIEntitySubTypeProvider implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | ||
Reflections reflections = new Reflections(APIEntity.class.getPackage().getName()); | ||
Set<Class<? extends APIEntity>> classes = reflections.getSubTypesOf(APIEntity.class); | ||
return classes.stream() | ||
.filter(c -> c != APIList.class) | ||
.filter(c -> c != APISimpleList.class) | ||
.map(Arguments::of); | ||
} | ||
} | ||
|
||
@Test | ||
void testConstructor() { | ||
assertThrows(IllegalAccessException.class, () -> TypeReferenceFactory.class.getDeclaredConstructor() | ||
.newInstance()); | ||
} | ||
|
||
@ArgumentsSource(ExplicitTypeProvider.class) | ||
@ParameterizedTest | ||
void testGetTypeRef(Class<?> clazz) { | ||
TypeReference<?> result = TypeReferenceFactory.getTypeRef(clazz); | ||
assertThat(result).isNotNull(); | ||
assertThat(result.getType().getTypeName()).isEqualTo(clazz.getName()); | ||
} | ||
|
||
@ArgumentsSource(APIEntitySubTypeProvider.class) | ||
@ParameterizedTest | ||
<T extends APIEntity> void testGetListTypeRef(Class<T> clazz) { | ||
TypeReference<?> result = TypeReferenceFactory.getListTypeRef(clazz); | ||
assertThat(result).withFailMessage(clazz.getSimpleName() + " not in the map").isNotNull(); | ||
assertThat(result.getType().getTypeName()) | ||
.isEqualTo(String.format("%s<%s>", APIList.class.getName(), clazz.getName())); | ||
} | ||
|
||
@ArgumentsSource(APIEntitySubTypeProvider.class) | ||
@ParameterizedTest | ||
<T extends APIEntity> void testGetSimpleListTypeRef(Class<T> clazz) { | ||
TypeReference<?> result = TypeReferenceFactory.getSimpleListTypeRef(clazz); | ||
if (clazz == APIBrokerHub.class) { | ||
assertThat(result).withFailMessage(clazz.getSimpleName() + " not in the map").isNotNull(); | ||
assertThat(result.getType().getTypeName()) | ||
.isEqualTo(String.format("%s<%s>", APISimpleList.class.getName(), clazz.getName())); | ||
} else { | ||
assertThat(result).isNull(); | ||
} | ||
} | ||
|
||
@Test | ||
void testGetMapTypeReference() { | ||
TypeReference<?> result = TypeReferenceFactory.getMapTypeReference(); | ||
assertThat(result).isNotNull(); | ||
assertThat(result.getType().getTypeName()).isEqualTo( | ||
String.format("%1$s<%2$s, %2$s>", Map.class.getName(), String.class.getName())); | ||
} | ||
} |