<commit_before>/*
 * #%L
 * service
 * %%
 * Copyright (C) 2017 MRS Internet Service GmbH
 * %%
 * 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.
 * #L%
 */

package org.mcrossplatform.core.validation;

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mcrossplatform.core.transport.json.JsonSerializable;

public class ValidateTest {

  @Rule
  public ExpectedException exceptionRule = ExpectedException.none();

  @Test
  public void notNull_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("expected not to be null");
    // act
    Validate.notNull(null);
  }

  @Test
  public void notNull_Object_Success() {
    // arrange, act, assert
    Validate.notNull("");
  }

  @Test
  public void greaterThan_LessThan_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("expected at least 5 but not 3");
    // act
    Validate.greaterThan(5, 3);
  }

  @Test
  public void greaterThan_Equals_Success() {
    // arrange, act, assert
    Validate.greaterThan(9, 9);
  }

  @Test
  public void jsonObject_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("JsonObject expected and not null");
    // act
    Validate.jsonObject(null);
  }

  @Test
  public void jsonObject_JsonObject_Success() {
    // arrange, act, assert
    Validate.jsonObject(Json.object());
  }

  @Test
  public void jsonSerializable_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("Unsupported parameter type <null> JsonSerializable expected.");
    // act
    Validate.jsonSerializable(null);
  }

  @Test
  public void jsonSerializable_String_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule
        .expectMessage("Unsupported parameter type java.lang.String JsonSerializable expected.");
    // act
    Validate.jsonSerializable("hello");
  }

  @Test
  public void jsonSerializable_JsonSerializable_Success() {
    // arrange, act, assert
    Validate.jsonSerializable(new JsonSerializable() {

      @Override
      public JsonValue toJson() {
        // TODO Auto-generated method stub
        return null;
      }
    });
  }
}<commit_msg>#8 testcase for ctor<commit_after>/*
 * #%L
 * service
 * %%
 * Copyright (C) 2017 MRS Internet Service GmbH
 * %%
 * 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.
 * #L%
 */

package org.mcrossplatform.core.validation;

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mcrossplatform.core.transport.json.JsonSerializable;

public class ValidateTest {

  @Rule
  public ExpectedException exceptionRule = ExpectedException.none();

  @Test
  public void notNull_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("expected not to be null");
    // act
    Validate.notNull(null);
  }

  @Test
  public void notNull_Object_Success() {
    // arrange, act, assert
    Validate.notNull("");
  }

  @Test
  public void greaterThan_LessThan_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("expected at least 5 but not 3");
    // act
    Validate.greaterThan(5, 3);
  }

  @Test
  public void greaterThan_Equals_Success() {
    // arrange, act, assert
    Validate.greaterThan(9, 9);
  }

  @Test
  public void jsonObject_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("JsonObject expected and not null");
    // act
    Validate.jsonObject(null);
  }

  @Test
  public void jsonObject_JsonObject_Success() {
    // arrange, act, assert
    Validate.jsonObject(Json.object());
  }

  @Test
  public void jsonSerializable_Null_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("Unsupported parameter type <null> JsonSerializable expected.");
    // act
    Validate.jsonSerializable(null);
  }

  @Test
  public void jsonSerializable_String_ThrowsException() {
    // arrange & pre assert
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule
        .expectMessage("Unsupported parameter type java.lang.String JsonSerializable expected.");
    // act
    Validate.jsonSerializable("hello");
  }

  @Test
  public void jsonSerializable_JsonSerializable_Success() {
    // arrange, act, assert
    Validate.jsonSerializable(new JsonSerializable() {

      @Override
      public JsonValue toJson() {
        // TODO Auto-generated method stub
        return null;
      }
    });
  }

  @Test
  public void newInstance_void_throwsIllegalAccessException() throws Exception {
    // arrange & pre assert
    exceptionRule.expect(IllegalAccessException.class);
    Validate.class.newInstance();
  }
}
{'fraction_non_alphanumeric': 0.09630092086780084, 'fraction_numerical': 0.004526299360074918, 'mean_word_length': 3.6233766233766236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4742624', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1765, 'n_words': 486}