/*
 * Copyright 2015-2019 the original author or authors.
 *
 * 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.bremersee.comparator;

import junit.framework.TestCase;
import org.bremersee.comparator.testmodel.ComplexObject;
import org.bremersee.comparator.testmodel.SimpleGetObject;
import org.bremersee.comparator.testmodel.SimpleIsObject;
import org.bremersee.comparator.testmodel.SimpleObject;
import org.junit.Test;

/**
 * The comparator builder tests.
 *
 * @author Christian Bremer
 */
public class ComparatorBuilderTests {

  /**
   * Test primitive type.
   */
  @Test
  public void testPrimitiveType() {
    System.out.println("Testing primitive type ...");
    int result = ComparatorBuilder.builder()
        .build()
        .compare(1, 2);
    System.out.println(result);
    TestCase.assertTrue(result < 0);
    System.out.println("OK\n");
  }

  /**
   * Test simple object.
   */
  @Test
  public void testSimpleObject() {
    System.out.println("Testing simple object ...");
    int result = ComparatorBuilder.builder()
        .field("number", true, true, false)
        .build()
        .compare(new SimpleObject(1), new SimpleObject(2));
    System.out.println(result);
    TestCase.assertTrue(result < 0);
    System.out.println("OK\n");
  }

  /**
   * Test simple get object.
   */
  @Test
  public void testSimpleGetObject() {
    System.out.println("Testing simple 'get' object ...");
    int result = ComparatorBuilder.builder()
        .field("number", true, true, false)
        .build()
        .compare(new SimpleGetObject(1),
            new SimpleGetObject(2));
    System.out.println(result);
    TestCase.assertTrue(result < 0);
    System.out.println("OK\n");
  }

  /**
   * Test simple is object.
   */
  @Test
  public void testSimpleIsObject() {
    System.out.println("Testing simple 'is' object ...");
    int result = ComparatorBuilder.builder()
        .field("nice", false, true, false)
        .build()
        .compare(new SimpleIsObject(true),
            new SimpleIsObject(false));
    System.out.println(result);
    TestCase.assertTrue(result < 0);
    System.out.println("OK\n");
  }

  /**
   * Test complex object.
   */
  @Test
  public void testComplexObject() {
    System.out.println("Testing complex object ...");
    int result = ComparatorBuilder.builder()
        .field("simple.number", true, true, false)
        .build()
        .compare(
            new ComplexObject(new SimpleObject(1)),
            new ComplexObject(new SimpleObject(2)));
    System.out.println(result);
    TestCase.assertTrue(result < 0);
    System.out.println("OK\n");
  }

}

@@ -650,16 +650,64 @@
 rator;%0A%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A
 import j
@@ -953,32 +953,57 @@
 l.SimpleObject;%0A
+import org.junit.Assert;%0A
 import org.junit
@@ -3205,10 +3205,579 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Test comparing of complex objects.%0A   */%0A  @Test%0A  public void testComparingOfComplexObjects() %7B%0A    ComplexObject a = new ComplexObject(new SimpleObject(1));%0A    ComplexObject b = new ComplexObject(new SimpleObject(2));%0A%0A    List%3CComplexObject%3E list = Arrays.asList(b, a);%0A%0A    Assert.assertEquals(b, list.get(0));%0A    Assert.assertEquals(a, list.get(1));%0A%0A    list.sort(ComparatorBuilder.builder()%0A        .field(%22simple.number%22, true, true, false)%0A        .build());%0A%0A    Assert.assertEquals(a, list.get(0));%0A    Assert.assertEquals(b, list.get(1));%0A  %7D%0A%0A
 %7D%0A

Version 2.0.0-SNAPSHOT