Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Changed the default source and target java version to 1.7 :( #151

Merged
merged 1 commit into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

import org.assertj.core.api.ThrowableAssert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -97,7 +98,11 @@ private void checkBroadcastResponse(ByteString expectedResponseBytes)
@SuppressWarnings("ConstantConditions")
@Test
public void sendResponse_nullQuery_nullReponse() throws Exception {
assertThatThrownBy(() -> mResponseSender.sendResponse(null, null))
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
mResponseSender.sendResponse(null, null);
}
}).isInstanceOf(NullPointerException.class);
}
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ project.ext.glideVersion = '4.0.0'
project.ext.valid4jVersion = '0.5.0'
project.ext.hamcrestVersion = '1.3'
project.ext.guavaVersion = '23.0-android'
project.ext.sourceJavaVersion = JavaVersion.VERSION_1_7
project.ext.targetJavaVersion = JavaVersion.VERSION_1_7

subprojects {
repositories {
Expand Down
4 changes: 2 additions & 2 deletions config/android-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = rootProject.ext.sourceJavaVersion
targetCompatibility = rootProject.ext.targetJavaVersion
}

sourceSets {
Expand Down
4 changes: 2 additions & 2 deletions demoapps/passwordlogin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
targetCompatibility JavaVersion.VERSION_1_8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep 1_8 here? It may be easier for developers to understand the code if they are used to (so not Java 1.8)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ unless there's a good reason to do otherwise, we should be consistent with the Java version

Copy link
Collaborator Author

@dxslly dxslly Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that is is was not part the public libraries I didn't see the need to remain consistent. In my mind the passwordlogin example was the "The latest and greatest practices" example, but there's no other motivation I can think of and you make a good point.

I will plan to migrate it in a follow up PR.

sourceCompatibility JavaVersion.VERSION_1_8
}
}

Expand Down
116 changes: 89 additions & 27 deletions protocol/javatests/org/openyolo/protocol/AdditionalPropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Callable;

import org.assertj.core.api.ThrowableAssert;
import org.assertj.core.util.Maps;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -58,38 +60,88 @@ public class AdditionalPropertiesTest {
private static final Map<String, Callable<AdditionalPropertiesBuilder>> buildersByContainerType =
ImmutableMap.<String, Callable<AdditionalPropertiesBuilder>>builder()
.put("Credential",
() -> new Credential.Builder(
ValidFacebookCredential.ID,
ValidFacebookCredential.AUTHENTICATION_METHOD,
ValidFacebookCredential.AUTHENTICATION_DOMAIN))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new Credential.Builder(
ValidFacebookCredential.ID,
ValidFacebookCredential.AUTHENTICATION_METHOD,
ValidFacebookCredential.AUTHENTICATION_DOMAIN);
}
})
.put("CredentialDeleteRequest",
() -> new CredentialDeleteRequest.Builder(
ValidFacebookCredential.make()))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialDeleteRequest.Builder(
ValidFacebookCredential.make());
}
})
.put("CredentialDeleteResult",
() -> new CredentialDeleteResult.Builder(
CredentialDeleteResult.CODE_DELETED))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialDeleteResult.Builder(
CredentialDeleteResult.CODE_DELETED);
}
})
.put("CredentialRetrieveRequest",
() -> new CredentialRetrieveRequest.Builder(
AuthenticationMethods.EMAIL))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialRetrieveRequest.Builder(
AuthenticationMethods.EMAIL);
}
})
.put("CredentialRetrieveResult",
() -> new CredentialRetrieveResult.Builder(
CredentialRetrieveResult.CODE_NO_CREDENTIALS_AVAILABLE))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialRetrieveResult.Builder(
CredentialRetrieveResult.CODE_NO_CREDENTIALS_AVAILABLE);
}
})
.put("CredentialSaveRequest",
() -> new CredentialSaveRequest.Builder(
ValidFacebookCredential.make()))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialSaveRequest.Builder(
ValidFacebookCredential.make());
}
})
.put("CredentialSaveResult",
() -> new CredentialSaveResult.Builder(
CredentialSaveResult.CODE_SAVED))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new CredentialSaveResult.Builder(
CredentialSaveResult.CODE_SAVED);
}
})
.put("Hint",
() -> new Hint.Builder(
ValidFacebookCredential.ID,
ValidFacebookCredential.AUTHENTICATION_METHOD))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new Hint.Builder(
ValidFacebookCredential.ID,
ValidFacebookCredential.AUTHENTICATION_METHOD);
}
})
.put("HintRetrieveRequest",
() -> new HintRetrieveRequest.Builder(
AuthenticationMethods.EMAIL))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new HintRetrieveRequest.Builder(
AuthenticationMethods.EMAIL);
}
})
.put("HintRetrieveResult",
() -> new HintRetrieveResult.Builder(
HintRetrieveResult.CODE_NO_HINTS_AVAILABLE))
new Callable<AdditionalPropertiesBuilder>() {
@Override
public AdditionalPropertiesBuilder call() throws Exception {
return new HintRetrieveResult.Builder(
HintRetrieveResult.CODE_NO_HINTS_AVAILABLE);
}
})
.build();

