src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
SearchHistoryEntity implements SearchHistory { @Override public CarmenFeature getCarmenFeature() { return carmenFeature; } SearchHistoryEntity(@NonNull String placeId, CarmenFeature carmenFeature); @Override @NonNull String getPlaceId(); @Override CarmenFeature getCarmenFeature(); } | @Test public void getCarmenFeature_doesReturnTheSetCarmenFeature() throws Exception { CarmenFeature feature = CarmenFeature.builder() .id("myCarmenFeature") .properties(new JsonObject()) .build(); SearchHistoryEntity entity = new SearchHistoryEntity("placeId", feature); assertNotNull(entity.getCarmenFeature()); assertT... |
DraggableAnnotationController { boolean startDragging(@NonNull Annotation annotation, @NonNull AnnotationManager annotationManager) { if (annotation.isDraggable()) { for (OnAnnotationDragListener d : (List<OnAnnotationDragListener>) annotationManager.getDragListeners()) { d.onAnnotationDragStarted(annotation); } dragge... | @Test public void annotationNotDraggableTest() { when(annotation.isDraggable()).thenReturn(false); draggableAnnotationController.startDragging(annotation, annotationManager); verify(dragListener, times(0)).onAnnotationDragStarted(annotation); }
@Test public void annotationDragStartTest() { when(annotation.isDraggable()... |
DraggableAnnotationController { void stopDragging(@Nullable Annotation annotation, @Nullable AnnotationManager annotationManager) { if (annotation != null && annotationManager != null) { for (OnAnnotationDragListener d : (List<OnAnnotationDragListener>) annotationManager.getDragListeners()) { d.onAnnotationDragFinished... | @Test public void annotationDragStopNoneTest() { draggableAnnotationController.stopDragging(null, null); verify(dragListener, times(0)).onAnnotationDragFinished(annotation); }
@Test public void annotationDragStopTest() { when(annotation.isDraggable()).thenReturn(true); when(annotationManager.getDragListeners()).thenRet... |
CarmenFeatureConverter { @TypeConverter public static CarmenFeature toCarmenFeature(String serializedCarmenFeature) { return serializedCarmenFeature == null ? null : CarmenFeature.fromJson(serializedCarmenFeature); } private CarmenFeatureConverter(); @TypeConverter static CarmenFeature toCarmenFeature(String serialize... | @Test public void toCarmenFeature_equalsNull() throws Exception { CarmenFeature carmenFeature = CarmenFeatureConverter.toCarmenFeature(null); assertNull(carmenFeature); }
@Test public void toCarmenFeature_successfullyConvertsToFeature() throws Exception { String json = "{\"id\":\"place.9962989141465270\",\"type\":\"Fea... |
DraggableAnnotationController { boolean onMoveBegin(MoveGestureDetector detector) { for (AnnotationManager annotationManager : annotationManagers) { if (detector.getPointersCount() == 1) { Annotation annotation = annotationManager.queryMapForFeatures(detector.getFocalPoint()); if (annotation != null && startDragging(an... | @Test public void gestureOnMoveBeginWrongPointersTest() { when(annotation.isDraggable()).thenReturn(true); when(annotationManager.getDragListeners()).thenReturn(dragListenerList); PointF pointF = new PointF(); when(annotationManager.queryMapForFeatures(pointF)).thenReturn(annotation); when(moveGestureDetector.getFocalP... |
SymbolManager extends AnnotationManager<SymbolLayer, Symbol, SymbolOptions, OnSymbolDragListener, OnSymbolClickListener, OnSymbolLongClickListener> { @Override public void setFilter(@NonNull Expression expression) { layerFilter = expression; layer.setFilter(layerFilter); } @UiThread SymbolManager(@NonNull MapView mapV... | @Test public void testInitialization() { symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); verify(style).addSource(geoJsonSource); verify(style).addLayer(symbolLayer); assertTrue(symbolManager.dataDrivenPropertyUsageMap.size() > 0); for (Boolea... |
SymbolManager extends AnnotationManager<SymbolLayer, Symbol, SymbolOptions, OnSymbolDragListener, OnSymbolClickListener, OnSymbolLongClickListener> { @UiThread public List<Symbol> create(@NonNull String json) { return create(FeatureCollection.fromJson(json)); } @UiThread SymbolManager(@NonNull MapView mapView, @NonNul... | @Test public void testAddSymbol() { symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); Symbol symbol = symbolManager.create(new SymbolOptions().withLatLng(new LatLng())); assertEquals(symbolManager.getAnnotations().get(0), symbol); }
@Test publi... |
CarmenFeatureConverter { @TypeConverter public static String fromCarmenFeature(@NonNull CarmenFeature carmenFeature) { return carmenFeature.toJson(); } private CarmenFeatureConverter(); @TypeConverter static CarmenFeature toCarmenFeature(String serializedCarmenFeature); @TypeConverter static String fromCarmenFeature(@... | @Test public void fromCarmenFeature_doesSerializeCorrectly() { String json = "{\"type\":\"Feature\",\"id\":\"id\",\"geometry\":{\"type\":\"Point\"," + "\"coordinates\":[1.0,2.0]},\"properties\":{\"hello\":\"world\"},\"address\":\"address\"," + "\"matching_place_name\":\"matchingPlaceName\",\"language\":\"language\"}"; ... |
PlacePickerOptions implements BasePlaceOptions, Parcelable { public static Builder builder() { return new AutoValue_PlacePickerOptions.Builder() .includeReverseGeocode(true) .includeDeviceLocationButton(false); } @Override @Nullable abstract String language(); @Override @Nullable abstract String geocodingTypes(); @Nul... | @Test public void builder() throws Exception { PlaceOptions.Builder builder = PlaceOptions.builder(); assertNotNull(builder); } |
PlacePicker { @Nullable public static CarmenFeature getPlace(Intent data) { String json = data.getStringExtra(PlaceConstants.RETURNING_CARMEN_FEATURE); if (json == null) { return null; } return CarmenFeature.fromJson(json); } private PlacePicker(); @Nullable static CarmenFeature getPlace(Intent data); static CameraPos... | @Test public void getPlace_returnsNullWhenJsonNotFound() throws Exception { Intent data = new Intent(); CarmenFeature carmenFeature = PlacePicker.getPlace(data); assertNull(carmenFeature); }
@Test public void getPlace_returnsDeserializedCarmenFeature() throws Exception { String json = "{\"type\":\"Feature\",\"id\":\"id... |
CircleManager extends AnnotationManager<CircleLayer, Circle, CircleOptions, OnCircleDragListener, OnCircleClickListener, OnCircleLongClickListener> { @Override public void setFilter(@NonNull Expression expression) { layerFilter = expression; layer.setFilter(layerFilter); } @UiThread CircleManager(@NonNull MapView mapV... | @Test public void testInitialization() { circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); verify(style).addSource(geoJsonSource); verify(style).addLayer(circleLayer); assertTrue(circleManager.dataDrivenPropertyUsageMap.size() > 0); for (Boolea... |
CircleManager extends AnnotationManager<CircleLayer, Circle, CircleOptions, OnCircleDragListener, OnCircleClickListener, OnCircleLongClickListener> { @UiThread public List<Circle> create(@NonNull String json) { return create(FeatureCollection.fromJson(json)); } @UiThread CircleManager(@NonNull MapView mapView, @NonNul... | @Test public void testAddCircle() { circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); Circle circle = circleManager.create(new CircleOptions().withLatLng(new LatLng())); assertEquals(circleManager.getAnnotations().get(0), circle); }
@Test publi... |
PlacePicker { public static CameraPosition getLastCameraPosition(Intent data) { return data.getParcelableExtra(PlaceConstants.MAP_CAMERA_POSITION); } private PlacePicker(); @Nullable static CarmenFeature getPlace(Intent data); static CameraPosition getLastCameraPosition(Intent data); } | @Test @Ignore public void getLastCameraPosition() throws Exception { CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(2.0, 3.0)) .bearing(30) .zoom(20) .build(); Parcel parcel = mock(Parcel.class); cameraPosition.writeToParcel(parcel, 0); parcel.setDataPosition(0); Intent data = mock(Inte... |
LineManager extends AnnotationManager<LineLayer, Line, LineOptions, OnLineDragListener, OnLineClickListener, OnLineLongClickListener> { @Override public void setFilter(@NonNull Expression expression) { layerFilter = expression; layer.setFilter(layerFilter); } @UiThread LineManager(@NonNull MapView mapView, @NonNull Ma... | @Test public void testInitialization() { lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); verify(style).addSource(geoJsonSource); verify(style).addLayer(lineLayer); assertTrue(lineManager.dataDrivenPropertyUsageMap.size() > 0); for (Boolean value ... |
TightCouplingProcessor { public List<View> generateView() { Assert.notNull(project, "Project must not be null"); Assert.notNull(projectEvent, "Event must not be null"); Assert.notNull(commit, "Commit must not be null"); Assert.notNull(commit, "Commit must contain files"); if (commit.getFiles().size() == 0) return null;... | @Test public void generateView() throws Exception { MessageDigest md5 = java.security.MessageDigest.getInstance("MD5"); Commit commit = new Commit(Arrays.asList(new File("file1.txt"), new File("file2.txt"))); Project project = new Project("test"); project.setIdentity(1L); project.setOwner("test"); project.setStatus(Pro... |
TightCouplingProcessor { List<List<String>> subsets(List<String> set) { List<List<String>> subsets = new ArrayList<>(); int n = set.size(); for (int i = 0; i < (1 << n); i++) { List<String> combination = new ArrayList<>(); for (int j = 0; j < n; j++) if ((i & (1 << j)) > 0) combination.add(set.get(j)); if (combination.... | @Test public void subsetReturnsCorrectCombinations() { TightCouplingProcessor tightCouplingProcessor = new TightCouplingProcessor(); List<String> input = Arrays.asList("a", "b", "c"); List<List<String>> expected = Arrays.asList(Arrays.asList("a", "b"), Arrays.asList("a", "c"), Arrays.asList("b", "c")); List<List<String... |
InvocationStatistics { public void addInvocation(Invocation invocation) { numberOfInvocations++; if (this.methodName != null) { this.methodName = invocation.getMethodName(); } this.recentDuration = invocation.getRecentDuration(); this.lastInvocationTimestamp = invocation.getCreationTime(); String currentException = inv... | @Test public void addInvocation() { Invocation first = new Invocation(null, 15, null, 1); Invocation second = new Invocation(null, 15, null, 2); Invocation another = new Invocation(null, 30, null, 2); this.cut.addInvocation(first); this.cut.addInvocation(second); this.cut.addInvocation(another); long averageDuration = ... |
InvocationMonitoring { public void reset() { this.statistics.clear(); } @PostConstruct void init(); void onNewCall(@Observes Invocation invocation); List<InvocationStatistics> getExceptional(); List<InvocationStatistics> getUnstable(); List<InvocationStatistics> getSlowest(); List<InvocationStatistics> getRecent(); vo... | @Test public void reset() { Invocation ex1 = new Invocation("unstable", 1, "lazy - don't call me", 1); Invocation ex2 = new Invocation("does not matter", 2, null, 2); this.cut.onNewCall(ex1); this.cut.onNewCall(ex2); List<InvocationStatistics> recent = this.cut.getRecent(); assertThat(recent.size(), is(2)); this.cut.re... |
BluetoothController implements Closeable { public boolean isBluetoothEnabled() { return bluetooth.isEnabled(); } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnabled(); void startDiscovery(); void turnOnBluetooth(); boolean pair(BluetoothD... | @Test public void whenTryCheckThatBluetoothIsEnabledShouldCheckThatMethodReturnCorrectData() throws Exception { Activity activity = mock(Activity.class); BluetoothDiscoveryDeviceListener listener = mock(BluetoothDiscoveryDeviceListener.class); BluetoothAdapter adapter = mock(BluetoothAdapter.class); mockStatic(Bluetoot... |
BluetoothController implements Closeable { public void turnOnBluetooth() { Log.d(TAG, "Enabling Bluetooth."); broadcastReceiverDelegator.onBluetoothTurningOn(); bluetooth.enable(); } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnabled(); ... | @Test public void whenTryEnableBluetoothShouldCheckThatBluetoothAdapterCallEnableMethod() throws Exception { Activity activity = mock(Activity.class); BluetoothDiscoveryDeviceListener listener = mock(BluetoothDiscoveryDeviceListener.class); BluetoothAdapter adapter = mock(BluetoothAdapter.class); mockStatic(BluetoothAd... |
BluetoothController implements Closeable { public boolean isDiscovering() { return bluetooth.isDiscovering(); } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnabled(); void startDiscovery(); void turnOnBluetooth(); boolean pair(BluetoothDe... | @Test public void whenTryCallDiscoveringMethodOnBluetoothShouldCheckThatIsCalled() throws Exception { Activity activity = mock(Activity.class); BluetoothDiscoveryDeviceListener listener = mock(BluetoothDiscoveryDeviceListener.class); BluetoothAdapter adapter = mock(BluetoothAdapter.class); mockStatic(BluetoothAdapter.c... |
BluetoothController implements Closeable { public int getPairingDeviceStatus() { if (this.boundingDevice == null) { throw new IllegalStateException("No device currently bounding"); } int bondState = this.boundingDevice.getBondState(); if (bondState != BluetoothDevice.BOND_BONDING) { this.boundingDevice = null; } return... | @Test(expected = IllegalStateException.class) public void whenTryBoundingDeviceButDeviceIsNullShouldCheckThatThrowException() throws Exception { Activity activity = mock(Activity.class); BluetoothDiscoveryDeviceListener listener = mock(BluetoothDiscoveryDeviceListener.class); BluetoothAdapter adapter = mock(BluetoothAd... |
BluetoothController implements Closeable { public static String getDeviceName(BluetoothDevice device) { String deviceName = device.getName(); if (deviceName == null) { deviceName = device.getAddress(); } return deviceName; } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener... | @Test public void whenTryGetDeviceNameShouldCheckThatAllIsOK() throws Exception { BluetoothDevice device = mock(BluetoothDevice.class); when(device.getName()).thenReturn("android"); assertThat(BluetoothController.getDeviceName(device), is("android")); }
@Test public void whenTryGetDeviceNameButItIsNullShouldCheckThatCo... |
BluetoothController implements Closeable { public boolean isAlreadyPaired(BluetoothDevice device) { return bluetooth.getBondedDevices().contains(device); } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnabled(); void startDiscovery(); void... | @Test public void whenTryCheckThatDevicesAlreadyPairedShouldCheckThatMethodWorksCorrect() throws Exception { Activity activity = mock(Activity.class); Set<BluetoothDevice> devices = new HashSet<>(); BluetoothDevice device = mock(BluetoothDevice.class); devices.add(device); BluetoothDiscoveryDeviceListener listener = mo... |
BluetoothController implements Closeable { public static String deviceToString(BluetoothDevice device) { return "[Address: " + device.getAddress() + ", Name: " + device.getName() + "]"; } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnable... | @Test public void whenTryCastDeviceToStringShouldCheckThatAllIsOk() throws Exception { BluetoothDevice device = mock(BluetoothDevice.class); when(device.getName()).thenReturn("device"); when(device.getAddress()).thenReturn("08-ED-B9-49-B2-E5"); String actual = "[Address: 08-ED-B9-49-B2-E5, Name: device]"; assertEquals(... |
BluetoothController implements Closeable { public void turnOnBluetoothAndScheduleDiscovery() { this.bluetoothDiscoveryScheduled = true; turnOnBluetooth(); } BluetoothController(Activity context,BluetoothAdapter adapter, BluetoothDiscoveryDeviceListener listener); boolean isBluetoothEnabled(); void startDiscovery(); voi... | @Test public void whenTurnOnBluetoothAndScheduleDiscoveryShouldCheckThatBTenabled() throws Exception { Activity activity = mock(Activity.class); BluetoothDiscoveryDeviceListener listener = mock(BluetoothDiscoveryDeviceListener.class); BluetoothAdapter adapter = mock(BluetoothAdapter.class); mockStatic(BluetoothAdapter.... |
ReflectionUtil { public static Set<Class> getSubTypes(final Class<?> clazz) { Set<Class> subClasses = subclassesCache.get(clazz); if (null == subClasses) { updateReflectionPackages(); final Set<Class> newSubClasses = new HashSet<>(); if (clazz.isInterface()) { getScanner().matchClassesImplementing(clazz, c -> { if (isP... | @Test public void shouldReturnUnmodifiableClasses() { final Set<Class> subclasses = ReflectionUtil.getSubTypes(Number.class); assertThrows(UnsupportedOperationException.class, () -> subclasses.add(String.class)); }
@Test public void shouldCacheSubclasses() { final Set<Class> subclasses = ReflectionUtil.getSubTypes(Numb... |
Regex extends KoryphePredicate<String> { @Override public boolean test(final String input) { return !(null == input || input.getClass() != String.class) && controlValue.matcher(input).matches(); } Regex(); Regex(final String controlValue); Regex(final Pattern controlValue); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, ... | @Test public void shouldAccepValidValue() { final Regex filter = new Regex("te[a-d]{3}st"); boolean accepted = filter.test("teaadst"); assertTrue(accepted); }
@Test public void shouldRejectInvalidValue() { final Regex filter = new Regex("fa[a-d]{3}il"); boolean accepted = filter.test("favcdil"); assertFalse(accepted); ... |
Regex extends KoryphePredicate<String> { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonProperty("value") public Pattern getControlValue() { return controlValue; } Regex(); Regex(final String controlValue); Regex(final Pattern controlValue); @JsonTypeInfo(use = JsonTypeInfo.... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final Regex filter = new Regex("test"); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.Regex\",%n" + " \"value\" : {%n" + " \"java.util.r... |
AreIn extends KoryphePredicate<Collection<?>> { @Override public boolean test(final Collection<?> input) { return null == allowedValues || allowedValues.isEmpty() || (null != input && allowedValues.containsAll(input)); } AreIn(); AreIn(final Collection<?> allowedValues); AreIn(final Object... allowedValues); @JsonIgn... | @Test public void shouldAcceptWhenValuesAndInputAreNullOrEmpty() { final AreIn filter = new AreIn(); boolean accepted = filter.test((Collection) null); assertTrue(accepted); }
@Test public void shouldAcceptWhenValuesIsEmpty() { final AreIn filter = new AreIn(); boolean accepted = filter.test(list); assertTrue(accepted)... |
IterableUtil { public static <T> CloseableIterable<T> concat(final Iterable<? extends Iterable<? extends T>> iterables) { return new ChainedIterable<>(iterables); } private IterableUtil(); static CloseableIterable<T> filter(final Iterable<T> iterable, final Predicate predicate); static CloseableIterable<T> filter(fina... | @Test public void shouldWrapAllIterables() { final List<Integer> itr1 = Collections.singletonList(0); final List<Integer> itr2 = new ArrayList<>(0); final List<Integer> itr3 = Lists.newArrayList(1, 2, 3, 4); final List<Integer> itr4 = Lists.newArrayList(5, 6); final Iterable<Integer> itrConcat = IterableUtil.concat(Arr... |
AreIn extends KoryphePredicate<Collection<?>> { @JsonIgnore public Collection<?> getValues() { return allowedValues; } AreIn(); AreIn(final Collection<?> allowedValues); AreIn(final Object... allowedValues); @JsonIgnore Collection<?> getValues(); void setValues(final Collection<?> allowedValues); @JsonTypeInfo(use = ... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final AreIn filter = new AreIn(VALUE1); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.AreIn\",%n" + " \"values\" : [{\"uk.gov.gchq.koryp... |
IsMoreThan extends KoryphePredicate<Comparable> implements InputValidator { @Override public boolean test(final Comparable input) { if (null == input || !controlValue.getClass().isAssignableFrom(input.getClass())) { return false; } final int compareVal = controlValue.compareTo(input); if (orEqualTo) { return compareVal... | @Test public void shouldAcceptTheValueWhenMoreThan() { final IsMoreThan filter = new IsMoreThan(5); boolean accepted = filter.test(6); assertTrue(accepted); }
@Test public void shouldAcceptTheValueWhenMoreThanAndOrEqualToIsTrue() { final IsMoreThan filter = new IsMoreThan(5, true); boolean accepted = filter.test(6); as... |
IsMoreThan extends KoryphePredicate<Comparable> implements InputValidator { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonProperty("value") public Comparable getControlValue() { return controlValue; } IsMoreThan(); IsMoreThan(final Comparable<?> controlValue); IsMoreThan(fi... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final CustomObj controlValue = new CustomObj(); final IsMoreThan filter = new IsMoreThan(controlValue); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.i... |
IsMoreThan extends KoryphePredicate<Comparable> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == controlValue) { result.addError("Control value has not been set"); return result; } if (null == ar... | @Test public void shouldCheckInputClass() { final IsMoreThan predicate = new IsMoreThan(1); assertTrue(predicate.isInputValid(Integer.class).isValid()); assertFalse(predicate.isInputValid(Double.class).isValid()); assertFalse(predicate.isInputValid(Integer.class, Integer.class).isValid()); } |
IsXMoreThanY extends KoryphePredicate2<Comparable, Comparable> implements InputValidator { @Override public boolean test(final Comparable input1, final Comparable input2) { return null != input1 && null != input2 && input1.getClass() == input2.getClass() && (input1.compareTo(input2) > 0); } @Override boolean test(fina... | @Test public void shouldAcceptWhenMoreThan() { final IsXMoreThanY filter = new IsXMoreThanY(); boolean accepted = filter.test(2, 1); assertTrue(accepted); }
@Test public void shouldRejectTheValueWhenMoreThan() { final IsXMoreThanY filter = new IsXMoreThanY(); boolean accepted = filter.test(5, 6); assertFalse(accepted);... |
IsXMoreThanY extends KoryphePredicate2<Comparable, Comparable> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 2 != arguments.length || null == arguments[0] || null == arguments[1])... | @Test public void shouldCheckInputClass() { final IsXLessThanY predicate = new IsXLessThanY(); assertTrue(predicate.isInputValid(Integer.class, Integer.class).isValid()); assertTrue(predicate.isInputValid(String.class, String.class).isValid()); assertFalse(predicate.isInputValid(Double.class).isValid()); assertFalse(pr... |
And extends PredicateComposite<I, Predicate<I>> { @Override public boolean test(final I input) { if (components == null || components.isEmpty()) { return true; } else { return super.test(input); } } And(); And(final Predicate<?>... predicates); And(final List<Predicate> predicates); @Override boolean test(final I inp... | @Test public void shouldAcceptWhenAllFunctionsAccept() { final Predicate<String> func1 = mock(Predicate.class); final Predicate<String> func2 = mock(Predicate.class); final Predicate<String> func3 = mock(Predicate.class); final And<String> and = new And<>(func1, func2, func3); given(func1.test("value")).willReturn(true... |
AreEqual extends KoryphePredicate2<Object, Object> { @Override public boolean test(final Object input1, final Object input2) { if (null == input1) { return null == input2; } return input1.equals(input2); } @Override boolean test(final Object input1, final Object input2); } | @Test public void shouldAcceptTheWhenEqualValues() { final AreEqual equals = new AreEqual(); boolean accepted = equals.test("test", "test"); assertTrue(accepted); }
@Test public void shouldAcceptWhenAllNull() { final AreEqual equals = new AreEqual(); boolean accepted = equals.test(null, null); assertTrue(accepted); }
@... |
IsFalse extends KoryphePredicate<Boolean> { @Override public boolean test(final Boolean input) { return Boolean.FALSE.equals(input); } @Override boolean test(final Boolean input); } | @Test public void shouldAcceptTheValueWhenFalse() { final IsFalse filter = new IsFalse(); boolean accepted = filter.test(false); assertTrue(accepted); }
@Test public void shouldAcceptTheValueWhenObjectFalse() { final IsFalse filter = new IsFalse(); boolean accepted = filter.test(Boolean.FALSE); assertTrue(accepted); }
... |
IsA extends KoryphePredicate<Object> { @Override public boolean test(final Object input) { return null == input || null == type || type.isAssignableFrom(input.getClass()); } IsA(); IsA(final Class<?> type); IsA(final String type); void setType(final String type); String getType(); @Override boolean test(final Object ... | @Test public void shouldAcceptTheValueWhenSameClass() { final IsA predicate = new IsA(String.class); boolean valid = predicate.test("Test"); assertTrue(valid); }
@Test public void shouldRejectTheValueWhenDifferentClasses() { final IsA predicate = new IsA(String.class); boolean valid = predicate.test(5); assertFalse(val... |
IterableUtil { public static <T> CloseableIterable<T> limit(final Iterable<T> iterable, final int start, final Integer end, final boolean truncate) { return new LimitedIterable<>(iterable, start, end, truncate); } private IterableUtil(); static CloseableIterable<T> filter(final Iterable<T> iterable, final Predicate pr... | @Test public void shouldLimitResultsToFirstItem() { final List<Integer> values = Arrays.asList(0, 1, 2, 3); final int start = 0; final int end = 1; final CloseableIterable<Integer> limitedValues = IterableUtil.limit(values, start, end, true); assertEquals(values.subList(start, end), Lists.newArrayList(limitedValues)); ... |
IsA extends KoryphePredicate<Object> { public String getType() { return null != type ? type.getName() : null; } IsA(); IsA(final Class<?> type); IsA(final String type); void setType(final String type); String getType(); @Override boolean test(final Object input); @Override boolean equals(final Object obj); @Override ... | @Test public void shouldCreateIsAFromClassName() { final String type = "java.lang.String"; final IsA predicate = new IsA(type); assertNotNull(predicate); assertEquals(predicate.getType(), type); }
@Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final Class<Integer> type = Integer.class; final... |
AbstractInTimeRange extends KoryphePredicate<T> { @Override public String toString() { return new ToStringBuilder(this) .appendSuper(predicate.toString()) .toString(); } protected AbstractInTimeRange(final AbstractInTimeRangeDual<T> predicate); @Override boolean test(final T value); String getStart(); Long getStartOff... | @Test public void shouldAcceptValuesInRangeDayOffsetFromStart() { final long start = System.currentTimeMillis() - 100 * DAYS_TO_MILLISECONDS; final long end = System.currentTimeMillis() - 60 * DAYS_TO_MILLISECONDS; final AbstractInTimeRange<T> filter = createBuilder() .start(Long.toString(start)) .startOffset(-7L) .end... |
AbstractInTimeRangeDual extends KoryphePredicate2<Comparable<T>, Comparable<T>> { @JsonGetter("timeZone") public String getTimeZoneId() { return null != timeZone ? timeZone.getID() : null; } protected AbstractInTimeRangeDual(); protected AbstractInTimeRangeDual(final Function<Long, T> toT); void initialise(); @Overri... | @Test public void shouldSetSystemPropertyTimeZone() { final String timeZone = "Etc/GMT+6"; System.setProperty(DateUtil.TIME_ZONE, timeZone); final AbstractInTimeRangeDual predicate = createBuilder() .start("1") .end("10") .startFullyContained(true) .endFullyContained(true) .build(); assertEquals(timeZone, predicate.get... |
Not extends KoryphePredicate<I> implements InputValidator { @Override public boolean test(final I input) { return null != predicate && !predicate.test(input); } Not(); Not(final Predicate<I> predicate); void setPredicate(final Predicate<I> predicate); Predicate<I> getPredicate(); @Override boolean test(final I input);... | @Test public void shouldAcceptTheValueWhenTheWrappedFunctionReturnsFalse() { final Predicate<String> function = mock(Predicate.class); final Not<String> filter = new Not<>(function); given(function.test("some value")).willReturn(false); boolean accepted = filter.test("some value"); assertTrue(accepted); verify(function... |
Not extends KoryphePredicate<I> implements InputValidator { public Predicate<I> getPredicate() { return predicate; } Not(); Not(final Predicate<I> predicate); void setPredicate(final Predicate<I> predicate); Predicate<I> getPredicate(); @Override boolean test(final I input); @Override boolean equals(final Object obj);... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final IsA isA = new IsA(String.class); final Not<Object> filter = new Not<>(isA); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.Not\",%n... |
IsTrue extends KoryphePredicate<Boolean> { @Override public boolean test(final Boolean input) { return Boolean.TRUE.equals(input); } @Override boolean test(final Boolean input); } | @Test public void shouldAcceptTheValueWhenTrue() { final IsTrue filter = new IsTrue(); boolean accepted = filter.test(true); assertTrue(accepted); }
@Test public void shouldAcceptTheValueWhenObjectTrue() { final IsTrue filter = new IsTrue(); boolean accepted = filter.test(Boolean.TRUE); assertTrue(accepted); }
@Test pu... |
IsEqual extends KoryphePredicate<Object> { @Override public boolean test(final Object input) { if (null == controlValue) { return null == input; } return controlValue.equals(input); } IsEqual(); IsEqual(final Object controlValue); @JsonProperty("value") @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo... | @Test public void shouldAcceptTheTestValue() { final IsEqual filter = new IsEqual("test"); boolean accepted = filter.test("test"); assertTrue(accepted); }
@Test public void shouldAcceptWhenControlValueAndTestValueAreNull() { final IsEqual filter = new IsEqual(); boolean accepted = filter.test(null); assertTrue(accepted... |
IsEqual extends KoryphePredicate<Object> { @JsonProperty("value") @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) public Object getControlValue() { return controlValue; } IsEqual(); IsEqual(final Object controlValue); @JsonProperty("value") @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final CustomObj controlValue = new CustomObj(); final IsEqual filter = new IsEqual(controlValue); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.pr... |
CollectionContains extends KoryphePredicate<Collection<?>> { @Override public boolean test(final Collection<?> input) { return input.contains(value); } CollectionContains(); CollectionContains(final Object value); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class") Object... | @Test public void shouldAcceptWhenValueInList() { final CollectionContains filter = new CollectionContains(VALUE1); boolean accepted = filter.test(list); assertTrue(accepted); }
@Test public void shouldAcceptWhenValueInSet() { final CollectionContains filter = new CollectionContains(VALUE1); boolean accepted = filter.t... |
CollectionContains extends KoryphePredicate<Collection<?>> { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class") public Object getValue() { return value; } CollectionContains(); CollectionContains(final Object value); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = J... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final CollectionContains filter = new CollectionContains(VALUE1); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.CollectionContains\",%n"... |
MapContainsPredicate extends KoryphePredicate<Map> { @Override public boolean test(final Map input) { if (null != input && null != keyPredicate) { for (final Object key : input.keySet()) { if (keyPredicate.test(key)) { return true; } } } return false; } MapContainsPredicate(); MapContainsPredicate(final Predicate keyP... | @Test public void shouldAcceptWhenKeyEqualsInMap() { final MapContainsPredicate filter = new MapContainsPredicate(KEY_PREDICATE_1); boolean accepted = filter.test(map1); assertTrue(accepted); }
@Test public void shouldAcceptWhenKeyRegexInMap() { final MapContainsPredicate filter = new MapContainsPredicate(KEY_PREDICATE... |
MapContainsPredicate extends KoryphePredicate<Map> { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class") public Predicate getKeyPredicate() { return keyPredicate; } MapContainsPredicate(); MapContainsPredicate(final Predicate keyPredicate); @JsonTypeInfo(use = JsonTypeInf... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final MapContainsPredicate filter = new MapContainsPredicate(KEY_PREDICATE_1); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals("{" + "\"class\":\"uk.gov.gchq.koryphe.impl.predicate.MapContainsPredicate\"," + "\"... |
AgeOffFromDays extends KoryphePredicate2<Long, Integer> { @Override public boolean test(final Long timestamp, final Integer days) { return null != timestamp && null != days && (System.currentTimeMillis() - (days * DAYS_TO_MILLISECONDS) < timestamp); } @Override boolean test(final Long timestamp, final Integer days); s... | @Test public void shouldAcceptWhenWithinAgeOffLimit() { final AgeOffFromDays filter = new AgeOffFromDays(); final boolean accepted = filter.test(System.currentTimeMillis() - AGE_OFF_MILLISECONDS + MINUTE_IN_MILLISECONDS, AGE_OFF_DAYS); assertTrue(accepted); }
@Test public void shouldAcceptWhenOutsideAgeOffLimit() { fin... |
IsLessThan extends KoryphePredicate<Comparable> implements InputValidator { @Override public boolean test(final Comparable input) { if (null == input || !controlValue.getClass().isAssignableFrom(input.getClass())) { return false; } final int compareVal = controlValue.compareTo(input); if (orEqualTo) { return compareVal... | @Test public void shouldAcceptWhenLessThan() { final IsLessThan filter = new IsLessThan(5); boolean accepted = filter.test(4); assertTrue(accepted); }
@Test public void shouldAcceptWhenLessThanAndOrEqualToIsTrue() { final IsLessThan filter = new IsLessThan(5, true); boolean accepted = filter.test(4); assertTrue(accepte... |
IsLessThan extends KoryphePredicate<Comparable> implements InputValidator { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonProperty("value") public Comparable getControlValue() { return controlValue; } IsLessThan(); IsLessThan(final Comparable<?> controlValue); IsLessThan(fi... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final CustomObj controlValue = new CustomObj(); final IsLessThan filter = new IsLessThan(controlValue); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.i... |
IsLessThan extends KoryphePredicate<Comparable> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == controlValue) { result.addError("Control value has not been set"); return result; } if (null == ar... | @Test public void shouldCheckInputClass() { final IsLessThan predicate = new IsLessThan(1); assertTrue(predicate.isInputValid(Integer.class).isValid()); assertFalse(predicate.isInputValid(Double.class).isValid()); assertFalse(predicate.isInputValid(Integer.class, Integer.class).isValid()); } |
IsLongerThan extends KoryphePredicate<Object> implements InputValidator { @Override public boolean test(final Object input) { if (null == input) { return true; } if (orEqualTo) { return getLength(input) >= minLength; } else { return getLength(input) > minLength; } } IsLongerThan(); IsLongerThan(final int minLength); ... | @Test public void shouldAcceptTheValueWhenMoreThan() { final IsLongerThan filter = new IsLongerThan(5); final boolean accepted = filter.test("123456"); assertTrue(accepted); }
@Test public void shouldRejectTheValueWhenLessThan() { final IsLongerThan filter = new IsLongerThan(5); final boolean accepted = filter.test("12... |
IsLongerThan extends KoryphePredicate<Object> implements InputValidator { public int getMinLength() { return minLength; } IsLongerThan(); IsLongerThan(final int minLength); IsLongerThan(final int minLength, final boolean orEqualTo); int getMinLength(); void setMinLength(final int minLength); boolean isOrEqualTo(); vo... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final int min = 5; final IsLongerThan filter = new IsLongerThan(min); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsLongerThan\",%n" +... |
IsLongerThan extends KoryphePredicate<Object> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 1 != arguments.length || null == arguments[0]) { result.addError("Incorrect number of a... | @Test public void shouldCheckInputClass() { final IsLongerThan predicate = new IsLongerThan(10); assertTrue(predicate.isInputValid(String.class).isValid()); assertTrue(predicate.isInputValid(Object[].class).isValid()); assertTrue(predicate.isInputValid(Integer[].class).isValid()); assertTrue(predicate.isInputValid(Coll... |
MapContains extends KoryphePredicate<Map> { @Override public boolean test(final Map input) { return input.containsKey(key); } MapContains(); MapContains(final String key); String getKey(); void setKey(final String key); @Override boolean test(final Map input); @Override boolean equals(final Object obj); @Override int ... | @Test public void shouldAcceptWhenKeyInMap() { final MapContains filter = new MapContains(KEY1); boolean accepted = filter.test(map1); assertTrue(accepted); }
@Test public void shouldRejectWhenKeyNotPresent() { final MapContains filter = new MapContains(KEY2); boolean accepted = filter.test(map1); assertFalse(accepted)... |
MapContains extends KoryphePredicate<Map> { public String getKey() { return key; } MapContains(); MapContains(final String key); String getKey(); void setKey(final String key); @Override boolean test(final Map input); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); } | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final MapContains filter = new MapContains(KEY1); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.MapContains\",%n" + " \"key\" : \"key1\"... |
IsXLessThanY extends KoryphePredicate2<Comparable, Comparable> implements InputValidator { @Override public boolean test(final Comparable input1, final Comparable input2) { return null != input1 && null != input2 && input1.getClass() == input2.getClass() && (input1.compareTo(input2) < 0); } @Override boolean test(fina... | @Test public void shouldAcceptWhenLessThan() { final IsXLessThanY filter = new IsXLessThanY(); boolean accepted = filter.test(1, 2); assertTrue(accepted); }
@Test public void shouldRejectTheValueWhenMoreThan() { final IsXLessThanY filter = new IsXLessThanY(); boolean accepted = filter.test(6, 5); assertFalse(accepted);... |
ReflectionUtil { public static Map<String, Set<Class>> getSimpleClassNames(final Class<?> clazz) { Map<String, Set<Class>> simpleClassNames = simpleClassNamesCache.get(clazz); if (null == simpleClassNames) { final Set<Class> subTypes = getSubTypes(clazz); simpleClassNames = new HashMap<>(subTypes.size()); for (final Cl... | @Test public void shouldReturnUnmodifiableSimpleClassNames() { final Map<String, Set<Class>> simpleClassNames = ReflectionUtil.getSimpleClassNames(Number.class); assertThrows(UnsupportedOperationException.class, () -> simpleClassNames.put("test", new HashSet<>())); }
@Test public void shouldCacheSimpleNames() { final M... |
IsXLessThanY extends KoryphePredicate2<Comparable, Comparable> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 2 != arguments.length || null == arguments[0] || null == arguments[1])... | @Test public void shouldCheckInputClass() { final IsXLessThanY predicate = new IsXLessThanY(); assertTrue(predicate.isInputValid(Integer.class, Integer.class).isValid()); assertTrue(predicate.isInputValid(String.class, String.class).isValid()); assertFalse(predicate.isInputValid(Double.class).isValid()); assertFalse(pr... |
Or extends PredicateComposite<I, Predicate<I>> { @Override public boolean test(final I input) { for (final Predicate<I> predicate : components) { try { if (predicate.test(input)) { return true; } } catch (final ClassCastException e) { if (predicate instanceof TupleAdaptedPredicate && !(input instanceof Tuple)) { if (((... | @Test public void shouldAcceptWhenOneFunctionsAccepts() { final Predicate<String> func1 = mock(Predicate.class); final Predicate<String> func2 = mock(Predicate.class); final Predicate<String> func3 = mock(Predicate.class); final Or<String> or = new Or<>(func1, func2, func3); given(func1.test("value")).willReturn(false)... |
AgeOff extends KoryphePredicate<Long> { public long getAgeOffTime() { return ageOffTime; } AgeOff(); AgeOff(final long ageOffTime); @Override boolean test(final Long input); long getAgeOffTime(); void setAgeOffTime(final long ageOffTime); void setAgeOffDays(final int ageOfDays); void setAgeOffHours(final long ageOfHou... | @Test public void shouldUseDefaultAgeOffTime() { final AgeOff filter = new AgeOff(); final long ageOfTime = filter.getAgeOffTime(); assertEquals(AgeOff.AGE_OFF_TIME_DEFAULT, ageOfTime); }
@Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final AgeOff filter = new AgeOff(CUSTOM_AGE_OFF); final S... |
AgeOff extends KoryphePredicate<Long> { @Override public boolean test(final Long input) { return null != input && (System.currentTimeMillis() - input) < ageOffTime; } AgeOff(); AgeOff(final long ageOffTime); @Override boolean test(final Long input); long getAgeOffTime(); void setAgeOffTime(final long ageOffTime); void... | @Test public void shouldAcceptWhenWithinAgeOffLimit() { final AgeOff filter = new AgeOff(CUSTOM_AGE_OFF); final boolean accepted = filter.test(System.currentTimeMillis() - CUSTOM_AGE_OFF + MINUTE_IN_MILLISECONDS); assertTrue(accepted); }
@Test public void shouldAcceptWhenOutsideAgeOffLimit() { final AgeOff filter = new... |
If extends KoryphePredicate<I> { @Override public boolean test(final I input) { boolean conditionTmp; if (null == condition) { conditionTmp = null != predicate && predicate.test(input); } else { conditionTmp = condition; } if (conditionTmp) { return null != then && then.test(input); } return null != otherwise && otherw... | @Test public void shouldReturnTrueWithSuccessfulThen() { final Object input = "testValue"; final Predicate then = mock(Predicate.class); final Predicate otherwise = mock(Predicate.class); final If<Object> filter = new If<>(true, then, otherwise); given(then.test(input)).willReturn(true); final boolean accepted = filter... |
IsIn extends KoryphePredicate<Object> { @Override public boolean test(final Object input) { return null != allowedValues && allowedValues.contains(input); } IsIn(); IsIn(final Collection<Object> controlData); IsIn(final Object... controlData); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPP... | @Test public void shouldAcceptWhenValueInList() { final IsIn filter = new IsIn(Arrays.asList("A", "B", "C")); boolean accepted = filter.test("B"); assertTrue(accepted); }
@Test public void shouldRejectWhenValueNotInList() { final IsIn filter = new IsIn(Arrays.asList("A", "B", "C")); boolean accepted = filter.test("D");... |
IsIn extends KoryphePredicate<Object> { @JsonIgnore public Set<Object> getAllowedValues() { return allowedValues; } IsIn(); IsIn(final Collection<Object> controlData); IsIn(final Object... controlData); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonProperty("values") Object... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final Object[] controlData = {1, new CustomObj(), 3}; final IsIn filter = new IsIn(Arrays.asList(controlData)); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.k... |
Exists extends KoryphePredicate<Object> { @Override public boolean test(final Object input) { return null != input; } @Override boolean test(final Object input); } | @Test public void shouldAcceptTheValueWhenNotNull() { final Exists filter = new Exists(); boolean accepted = filter.test("Not null value"); assertTrue(accepted); }
@Test public void shouldRejectTheValueWhenNull() { final Exists filter = new Exists(); boolean accepted = filter.test(null); assertFalse(accepted); } |
MultiRegex extends KoryphePredicate<String> { @Override public boolean test(final String input) { if (null == input || input.getClass() != String.class) { return false; } for (final Pattern pattern : patterns) { if (pattern.matcher(input).matches()) { return true; } } return false; } MultiRegex(); MultiRegex(final Pat... | @Test public void shouldAcceptValidValue() { Pattern[] patterns = new Pattern[2]; patterns[0] = Pattern.compile("fail"); patterns[1] = Pattern.compile("pass"); final MultiRegex filter = new MultiRegex(patterns); boolean accepted = filter.test("pass"); assertTrue(accepted); }
@Test public void shouldRejectInvalidValue()... |
MultiRegex extends KoryphePredicate<String> { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonProperty("value") public Pattern[] getPatterns() { return Arrays.copyOf(patterns, patterns.length); } MultiRegex(); MultiRegex(final Pattern... patterns); @JsonTypeInfo(use = JsonType... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { Pattern[] patterns = new Pattern[2]; patterns[0] = Pattern.compile("test"); patterns[1] = Pattern.compile("test2"); final MultiRegex filter = new MultiRegex(patterns); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEq... |
IsShorterThan extends KoryphePredicate<Object> implements InputValidator { @Override public boolean test(final Object input) { if (null == input) { return true; } if (orEqualTo) { return getLength(input) <= maxLength; } else { return getLength(input) < maxLength; } } IsShorterThan(); IsShorterThan(final int maxLength)... | @Test public void shouldAcceptTheValueWhenLessThan() { final IsShorterThan filter = new IsShorterThan(5); final boolean accepted = filter.test("1234"); assertTrue(accepted); }
@Test public void shouldRejectTheValueWhenMoreThan() { final IsShorterThan filter = new IsShorterThan(5); final boolean accepted = filter.test("... |
IsShorterThan extends KoryphePredicate<Object> implements InputValidator { public int getMaxLength() { return maxLength; } IsShorterThan(); IsShorterThan(final int maxLength); IsShorterThan(final int maxLength, final boolean orEqualTo); int getMaxLength(); void setMaxLength(final int maxLength); boolean isOrEqualTo()... | @Test public void shouldJsonSerialiseAndDeserialise() throws IOException { final int max = 5; final IsShorterThan filter = new IsShorterThan(max); final String json = JsonSerialiser.serialise(filter); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsShorterThan\",%n... |
IsShorterThan extends KoryphePredicate<Object> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 1 != arguments.length || null == arguments[0]) { result.addError("Incorrect number of ... | @Test public void shouldCheckInputClass() { final IsShorterThan predicate = new IsShorterThan(10); assertTrue(predicate.isInputValid(String.class).isValid()); assertTrue(predicate.isInputValid(Object[].class).isValid()); assertTrue(predicate.isInputValid(Integer[].class).isValid()); assertTrue(predicate.isInputValid(Co... |
StringConcat extends KorypheBinaryOperator<String> { public void setSeparator(final String separator) { this.separator = separator; } StringConcat(); StringConcat(final String separator); @Override String _apply(final String a, final String b); String getSeparator(); void setSeparator(final String separator); @Overrid... | @Test public void shouldConcatStringsTogether() { final StringConcat function = new StringConcat(); function.setSeparator(";"); state = function.apply(state, "1"); state = function.apply(state, "2"); state = function.apply(state, null); assertEquals("1;2", state); } |
StringDeduplicateConcat extends KorypheBinaryOperator<String> { @Override protected String _apply(final String a, final String b) { final Set<String> set = new LinkedHashSet<>(); Collections.addAll(set, p.split(StringUtils.removeStart(a, separator))); Collections.addAll(set, p.split(StringUtils.removeStart(b, separator... | @Test public void shouldRemoveDuplicate() { final StringDeduplicateConcat sdc = new StringDeduplicateConcat(); String output = sdc._apply("test,string", "test,success"); assertEquals("test,string,success", output); }
@Test public void shouldHandleTrailingDelimiter() { final StringDeduplicateConcat sdc = new StringDedup... |
ExtractKeys extends KorypheFunction<Map<K, V>, Iterable<K>> { @Override public Iterable<K> apply(final Map<K, V> map) { return null == map ? null : map.keySet(); } @Override Iterable<K> apply(final Map<K, V> map); } | @Test public void shouldExtractKeysFromGivenMap() { final ExtractKeys<String, Integer> function = new ExtractKeys<>(); final Map<String, Integer> input = new HashMap<>(); input.put("first", 1); input.put("second", 2); input.put("third", 3); final Iterable<String> results = function.apply(input); assertEquals(Sets.newHa... |
DivideBy extends KorypheFunction<Integer, Tuple2<Integer, Integer>> { @Override public Tuple2<Integer, Integer> apply(final Integer input) { if (input == null) { return null; } else { return new Tuple2<>(input / by, input % by); } } DivideBy(); DivideBy(final int by); int getBy(); void setBy(final int by); @Override T... | @Test public void shouldDivideBy2() { final DivideBy function = new DivideBy(2); Tuple2<Integer, Integer> output = function.apply(4); assertEquals(new Tuple2<>(2, 0), output); }
@Test public void shouldDivideBy2WithRemainder() { final DivideBy function = new DivideBy(2); Tuple2<Integer, Integer> output = function.apply... |
DivideBy extends KorypheFunction<Integer, Tuple2<Integer, Integer>> { public int getBy() { return by; } DivideBy(); DivideBy(final int by); int getBy(); void setBy(final int by); @Override Tuple2<Integer, Integer> apply(final Integer input); @Override boolean equals(final Object o); @Override int hashCode(); } | @Test @Override public void shouldJsonSerialiseAndDeserialise() throws IOException { final DivideBy function = new DivideBy(4); final String json = JsonSerialiser.serialise(function); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.function.DivideBy\",%n" + " \"by\" : 4%n" + "... |
StringJoin extends KorypheFunction<Iterable<I_ITEM>, String> { @Override public String apply(final Iterable<I_ITEM> items) { return StringUtils.join(IterableUtil.map(items, new ToString()), delimiter); } StringJoin(); StringJoin(final String delimiter); @Override String apply(final Iterable<I_ITEM> items); String getD... | @Test public void shouldHandleNullInput() { final StringJoin function = new StringJoin(); final String result = function.apply(null); assertNull(result); }
@Test public void shouldHandleNullDelimiter() { final StringJoin<String> function = new StringJoin<>(null); final Set<String> input = Sets.newHashSet("a", "b", "c")... |
PredicateComposite extends Composite<C> implements Predicate<I>, InputValidator { @Override public boolean test(final I input) { for (final C predicate : components) { try { if (!predicate.test(input)) { return false; } } catch (final ClassCastException e) { if (predicate instanceof TupleAdaptedPredicate && !(input ins... | @Test public void shouldPassInputToTupleAdaptedPredicateIfAutomaticallyUnpacked() { Integer unpackedInput = 5; Tuple1<Integer> input = new Tuple1<>(unpackedInput); PredicateComposite predicateComposite = new PredicateComposite<>( Arrays.asList(new TupleAdaptedPredicate<>(new IsLessThan(10), new Integer[]{0})) ); boolea... |
StringRegexSplit extends KorypheFunction<String, List<String>> { @Override public List<String> apply(final String input) { if (null == input) { return null; } final Pattern pattern = Pattern.compile(regex); return Arrays.asList(pattern.split(input)); } StringRegexSplit(); StringRegexSplit(final String regex); @Overrid... | @Test public void shouldHandleNullInput() { final StringRegexSplit function = new StringRegexSplit(); final List<String> result = function.apply(null); assertNull(result); }
@Test public void shouldSplitString() { final StringRegexSplit function = new StringRegexSplit(","); final String input = "first,second,third"; fi... |
FirstValid extends KorypheFunction<Iterable<I_ITEM>, I_ITEM> { @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class") public Predicate getPredicate() { return predicate; } FirstValid(); FirstValid(final Predicate predicate); @Override I_ITEM apply(final Iterable<I_ITEM> iter... | @Test @Override public void shouldJsonSerialiseAndDeserialise() throws IOException { final FirstValid predicate = getInstance(); final String json = JsonSerialiser.serialise(predicate); JsonSerialiser.assertEquals("{" + "\"class\":\"uk.gov.gchq.koryphe.impl.function.FirstValid\"," + "\"predicate\":{\"class\":\"uk.gov.g... |
ToLong extends KorypheFunction<Object, Long> { @Override public Long apply(final Object value) { if (null == value) { return null; } if (value instanceof Number) { return ((Number) value).longValue(); } if (value instanceof String) { return Long.valueOf(((String) value)); } throw new IllegalArgumentException("Could not... | @Test public void shouldConvertToLong() { final ToLong function = new ToLong(); Object output = function.apply(5); assertEquals(5L, output); assertEquals(Long.class, output.getClass()); }
@Test public void shouldReturnNullWhenValueIsNull() { final ToLong function = new ToLong(); final Object output = function.apply(nul... |
ToTuple extends KorypheFunction<Object, Tuple<?>> { @Override public Tuple<?> apply(final Object value) { if (isNull(value)) { return null; } if (value instanceof Tuple) { return (Tuple<?>) value; } if (value instanceof Map) { return new MapTuple<>(((Map<?, Object>) value)); } if (value instanceof Object[]) { return ne... | @Test public void shouldConvertListIntoArrayTuple() { final ToTuple function = new ToTuple(); Tuple output = function.apply(Lists.newArrayList(1, 2, 3, 4)); assertEquals(new ArrayTuple(1, 2, 3, 4), output); }
@Test public void shouldConvertPrimitiveArrayIntoArrayTuple() { final ToTuple function = new ToTuple(); Tuple o... |
NthItem extends KorypheFunction<Iterable<T>, T> { public int getSelection() { return selection; } NthItem(); NthItem(final int selection); @Override @SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored") T apply(final Iterable<T> input); void setSelection(final int selection... | @Test @Override public void shouldJsonSerialiseAndDeserialise() throws IOException { final NthItem function = new NthItem(2); final String json = JsonSerialiser.serialise(function); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.function.NthItem\",%n" + " \"selection\" : 2%n"... |
NthItem extends KorypheFunction<Iterable<T>, T> { @Override @SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored") public T apply(final Iterable<T> input) { if (null == input) { throw new IllegalArgumentException("Input cannot be null"); } try { return Iterables.get(input, se... | @Test public void shouldReturnCorrectValueWithInteger() { final NthItem<Integer> function = new NthItem<>(2); final Integer result = function.apply(Arrays.asList(1, 2, 3, 4, 5)); assertNotNull(result); assertEquals(3, result); }
@Test public void shouldReturnCorrectValueWithString() { final NthItem<String> function = n... |
LastItem extends KorypheFunction<Iterable<T>, T> { @Override @SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored") public T apply(final Iterable<T> input) { if (null == input) { throw new IllegalArgumentException("Input cannot be null"); } try { return Iterables.getLast(inpu... | @Test public void shouldReturnCorrectValueWithInteger() { final LastItem<Integer> function = new LastItem<>(); final Integer result = function.apply(Arrays.asList(2, 3, 5, 7, 11)); assertNotNull(result); assertEquals(new Integer(11), result); }
@Test public void shouldReturnCorrectValueWithString() { final LastItem<Str... |
Divide extends KorypheFunction2<Integer, Integer, Tuple2<Integer, Integer>> { @Override public Tuple2<Integer, Integer> apply(final Integer input1, final Integer input2) { int in2 = input2 == null ? 1 : input2; if (input1 == null) { return null; } else { return new Tuple2<>(input1 / in2, input1 % in2); } } @Override T... | @Test public void shouldDivide2() { final Divide function = new Divide(); Tuple2<Integer, Integer> output = function.apply(4, 2); assertEquals(new Tuple2<>(2, 0), output); }
@Test public void shouldDivideBy2WithRemainder() { final Divide function = new Divide(); Tuple2<Integer, Integer> output = function.apply(5, 2); a... |
DictionaryLookup extends KorypheFunction<K, V> { @Override public V apply(final K key) { if (dictionary == null) { throw new IllegalArgumentException("The " + DictionaryLookup.class.getName() + " KorypheFunction has not been provided with a dictionary"); } return dictionary.get(key); } DictionaryLookup(); DictionaryLo... | @Test public void shouldReturnExistingValueInDictionary() { assertEquals(1, (int) dictionaryLookUp.apply("one")); assertEquals(2, (int) dictionaryLookUp.apply("two")); }
@Test public void shouldReturnNullIfNullKeyIsSupplied() { assertNull(dictionaryLookUp.apply(null)); }
@Test public void shouldReturnNullIfItemDoesntEx... |
CsvLinesToMaps extends KorypheFunction<Iterable<String>, Iterable<Map<String, Object>>> implements Serializable { @Override public Iterable<Map<String, Object>> apply(final Iterable<String> csvStrings) { if (isNull(csvStrings)) { return null; } final CloseableIterable<String> csvRecords = IterableUtil.limit(csvStrings,... | @Test public void shouldReturnNullForNullInput() { final CsvLinesToMaps function = new CsvLinesToMaps(); final List<String> input = null; final Object result = function.apply(input); assertNull(result); } |
Gunzip extends KorypheFunction<byte[], byte[]> { @SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS", justification = "Returning null means the input was null") @Override public byte[] apply(final byte[] compressed) { if (isNull(compressed)) { return null; } if (compressed.length == 0) { return new byte[0]; } ... | @Test public void shouldUncompressString() throws IOException { final Gunzip function = new Gunzip(); final byte[] input = "test string".getBytes(); final byte[] gzip; try (final ByteArrayOutputStream out = new ByteArrayOutputStream(); final GZIPOutputStream gzipOut = new GZIPOutputStream(out)) { gzipOut.write(input); ... |
Length extends KorypheFunction<Object, Integer> implements InputValidator { @Override public Integer apply(final Object value) { final int length; if (null == value) { length = 0; } else if (value instanceof String) { length = ((String) value).length(); } else if (value instanceof Object[]) { length = ((Object[]) value... | @Test public void shouldReturnZeroForNullInputValue() { final Length function = new Length(); final Integer result = function.apply(null); assertEquals(new Integer(0), result); }
@Test public void shouldReturnLengthForStringInput() { final Length function = new Length(); final String input = "testString"; final Integer... |
Length extends KorypheFunction<Object, Integer> implements InputValidator { @Override public ValidationResult isInputValid(final Class<?>... arguments) { final ValidationResult result = new ValidationResult(); if (null == arguments || 1 != arguments.length || null == arguments[0]) { result.addError("Incorrect number of... | @Test public void shouldCheckInputClass() { final Length function = new Length(); assertTrue(function.isInputValid(String.class).isValid()); assertTrue(function.isInputValid(Object[].class).isValid()); assertTrue(function.isInputValid(Integer[].class).isValid()); assertTrue(function.isInputValid(Collection.class).isVal... |
DeserialiseJson extends KorypheFunction<String, T> implements Serializable { public DeserialiseJson<T> outputClass(final Class<T> outputClass) { setOutputClass(outputClass); return this; } DeserialiseJson(); DeserialiseJson(final Class<T> outputClass); @Override T apply(final String json); Class<T> getOutputClass(); D... | @Test @Override public void shouldJsonSerialiseAndDeserialise() throws IOException { final DeserialiseJson function = new DeserialiseJson().outputClass(Map.class); final String json = JsonSerialiser.serialise(function); JsonSerialiser.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.function.... |
DeserialiseJson extends KorypheFunction<String, T> implements Serializable { @Override public T apply(final String json) { if (isNull(json)) { return null; } try { return MAPPER.readValue(json, outputClass); } catch (final IOException e) { throw new RuntimeException("Failed to deserialise JSON", e); } } DeserialiseJson... | @Test public void shouldParseJson() { final DeserialiseJson function = new DeserialiseJson(); final String input = "{\"elements\": [{\"value\": \"value1\"}, {\"value\": \"value2\"}]}"; Object result = function.apply(input); Map<String, Object> element2aMap = new HashMap<>(); element2aMap.put("value", "value1"); Map<Str... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.