content: /*
   * Copyright (C) 2016 david.wei (lighters)
   *
   * 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.lighters.demos.junit;
  
  /**
   * Created by david on 16/8/22.
   * Email: huangdiv5@gmail.com
   * GitHub: https://github.com/alighters
   */
  
  import java.util.Arrays;
  import org.hamcrest.core.CombinableMatcher;
  import org.junit.Test;
  
  import static org.hamcrest.CoreMatchers.allOf;
  import static org.hamcrest.CoreMatchers.anyOf;
  import static org.hamcrest.CoreMatchers.both;
  import static org.hamcrest.CoreMatchers.containsString;
  import static org.hamcrest.CoreMatchers.equalTo;
  import static org.hamcrest.CoreMatchers.everyItem;
  import static org.hamcrest.CoreMatchers.hasItems;
  import static org.hamcrest.CoreMatchers.not;
  import static org.hamcrest.CoreMatchers.sameInstance;
  import static org.hamcrest.CoreMatchers.startsWith;
  import static org.junit.Assert.assertArrayEquals;
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertNotNull;
  import static org.junit.Assert.assertNotSame;
  import static org.junit.Assert.assertNull;
  import static org.junit.Assert.assertSame;
  import static org.junit.Assert.assertThat;
  import static org.junit.Assert.assertTrue;
  
  public class AssertTests {
      @Test
      public void testAssertArrayEquals() {
          byte[] expected = "trial".getBytes();
          byte[] actual = "trial".getBytes();
          assertArrayEquals("failure - byte arrays not same", expected, actual);
      }
  
      @Test
      public void testAssertEquals() {
          assertEquals("failure - strings are not equal", "text", "text");
      }
  
      @Test
      public void testAssertFalse() {
          assertFalse("failure - should be false", false);
      }
  
      @Test
      public void testAssertNotNull() {
          assertNotNull("should not be null", new Object());
      }
  
      @Test
      public void testAssertNotSame() {
          assertNotSame("should not be same Object", new Object(), new Object());
      }
  
      @Test
      public void testAssertNull() {
          assertNull("should be null", null);
      }
  
      @Test
      public void testAssertSame() {
          Integer aNumber = Integer.valueOf(768);
          assertSame("should be same", aNumber, aNumber);
      }
  
      @Test
      public void testAssertTrue() {
          assertTrue("failure - should be true", true);
      }
  
      // JUnit Matchers assertThat
      @Test
      public void testAssertThatBothContainsString() {
          assertThat("albumen", both(containsString("a")).and(containsString("b")));
      }
  
      @Test
      public void testAssertThatHasItems() {
          assertThat(Arrays.asList("one", "two", "three"), hasItems("one", "three"));
      }
  
      @Test
      public void testAssertThatEveryItemContainsString() {
          assertThat(Arrays.asList(new String[] { "fun", "ban", "net" }), everyItem(containsString("n")));
      }
  
      // Core Hamcrest Matchers with assertThat
      @Test
      public void testAssertThatHamcrestCoreMatchers() {
          assertThat("good", allOf(equalTo("good"), startsWith("good")));
          assertThat("good", not(allOf(equalTo("bad"), equalTo("good"))));
          assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
          assertThat(7, not(CombinableMatcher.<Integer>either(equalTo(3)).or(equalTo(4))));
          assertThat(new Object(), not(sameInstance(new Object())));
      }
  }
  