Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ allprojects {
apply plugin: 'idea'

group = 'org.spine3'
version = '0.5.18-SNAPSHOT'
version = '0.5.19-SNAPSHOT'
}

ext {
Expand Down
34 changes: 34 additions & 0 deletions client/src/main/java/org/spine3/base/Mismatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

package org.spine3.base;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.google.protobuf.StringValue;
import org.spine3.protobuf.AnyPacker;

import javax.annotation.Nullable;

import static com.google.common.base.Throwables.propagate;
import static org.spine3.protobuf.Values.pack;

/**
Expand Down Expand Up @@ -157,4 +160,35 @@ public static ValueMismatch of(@Nullable Message expected, @Nullable Message act
builder.setVersion(version);
return builder.build();
}


/**
* Obtains expected string from the passed mismatch.
*
* @throws RuntimeException if the passed instance represent a mismatch of non-string values
*/
public static String getExpectedString(ValueMismatch mismatch) {
try {
final StringValue result = mismatch.getExpected()
.unpack(StringValue.class);
return result.getValue();
} catch (InvalidProtocolBufferException e) {
throw propagate(e);
}
}

/**
* Obtains actual string from the passed mismatch.
*
* @throws RuntimeException if the passed instance represent a mismatch of non-string values
*/
public static String getActualString(ValueMismatch mismatch) {
try {
final StringValue result = mismatch.getActual()
.unpack(StringValue.class);
return result.getValue();
} catch (InvalidProtocolBufferException e) {
throw propagate(e);
}
}
}
20 changes: 14 additions & 6 deletions client/src/test/java/org/spine3/base/MismatchShould.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.spine3.base.Mismatch.getActualString;
import static org.spine3.base.Mismatch.getExpectedString;
import static org.spine3.protobuf.AnyPacker.unpack;
import static org.spine3.protobuf.Values.newStringValue;
import static org.spine3.test.Tests.hasPrivateUtilityConstructor;
Expand All @@ -39,7 +41,6 @@
*/
public class MismatchShould {

private static final String REQUESTED = "requested";
private static final String EXPECTED = "expected";
private static final String ACTUAL = "ACTUAL";
private static final int VERSION = 0;
Expand Down Expand Up @@ -83,7 +84,6 @@ public void return_mismatch_object_with_string_values() {
public void return_mismatch_object_with_int32_values() {
final int expected = 0;
final int actual = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we remove unnecessary 'requsted' code from class.
Maybe remove private static final String REQUESTED as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well spotted. Fixed.

final int requested = 2;
final ValueMismatch mismatch = Mismatch.of(expected, actual, VERSION);
final Int32Value expectedWrapper = unpack(mismatch.getExpected());
final Int32Value actualWrapper = unpack(mismatch.getActual());
Expand All @@ -96,7 +96,6 @@ public void return_mismatch_object_with_int32_values() {
public void return_mismatch_object_with_int64_values() {
final long expected = 0L;
final long actual = 1L;
final long requested = 2L;
final ValueMismatch mismatch = Mismatch.of(expected, actual, VERSION);
final Int64Value expectedWrapped = unpack(mismatch.getExpected());
final Int64Value actualWrapped = unpack(mismatch.getActual());
Expand All @@ -109,7 +108,6 @@ public void return_mismatch_object_with_int64_values() {
public void return_mismatch_object_with_float_values() {
final float expected = 0.0F;
final float actual = 1.0F;
final float requested = 2.0F;
final ValueMismatch mismatch = Mismatch.of(expected, actual, VERSION);
final FloatValue expectedWrapped = unpack(mismatch.getExpected());
final FloatValue actualWrapped = unpack(mismatch.getActual());
Expand All @@ -122,7 +120,6 @@ public void return_mismatch_object_with_float_values() {
public void return_mismatch_object_with_double_values() {
final double expected = 0.1;
final double actual = 0.2;
final double requested = 0.3;
final ValueMismatch mismatch = Mismatch.of(expected, actual, VERSION);
final DoubleValue expectedWrapped = unpack(mismatch.getExpected());
final DoubleValue actualWrapped = unpack(mismatch.getActual());
Expand All @@ -135,7 +132,6 @@ public void return_mismatch_object_with_double_values() {
public void return_mismatch_object_with_boolean_values() {
final boolean expected = true;
final boolean actual = false;
final boolean requested = true;
final ValueMismatch mismatch = Mismatch.of(expected, actual, VERSION);
final BoolValue expectedWrapped = unpack(mismatch.getExpected());
final BoolValue actualWrapped = unpack(mismatch.getActual());
Expand Down Expand Up @@ -171,4 +167,16 @@ public void return_mismatch_object_with_message_values() {
assertEquals(EXPECTED, expected.getValue());
assertEquals(ACTUAL, actual.getValue());
}

@Test
public void return_expected_string() {
final ValueMismatch mismatch = Mismatch.of(newStringValue(EXPECTED), newStringValue(ACTUAL), VERSION);
assertEquals(EXPECTED, getExpectedString(mismatch));
}

@Test
public void return_actual_string() {
final ValueMismatch mismatch = Mismatch.of(newStringValue(EXPECTED), newStringValue(ACTUAL), VERSION);
assertEquals(ACTUAL, getActualString(mismatch));
}
}