Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicatesTest.java')
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicatesTest.java183
1 files changed, 183 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicatesTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicatesTest.java
new file mode 100644
index 00000000000..57f6556c71f
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicatesTest.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.util;
+
+import static org.eclipse.osee.framework.core.enums.DeletionFlag.EXCLUDE_DELETED;
+import static org.eclipse.osee.framework.core.enums.DeletionFlag.INCLUDE_DELETED;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.attributeContainsPattern;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.attributeStringEquals;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.attributeValueEquals;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.deletionFlagEquals;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.excludeDeleted;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.includeDeleted;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.isDirty;
+import static org.eclipse.osee.orcs.core.internal.util.OrcsPredicates.isNotDirty;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import java.util.Date;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.internal.attribute.Attribute;
+import org.eclipse.osee.orcs.data.HasDeleteState;
+import org.eclipse.osee.orcs.data.Modifiable;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import com.google.common.base.Predicate;
+
+/**
+ * Test Case for {@link OrcsPredicates}
+ *
+ * @author Roberto E. Escobar
+ */
+public class OrcsPredicatesTest {
+
+ // @formatter:off
+ @Mock private Modifiable dirty;
+ @Mock private Modifiable notDirty;
+
+ @Mock private HasDeleteState deleted;
+ @Mock private HasDeleteState notDeleted;
+
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute1;
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute2;
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute3;
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute4;
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute5;
+ // @formatter:on
+
+ private Date date;
+
+ @Before
+ public void init() throws OseeCoreException {
+ MockitoAnnotations.initMocks(this);
+
+ when(dirty.isDirty()).thenReturn(true);
+ when(notDirty.isDirty()).thenReturn(false);
+
+ when(deleted.isDeleted()).thenReturn(true);
+ when(notDeleted.isDeleted()).thenReturn(false);
+
+ date = new Date();
+
+ when(attribute1.getValue()).thenReturn(45789L);
+ when(attribute2.getValue()).thenReturn(true);
+ when(attribute3.getValue()).thenReturn(date);
+ when(attribute4.getValue()).thenReturn("Hello");
+ when(attribute5.getValue()).thenReturn(true);
+ }
+
+ @Test
+ public void testAcceptDirties() {
+ assertFalse(isDirty().apply(notDirty));
+ assertTrue(isDirty().apply(dirty));
+ }
+
+ @Test
+ public void testAcceptNoneDirties() {
+ assertTrue(isNotDirty().apply(notDirty));
+ assertFalse(isNotDirty().apply(dirty));
+ }
+
+ @Test
+ public void testIncludeDeleted() {
+ assertTrue(includeDeleted().apply(deleted));
+ assertTrue(includeDeleted().apply(notDeleted));
+ }
+
+ @Test
+ public void testExcludeDeleted() {
+ assertFalse(excludeDeleted().apply(deleted));
+ assertTrue(excludeDeleted().apply(notDeleted));
+ }
+
+ @Test
+ public void testDeletionFlag() {
+ when(attribute1.isDeleted()).thenReturn(true);
+ when(attribute2.isDeleted()).thenReturn(false);
+
+ assertFalse(deletionFlagEquals(EXCLUDE_DELETED).apply(attribute1));
+ assertTrue(deletionFlagEquals(EXCLUDE_DELETED).apply(attribute2));
+
+ assertTrue(deletionFlagEquals(INCLUDE_DELETED).apply(attribute1));
+ assertTrue(deletionFlagEquals(INCLUDE_DELETED).apply(attribute2));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAttributeStringEquals() throws OseeCoreException {
+ assertTrue(attributeStringEquals("45789").apply(attribute1));
+ assertTrue(attributeStringEquals("true").apply(attribute2));
+ assertTrue(attributeStringEquals(date.toString()).apply(attribute3));
+
+ assertFalse(attributeStringEquals("Helo").apply(attribute1));
+ assertFalse(attributeStringEquals("Hello").apply(attribute2));
+
+ Date date2 = new Date(123123111231L);
+
+ assertFalse(attributeStringEquals(date2.toString()).apply(attribute3));
+
+ assertFalse(attributeStringEquals("true").apply(attribute1));
+ assertFalse(attributeStringEquals("false").apply(attribute1));
+ assertFalse(attributeStringEquals("false").apply(attribute2));
+
+ when(attribute1.getValue()).thenReturn((String) null);
+
+ assertTrue(attributeStringEquals(null).apply(attribute1));
+ assertFalse(attributeStringEquals("null").apply(attribute1));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAttributeValueEquals() {
+ assertTrue(attributeValueEquals("Hello").apply(attribute4));
+ assertTrue(attributeValueEquals(true).apply(attribute5));
+
+ assertFalse(attributeValueEquals("Helo").apply(attribute4));
+ assertFalse(attributeValueEquals("Hello").apply(attribute5));
+
+ assertFalse(attributeValueEquals(true).apply(attribute4));
+ assertFalse(attributeValueEquals(false).apply(attribute4));
+ assertFalse(attributeValueEquals(false).apply(attribute5));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAttributeContainsPattern() throws OseeCoreException {
+ when(attribute1.getValue()).thenReturn("123-456-7890", "00-000-0000", "000-000-0000");
+
+ Predicate<Attribute<CharSequence>> telAttribute = attributeContainsPattern("[0-9]{3}[-][0-9]{3}[-][0-9]{4}");
+
+ assertTrue(telAttribute.apply(attribute1));
+ assertFalse(telAttribute.apply(attribute1));
+ assertTrue(telAttribute.apply(attribute1));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAttributeContainsPattern2() throws OseeCoreException {
+ Pattern pattern = Pattern.compile("[0-9]{3}[-][0-9]{3}[-][0-9]{4}");
+ when(attribute1.getValue()).thenReturn("123-456-7890", "00-000-0000", "000-000-0000");
+
+ Predicate<Attribute<CharSequence>> telAttribute = attributeContainsPattern(pattern);
+
+ assertTrue(telAttribute.apply(attribute1));
+ assertFalse(telAttribute.apply(attribute1));
+ assertTrue(telAttribute.apply(attribute1));
+ }
+}

Back to the top