<commit_before>/*
 * Copyright © 2014 <<EMAIL>> http://io7m.com
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.jnull;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@SuppressWarnings("static-method") public final class NullCheckTest
{
  @Test public void testNotNull()
  {
    Assert.assertEquals("example", NullCheck.notNull("example"));
  }

  @Test public void testNotNullAll()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(Integer.valueOf(1));
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs));
  }

  @Test public void testNotNullAllMessage()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(Integer.valueOf(1));
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs, "Integers"));
  }

  @Test(expected = NullCheckException.class) public
    void
    testNotNullAllNull_0()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(null);
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs));
  }

  @Test(expected = NullCheckException.class) public
    void
    testNotNullAllNull_1()
  {
    Collection<Object> c = null;
    NullCheck.notNullAll(c);
  }

  @Test(expected = NullCheckException.class) public
    void
    testNotNullAllNullMessage_0()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(null);
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs, "Integers"));
  }

  @Test(expected = NullCheckException.class) public
    void
    testNotNullAllNullMessage_1()
  {
    Collection<Object> c = null;
    NullCheck.notNullAll(c, "Integers");
  }

  @Test public void testNotNullMessage()
  {
    Assert.assertEquals("example", NullCheck.notNull("example", "Message"));
  }

  @Test(expected = NullCheckException.class) public void testNull()
  {
    NullCheck.notNull(null);
  }

  @Test(expected = NullCheckException.class) public void testNullMessage()
  {
    try {
      NullCheck.notNull(null, "value");
    } catch (final NullPointerException x) {
      Assert.assertEquals(
        "Null check failed: expression evaluated to null: value",
        x.getMessage());
      throw x;
    }
  }
}<commit_msg>Improve code coverage and tests<commit_after>/*
 * Copyright © 2014 <<EMAIL>> http://io7m.com
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.jnull;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.hamcrest.core.Is.isA;

@SuppressWarnings("static-method")
public final class NullCheckTest
{
  public NullCheckTest()
  {
    // Nothing
  }

  @Rule public final ExpectedException expected = ExpectedException.none();

  @Test
  public void testNotNull()
  {
    Assert.assertEquals("example", NullCheck.notNull("example"));
  }

  @Test
  public void testNotNullAll()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(Integer.valueOf(1));
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs));
  }

  @Test
  public void testNotNullAllMessage()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(Integer.valueOf(1));
    xs.add(Integer.valueOf(2));
    Assert.assertEquals(xs, NullCheck.notNullAll(xs, "Integers"));
  }

  @Test
  public void
  testNotNullAllNull0()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(null);
    xs.add(Integer.valueOf(2));

    this.expected.expect(NullCheckException.class);
    Assert.assertEquals(xs, NullCheck.notNullAll(xs));
  }

  @Test
  public void
  testNotNullAllNull1()
  {
    final Collection<Object> c = null;

    this.expected.expect(NullCheckException.class);
    NullCheck.notNullAll(c);
  }

  @Test
  public void
  testNotNullAllNullMessage0()
  {
    final List<Integer> xs = new ArrayList<Integer>();
    xs.add(Integer.valueOf(0));
    xs.add(null);
    xs.add(Integer.valueOf(2));

    this.expected.expect(NullCheckException.class);
    Assert.assertEquals(xs, NullCheck.notNullAll(xs, "Integers"));
  }

  @Test
  public void
  testNotNullAllNullMessage1()
  {
    final Collection<Object> c = null;

    this.expected.expect(NullCheckException.class);
    NullCheck.notNullAll(c, "Integers");
  }

  @Test
  public void testNotNullMessage()
  {
    Assert.assertEquals("example", NullCheck.notNull("example", "Message"));
  }

  @Test
  public void testNull()
  {
    this.expected.expect(NullCheckException.class);
    NullCheck.notNull(null);
  }

  @Test(expected = NullCheckException.class)
  public void testNullMessage()
  {
    try {
      NullCheck.notNull(null, "value");
    } catch (final NullPointerException x) {
      Assert.assertEquals(
        "Null check failed: expression evaluated to null: value",
        x.getMessage());
      throw x;
    }
  }

  @Test
  public void testNullExceptionCause()
  {
    final AssertionError ex = new AssertionError("Exception");
    final NullCheckException eex = new NullCheckException("Message", ex);
    Assert.assertEquals(eex.getCause(), ex);
  }

  @Test
  public void testNullCheckUnreachableConstructor()
    throws Exception
  {
    final Constructor<NullCheck> c =
      NullCheck.class.getDeclaredConstructor();
    c.setAccessible(true);

    this.expected.expect(InvocationTargetException.class);
    this.expected.expectCause(isA(RuntimeException.class));
    c.newInstance();
  }
}
{'fraction_non_alphanumeric': 0.11519540858157967, 'fraction_numerical': 0.005465974309920744, 'mean_word_length': 3.8793333333333333, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677494', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2165, 'n_words': 569}