Package com.jeklsoft.cassandraclient.hector

Source Code of com.jeklsoft.cassandraclient.hector.TestBigDecimalSerializer

//Copyright 2012 Joe McTee
//
//   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 com.jeklsoft.cassandraclient.hector;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;
import java.nio.ByteBuffer;

import org.junit.Test;

import me.prettyprint.hector.api.Serializer;

public class TestBigDecimalSerializer {
    @Test
    public void BigDecimalObjectShouldReturnBigDecimalSerializer() {
        ExtensibleTypeInferringSerializer.addSerializer(BigDecimal.class, BigDecimalSerializer.get());
        BigDecimal value = new BigDecimal(1);
        Serializer serializer = ExtensibleTypeInferringSerializer.getSerializer(value);
        assertEquals(serializer.getClass(), BigDecimalSerializer.class);
    }

    @Test
    public void BigDecimalClassShouldReturnBigDecimalSerializer() {
        ExtensibleTypeInferringSerializer.addSerializer(BigDecimal.class, BigDecimalSerializer.get());
        Serializer serializer = ExtensibleTypeInferringSerializer.getSerializer(BigDecimal.class);
        assertEquals(serializer.getClass(), BigDecimalSerializer.class);
    }

    @Test
    public void SerializingThenDeserializingBigDecimalResultsInSameBigDecimal() {
        ExtensibleTypeInferringSerializer.addSerializer(BigDecimal.class, BigDecimalSerializer.get());
        BigDecimal value = new BigDecimal(1);

        Serializer serializer = ExtensibleTypeInferringSerializer.getSerializer(BigDecimal.class);

        ByteBuffer buffer = serializer.toByteBuffer(value);

        BigDecimal deserializedBigDecimal = (BigDecimal) serializer.fromByteBuffer(buffer);

        assertEquals(value, deserializedBigDecimal);
    }
}
TOP

Related Classes of com.jeklsoft.cassandraclient.hector.TestBigDecimalSerializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.