/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * 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.pushtechnology.diffusion.transform.adder;

import static com.pushtechnology.diffusion.client.topics.details.TopicType.BINARY;
import static com.pushtechnology.diffusion.transform.transformer.Transformers.identity;
import static com.pushtechnology.diffusion.transform.transformer.Transformers.stringToBinary;
import static java.nio.charset.Charset.forName;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.MockitoAnnotations.initMocks;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import com.pushtechnology.diffusion.client.features.control.topics.TopicControl;
import com.pushtechnology.diffusion.datatype.binary.Binary;
import com.pushtechnology.diffusion.transform.transformer.TransformationException;
import com.pushtechnology.diffusion.transform.transformer.Transformer;
import com.pushtechnology.diffusion.transform.transformer.UnsafeTransformer;

/**
 * Unit tests for {@link BoundSafeTopicAdderBuilderImpl}.
 *
 * @author Push Technology Limited
 */
public final class BoundSafeTopicAdderBuilderImplTest {

    @Mock
    private TopicControl control;

    @Before
    public void setUp() {
        initMocks(this);
    }

    @After
    public void postConditions() {
        verifyNoMoreInteractions(control);
    }

    @Test
    public void transform() {
        final BoundSafeTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transform(stringToBinary(forName("UTF-8")));

        assertNotNull(builder);
    }

    @Test
    public void transformToClass() {
        final BoundSafeTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transform(stringToBinary(forName("UTF-8")), String.class);

        assertNotNull(builder);
    }

    @Test
    public void transformWith() {
        final BoundTransformedTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transformWith(new UnsafeTransformer<String, Binary>() {
                    @Override
                    public Binary transform(String value) throws Exception {
                        return null;
                    }
                });

        assertNotNull(builder);
    }

    @Test
    public void transformWithToClass() {
        final BoundTransformedTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transformWith(new UnsafeTransformer<String, Binary>() {
                    @Override
                    public Binary transform(String value) throws Exception {
                        return null;
                    }
                }, String.class);

        assertNotNull(builder);
    }

    @Test
    public void transformTransformer() {
        final BoundTransformedTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transform(new Transformer<String, Binary>() {
                    @Override
                    public Binary transform(String value) throws TransformationException {
                        return null;
                    }
                });

        assertNotNull(builder);
    }

    @Test
    public void transformTransformerToClass() {
        final BoundTransformedTopicAdderBuilder<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, identity(Binary.class), control)
                .transform(new Transformer<String, Binary>() {
                    @Override
                    public Binary transform(String value) throws TransformationException {
                        return null;
                    }
                }, String.class);

        assertNotNull(builder);
    }

    @Test
    public void create() {
        final BoundSafeTopicAdderBuilderImpl<Binary, String> builder =
            new BoundSafeTopicAdderBuilderImpl<>(BINARY, stringToBinary(forName("UTF-8")), control);

        final TopicAdder<String> adder = builder.create();

        assertNotNull(adder);
    }
}

@@ -967,23 +967,33 @@
 formers.
-identit
+bigIntegerToBinar
 y;%0Aimpor
@@ -1069,70 +1069,16 @@
 ers.
-stringToBinary;%0Aimport static java.nio.charset.Charset.forName
+identity
 ;%0Aim
@@ -1238,16 +1238,46 @@
 Mocks;%0A%0A
+import java.math.BigInteger;%0A%0A
 import o
@@ -2192,38 +2192,42 @@
 Builder%3CBinary, 
-String
+BigInteger
 %3E builder =%0A    
@@ -2343,39 +2343,27 @@
 orm(
-stringToBinary(forName(%22UTF-8%22)
+bigIntegerToBinary(
 ));%0A
@@ -2490,38 +2490,42 @@
 Builder%3CBinary, 
-String
+BigInteger
 %3E builder =%0A    
@@ -2641,48 +2641,40 @@
 orm(
-stringToBinary(forName(%22UTF-8%22)), String
+bigIntegerToBinary(), BigInteger
 .cla
@@ -4892,38 +4892,42 @@
 derImpl%3CBinary, 
-String
+BigInteger
 %3E builder =%0A    
@@ -4983,39 +4983,27 @@
 RY, 
-stringToBinary(forName(%22UTF-8%22)
+bigIntegerToBinary(
 ), c
@@ -5037,22 +5037,26 @@
 icAdder%3C
-String
+BigInteger
 %3E adder 

Update bound safe topic adder builder unit test to use a big integer.