@Parameters(name = "AdditionalPropertiesTest for {0}")
Expand Down Expand Up @@ -135,15 +187,25 @@ public void testBuilder_setAdditionalProperties_withNull() {
@Test
public void testBuilder_setAdditionalProperties_nullKey() {
final Map<String, byte[]> mapWithNullKey = Maps.newHashMap(null, new byte[0]);
assertThatThrownBy(() -> mBuilder.setAdditionalProperties(mapWithNullKey))
.isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
mBuilder.setAdditionalProperties(mapWithNullKey);
}
}).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void testBuild_setAdditionalProperty_nullValue() {
final Map<String, byte[]> mapWithNullValue = Maps.newHashMap("a", null);
assertThatThrownBy(() -> mBuilder.setAdditionalProperties(mapWithNullValue))
.isInstanceOf(IllegalArgumentException.class);


assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
mBuilder.setAdditionalProperties(mapWithNullValue);
}
}).isInstanceOf(IllegalArgumentException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public void testFromAuthMethods_withSet() {

@Test(expected=IllegalArgumentException.class)
public void testFromAuthMethods_emptySet() {
HintRetrieveRequest.fromAuthMethods(Collections.emptySet());
HintRetrieveRequest.fromAuthMethods(Collections.<AuthenticationMethod>emptySet());
}

@Test(expected = IllegalArgumentException.class)
public void testBuilder_emptyAuthMethodsSet() {
new HintRetrieveRequest.Builder(Collections.emptySet());
new HintRetrieveRequest.Builder(Collections.<AuthenticationMethod>emptySet());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import static junit.framework.Assert.fail;
import static junit.framework.TestCase.assertTrue;
import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;

import android.content.Intent;
import android.os.BadParcelableException;
import android.os.Parcel;

import org.assertj.core.api.ThrowableAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -70,22 +73,26 @@ public void fromBytes() throws Exception {

@Test
public void fromBytes_withNullIntent_throwsBadParcelableException() {
byte[] intentBytes = toBytesUnchecked(null);

final byte[] intentBytes = toBytesUnchecked(null);

assertThrows(BadParcelableException.class, () -> {
IntentUtil.fromBytes(intentBytes);
});
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
IntentUtil.fromBytes(intentBytes);
}
}).isInstanceOf(BadParcelableException.class);
}

@Test
public void fromBytes_withIntentNotPresent_throwsBadParcelableException() {
byte[] intentBytes = new byte[10];
final byte[] intentBytes = new byte[10];


assertThrows(BadParcelableException.class, () -> {
IntentUtil.fromBytes(intentBytes);
});
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
IntentUtil.fromBytes(intentBytes);
}
}).isInstanceOf(BadParcelableException.class);
}

private static byte[] toBytesUnchecked(Intent intent) {
Expand All @@ -97,34 +104,4 @@ private static byte[] toBytesUnchecked(Intent intent) {
return intentBytes;
}

private interface Operation {
void execute();
}

private static void assertThrows(Class expectedExceptionType, Operation operation) {
try {
operation.execute();

// No exception was thrown.
String failureMessage =
String.format(
"No exception was thrown, expected a %s exception",
expectedExceptionType);

fail(failureMessage);
} catch (Exception ex) {
if (expectedExceptionType.isInstance(ex)) {
// Expected exception was thrown.
return;
}

// An unexpected exception was thrown.
String failureMessage =
String.format(
"Expected exception to be instance of %s, but was %s",
expectedExceptionType,
ex.getClass());
fail(failureMessage);
}
}
}