Skip to content

Commit

Permalink
Fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
guperrot committed Oct 4, 2018
1 parent 467c7bd commit 2c68d1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.microsoft.appcenter.ingestion.models.properties;

import android.support.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -12,26 +14,20 @@

public class TypedPropertyUtils {

public static TypedProperty create(String type) throws JSONException {
switch (type) {
case BooleanTypedProperty.TYPE:
return new BooleanTypedProperty();

case DateTimeTypedProperty.TYPE:
return new DateTimeTypedProperty();

case DoubleTypedProperty.TYPE:
return new DoubleTypedProperty();

case LongTypedProperty.TYPE:
return new LongTypedProperty();

case StringTypedProperty.TYPE:
return new StringTypedProperty();

default:
throw new JSONException("Unsupported type: " + type);
@SuppressWarnings("IfCanBeSwitch")
public static TypedProperty create(@NonNull String type) throws JSONException {
if (BooleanTypedProperty.TYPE.equals(type)) {
return new BooleanTypedProperty();
} else if (DateTimeTypedProperty.TYPE.equals(type)) {
return new DateTimeTypedProperty();
} else if (DoubleTypedProperty.TYPE.equals(type)) {
return new DoubleTypedProperty();
} else if (LongTypedProperty.TYPE.equals(type)) {
return new LongTypedProperty();
} else if (StringTypedProperty.TYPE.equals(type)) {
return new StringTypedProperty();
}
throw new JSONException("Unsupported type: " + type);
}

public static List<TypedProperty> read(JSONObject object) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void createValidTypedProperty() throws JSONException {

@Test(expected = JSONException.class)
public void createInvalidTypedProperty() throws JSONException {
TypedPropertyUtils.create("Something");
//noinspection AccessStaticViaInstance to cover default constructor
new TypedPropertyUtils().create("Something");
}
}

0 comments on commit 2c68d1d

Please sign in to comment.