Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions msgpack-core/src/test/java/org/msgpack/core/Person.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.msgpack.core;

import org.msgpack.annotation.Message;
//import org.msgpack.annotation.Message;

@Message
//@Message
public class Person {
public int id;
public String name;
Expand Down
108 changes: 108 additions & 0 deletions msgpack-value/src/test/java/org/msgpack/value/TestImmutableValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// MessagePack for Java
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.value;


import org.junit.Assert;
import org.junit.Test;
import org.msgpack.core.ValueType;
import org.msgpack.value.impl.ImmutableArrayMapValueImpl;

import java.util.Collections;
import java.util.EnumSet;

public final class TestImmutableValue {
EnumSet<ValueType> valueTypes = EnumSet.allOf(ValueType.class);

@Test
public void testNilValue() {
Value v = ValueFactory.createNilValue();
assertValueType(ValueType.NIL, v.getType());
Assert.assertTrue(v.isNilValue());
}

@Test
public void testBooleanValue() {
Value v = ValueFactory.createBooleanValue(false);
assertValueType(ValueType.BOOLEAN, v.getType());
Assert.assertTrue(v.isBooleanValue());
}

@Test
public void testIntegerValue() {
Value v = ValueFactory.createIntegerValue(10);
assertValueType(ValueType.INTEGER, v.getType());
Assert.assertTrue(v.isIntegerValue());
}

@Test
public void testFloatValue() {
Value v = ValueFactory.createFloatValue(0.1f);
assertValueType(ValueType.FLOAT, v.getType());
Assert.assertTrue(v.isFloatValue());
}

@Test
public void testStringValue() {
Value v = ValueFactory.createStringValue("msgpack");
assertValueType(ValueType.STRING, v.getType());
Assert.assertTrue(v.isStringValue());
}

@Test
public void testBinaryValue() {
Value v = ValueFactory.createBinaryValue("msgpack".getBytes());
assertValueType(ValueType.BINARY, v.getType());
Assert.assertTrue(v.isBinaryValue());
}

@Test
public void testArrayValue() {
Value v = ValueFactory.createArrayValue(Collections.<Value>emptyList());
assertValueType(ValueType.ARRAY, v.getType());
Assert.assertTrue("getType should return Array", v.isArrayValue());
ArrayValue arrayValue = (ArrayValue) v;
Assert.assertTrue(arrayValue.isEmpty());
Assert.assertEquals("size should be zero", 0, arrayValue.size());
Assert.assertTrue(v.isArrayValue());
}

@Test
public void testMapValue() {
Value v = ValueFactory.createMapValue(ImmutableArrayMapValueImpl.getEmptyMapInstance());
assertValueType(ValueType.MAP, v.getType());
Assert.assertTrue(v.isMapValue());
}

//@Test
//public void testExtendedValue() {
// Value v = ValueFactory.createExtendedValue();
// assertValueType(ValueType.MAP, v.getType());
//}

public void assertValueType(ValueType expected, ValueType actual) {
Copy link
Member

Choose a reason for hiding this comment

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

Java guarantees that you can't override Enum#equals. You don't have to check whether expected is the only value in the valueTypes. Assertion can be assertTrue(ValueType.NIL == v.getType()).

Copy link
Member

Choose a reason for hiding this comment

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

Instead, you need to verify ValueType.isXxxType methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

+1. I'll update PR soon.

for (ValueType type: valueTypes) {
if (expected.equals(type)) {
Assert.assertEquals("getType should return " + expected,
expected, actual);
} else {
Assert.assertNotSame("getType should not return " + expected,
type, actual);
}
}
}

}