001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.api.model.predicate; 015 016import org.junit.jupiter.api.Test; 017 018import static org.hamcrest.CoreMatchers.both; 019import static org.hamcrest.CoreMatchers.equalTo; 020import static org.hamcrest.CoreMatchers.not; 021import static org.hamcrest.MatcherAssert.assertThat; 022import static org.junit.jupiter.api.Assertions.assertThrows; 023import static org.mockito.Mockito.mock; 024 025public class NotPredicateTest { 026 027 @Test 028 public void testBasics() { 029 Predicate p = mock(Predicate.class); 030 031 NotPredicate np = new NotPredicate(p); 032 assertThat(p, equalTo(np.getPredicate())); 033 } 034 035 @Test 036 public void testEquals() { 037 Predicate p = mock(Predicate.class); 038 039 Predicate np1 = new NotPredicate(p); 040 Predicate np2 = new NotPredicate(p); 041 042 assertThat(np1, both(equalTo(np1)).and(equalTo(np2))); 043 044 np2 = new NotPredicate(mock(Predicate.class)); 045 assertThat(np1, not(equalTo(np2))); 046 047 assertThat(p, not(equalTo(np1))); 048 } 049 050 @Test 051 public void testHashcode() { 052 Predicate p = mock(Predicate.class); 053 054 Predicate np1 = new NotPredicate(p); 055 Predicate np2 = new NotPredicate(p); 056 057 assertThat(np1.hashCode(), both(equalTo(np1.hashCode())).and(equalTo(np2.hashCode()))); 058 059 np2 = new NotPredicate(mock(Predicate.class)); 060 assertThat(np1.hashCode(), not(equalTo(np2.hashCode()))); 061 062 assertThat(p.hashCode(), not(equalTo(np1.hashCode()))); 063 } 064 065 @Test 066 public void testNullConstructor() { 067 assertThrows(NullPointerException.class, () -> new NotPredicate(null)); 068 } 069}