repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
pmonks/alfresco-bulk-import
amp/src/main/java/org/alfresco/extension/bulkimport/impl/BulkImportStatusImpl.java
// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java // public interface BulkImportSource // { // /** // * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>. // */ // String getName(); // // // /** // * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>. // */ // String getDescription(); // // // /** // * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>. // */ // Map<String, String> getParameters(); // // // /** // * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>. // */ // String getConfigWebScriptURI(); // // // /** // * Called before anything else, so that the source can validate and parse its parameters. If the parameters are invalid, // * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid. // * // * @param status The status object to use to pre-register any source-side statistics <i>(will not be null)</li>. // * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>. // */ // void init(BulkImportSourceStatus status, Map<String, List<String>> parameters); // // // /** // * Query to determine whether an "in-place" import is possible, given the provided parameters. Note that this doesn't imply // * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file // * basis. Instead this is indicative of whether any amount of in-place import is possible or not. // * // * @return True if an in-place import is possible with the given parameters, or false otherwise. // */ // boolean inPlaceImportPossible(); // // // /** // * Called when the folder scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>Items must be submitted in dependency order i.e. parents before children. // * Failure to do so will have a <b>severe</b> impact on performance (due to // * transactional rollbacks, followed by retries).</li> // * <li>This code <u>must not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // // /** // * Called when the file scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>This code must <u>not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // }
import java.util.concurrent.atomic.AtomicLong; import org.alfresco.extension.bulkimport.source.BulkImportSource; import static java.util.concurrent.TimeUnit.*; import static org.alfresco.extension.bulkimport.util.LogUtils.*; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Collections; import java.util.Date; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean;
/* * Copyright (C) 2007 Peter Monks * * 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. * * This file is part of an unsupported extension to Alfresco. * */ package org.alfresco.extension.bulkimport.impl; /** * Thread-safe implementation of Bulk Import Status. * * @author Peter Monks (pmonks@gmail.com) * @see org.alfresco.extension.bulkimport.impl.WritableBulkImportStatus */ public class BulkImportStatusImpl implements WritableBulkImportStatus { // General information private AtomicBoolean inProgress = new AtomicBoolean(false); private volatile ProcessingState state = ProcessingState.NEVER_RUN; private volatile ProcessingState priorState = state; private String initiatingUserId = null;
// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java // public interface BulkImportSource // { // /** // * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>. // */ // String getName(); // // // /** // * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>. // */ // String getDescription(); // // // /** // * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>. // */ // Map<String, String> getParameters(); // // // /** // * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>. // */ // String getConfigWebScriptURI(); // // // /** // * Called before anything else, so that the source can validate and parse its parameters. If the parameters are invalid, // * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid. // * // * @param status The status object to use to pre-register any source-side statistics <i>(will not be null)</li>. // * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>. // */ // void init(BulkImportSourceStatus status, Map<String, List<String>> parameters); // // // /** // * Query to determine whether an "in-place" import is possible, given the provided parameters. Note that this doesn't imply // * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file // * basis. Instead this is indicative of whether any amount of in-place import is possible or not. // * // * @return True if an in-place import is possible with the given parameters, or false otherwise. // */ // boolean inPlaceImportPossible(); // // // /** // * Called when the folder scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>Items must be submitted in dependency order i.e. parents before children. // * Failure to do so will have a <b>severe</b> impact on performance (due to // * transactional rollbacks, followed by retries).</li> // * <li>This code <u>must not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // // /** // * Called when the file scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>This code must <u>not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // } // Path: amp/src/main/java/org/alfresco/extension/bulkimport/impl/BulkImportStatusImpl.java import java.util.concurrent.atomic.AtomicLong; import org.alfresco.extension.bulkimport.source.BulkImportSource; import static java.util.concurrent.TimeUnit.*; import static org.alfresco.extension.bulkimport.util.LogUtils.*; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Collections; import java.util.Date; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; /* * Copyright (C) 2007 Peter Monks * * 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. * * This file is part of an unsupported extension to Alfresco. * */ package org.alfresco.extension.bulkimport.impl; /** * Thread-safe implementation of Bulk Import Status. * * @author Peter Monks (pmonks@gmail.com) * @see org.alfresco.extension.bulkimport.impl.WritableBulkImportStatus */ public class BulkImportStatusImpl implements WritableBulkImportStatus { // General information private AtomicBoolean inProgress = new AtomicBoolean(false); private volatile ProcessingState state = ProcessingState.NEVER_RUN; private volatile ProcessingState priorState = state; private String initiatingUserId = null;
private BulkImportSource source = null;
pmonks/alfresco-bulk-import
amp/src/main/java/org/alfresco/extension/bulkimport/impl/WritableBulkImportStatus.java
// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java // public interface BulkImportSource // { // /** // * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>. // */ // String getName(); // // // /** // * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>. // */ // String getDescription(); // // // /** // * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>. // */ // Map<String, String> getParameters(); // // // /** // * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>. // */ // String getConfigWebScriptURI(); // // // /** // * Called before anything else, so that the source can validate and parse its parameters. If the parameters are invalid, // * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid. // * // * @param status The status object to use to pre-register any source-side statistics <i>(will not be null)</li>. // * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>. // */ // void init(BulkImportSourceStatus status, Map<String, List<String>> parameters); // // // /** // * Query to determine whether an "in-place" import is possible, given the provided parameters. Note that this doesn't imply // * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file // * basis. Instead this is indicative of whether any amount of in-place import is possible or not. // * // * @return True if an in-place import is possible with the given parameters, or false otherwise. // */ // boolean inPlaceImportPossible(); // // // /** // * Called when the folder scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>Items must be submitted in dependency order i.e. parents before children. // * Failure to do so will have a <b>severe</b> impact on performance (due to // * transactional rollbacks, followed by retries).</li> // * <li>This code <u>must not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // // /** // * Called when the file scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>This code must <u>not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // }
import org.alfresco.extension.bulkimport.source.BulkImportSource; import org.alfresco.extension.bulkimport.source.BulkImportSourceStatus;
/* * Copyright (C) 2007 Peter Monks * * 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. * * This file is part of an unsupported extension to Alfresco. * */ package org.alfresco.extension.bulkimport.impl; /** * Defines a fully writable interface to the <code>BulkImportStatus</code>. * * @author Peter Monks (pmonks@gmail.com) * @see org.alfresco.extension.bulkimport.source.BulkImportSourceStatus * */ public interface WritableBulkImportStatus extends BulkImportSourceStatus { void importStarted(String initiatingUserId,
// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java // public interface BulkImportSource // { // /** // * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>. // */ // String getName(); // // // /** // * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>. // */ // String getDescription(); // // // /** // * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>. // */ // Map<String, String> getParameters(); // // // /** // * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>. // */ // String getConfigWebScriptURI(); // // // /** // * Called before anything else, so that the source can validate and parse its parameters. If the parameters are invalid, // * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid. // * // * @param status The status object to use to pre-register any source-side statistics <i>(will not be null)</li>. // * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>. // */ // void init(BulkImportSourceStatus status, Map<String, List<String>> parameters); // // // /** // * Query to determine whether an "in-place" import is possible, given the provided parameters. Note that this doesn't imply // * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file // * basis. Instead this is indicative of whether any amount of in-place import is possible or not. // * // * @return True if an in-place import is possible with the given parameters, or false otherwise. // */ // boolean inPlaceImportPossible(); // // // /** // * Called when the folder scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>Items must be submitted in dependency order i.e. parents before children. // * Failure to do so will have a <b>severe</b> impact on performance (due to // * transactional rollbacks, followed by retries).</li> // * <li>This code <u>must not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // // /** // * Called when the file scanning phase of a bulk import is commenced. Importable items should be submitted via the callback, // * and status may (optionally) be provided via the status object. // * // * Notes: // * <ol> // * <li>This code must <u>not</u> use any Alfresco repository services whatsoever, // * as this method is executed on a background thread that runs outside of both // * an Alfresco authentication context and an Alfresco transaction.</li> // * </ol> // * // * @param status The status object to use to report source-side statistics <i>(will not be null)</li>. // * @param callback The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>. // * @throws InterruptedException Should be thrown if the thread running the scan is interrupted. // */ // void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback) // throws InterruptedException; // // } // Path: amp/src/main/java/org/alfresco/extension/bulkimport/impl/WritableBulkImportStatus.java import org.alfresco.extension.bulkimport.source.BulkImportSource; import org.alfresco.extension.bulkimport.source.BulkImportSourceStatus; /* * Copyright (C) 2007 Peter Monks * * 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. * * This file is part of an unsupported extension to Alfresco. * */ package org.alfresco.extension.bulkimport.impl; /** * Defines a fully writable interface to the <code>BulkImportStatus</code>. * * @author Peter Monks (pmonks@gmail.com) * @see org.alfresco.extension.bulkimport.source.BulkImportSourceStatus * */ public interface WritableBulkImportStatus extends BulkImportSourceStatus { void importStarted(String initiatingUserId,
BulkImportSource source,
jsjolund/GdxDemo3D
core/src/com/mygdx/game/ui/GameSpeedController.java
// Path: core/src/com/mygdx/game/settings/GameSettings.java // public class GameSettings { // // public static final float CAMERA_FOV = 60; // public static final float CAMERA_FAR = 100f; // public static final float CAMERA_NEAR = 0.1f; // public static final float CAMERA_MAX_PAN_VELOCITY = 50; // public static final float CAMERA_MIN_ZOOM = 1; // public static final float CAMERA_ZOOM_STEP = 4; // public static final float CAMERA_MAX_ZOOM = 40; // public static final float CAMERA_LERP_ALPHA = 5f; // // public static final float CAMERA_PICK_RAY_DST = 100; // // public static final float SCENE_AMBIENT_LIGHT = 0.1f; // // public static final Vector3 GRAVITY = new Vector3(0, -9.8f, 0); // // public static final int SHADOW_MAP_WIDTH = 2048; // public static final int SHADOW_MAP_HEIGHT = 2048; // public static final float SHADOW_VIEWPORT_HEIGHT = 100; // public static final float SHADOW_VIEWPORT_WIDTH = 100; // public static final float SHADOW_NEAR = 1; // public static final float SHADOW_FAR = 100; // public static final float SHADOW_INTENSITY = 1f; // // public static float GAME_SPEED = 1; // public static float GAME_SPEED_PAUSE = 0; // public static float GAME_SPEED_PLAY = 1; // public static float GAME_SPEED_SLOW = 0.05f; // // public static float MOUSE_SENSITIVITY = 0.1f; // public static float MOUSE_DRAG_THRESHOLD = 10f; // // public static int KEY_PAUSE = Input.Keys.SPACE; // public static int KEY_PAN_FORWARD = Input.Keys.W; // public static int KEY_PAN_LEFT = Input.Keys.A; // public static int KEY_PAN_BACKWARD = Input.Keys.S; // public static int KEY_PAN_RIGHT = Input.Keys.D; // // public static float SOUND_VOLUME = 1f; // public static float MUSIC_VOLUME = 1f; // }
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.mygdx.game.settings.GameSettings;
/******************************************************************************* * Copyright 2015 See AUTHORS file. * <p/> * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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. ******************************************************************************/ package com.mygdx.game.ui; /** * @author jsjolund */ public class GameSpeedController extends Table { private final ImageButton imageButton; private final ImageButton.ImageButtonStyle btnPauseStyle; private final ImageButton.ImageButtonStyle btnPlayStyle; private final ImageButton.ImageButtonStyle btnSlowStyle; public GameSpeedController(TextureAtlas buttonAtlas) { btnPauseStyle = new ImageButton.ImageButtonStyle(); btnPauseStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("pause-up")); btnPauseStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("pause-down")); btnPlayStyle = new ImageButton.ImageButtonStyle(); btnPlayStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("play-up")); btnPlayStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("play-down")); btnSlowStyle = new ImageButton.ImageButtonStyle(); btnSlowStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("slow-up")); btnSlowStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("slow-down")); imageButton = new ImageButton(btnPauseStyle); add(imageButton); imageButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { setGameSpeed(); event.cancel(); } }); } public void setGameSpeed() {
// Path: core/src/com/mygdx/game/settings/GameSettings.java // public class GameSettings { // // public static final float CAMERA_FOV = 60; // public static final float CAMERA_FAR = 100f; // public static final float CAMERA_NEAR = 0.1f; // public static final float CAMERA_MAX_PAN_VELOCITY = 50; // public static final float CAMERA_MIN_ZOOM = 1; // public static final float CAMERA_ZOOM_STEP = 4; // public static final float CAMERA_MAX_ZOOM = 40; // public static final float CAMERA_LERP_ALPHA = 5f; // // public static final float CAMERA_PICK_RAY_DST = 100; // // public static final float SCENE_AMBIENT_LIGHT = 0.1f; // // public static final Vector3 GRAVITY = new Vector3(0, -9.8f, 0); // // public static final int SHADOW_MAP_WIDTH = 2048; // public static final int SHADOW_MAP_HEIGHT = 2048; // public static final float SHADOW_VIEWPORT_HEIGHT = 100; // public static final float SHADOW_VIEWPORT_WIDTH = 100; // public static final float SHADOW_NEAR = 1; // public static final float SHADOW_FAR = 100; // public static final float SHADOW_INTENSITY = 1f; // // public static float GAME_SPEED = 1; // public static float GAME_SPEED_PAUSE = 0; // public static float GAME_SPEED_PLAY = 1; // public static float GAME_SPEED_SLOW = 0.05f; // // public static float MOUSE_SENSITIVITY = 0.1f; // public static float MOUSE_DRAG_THRESHOLD = 10f; // // public static int KEY_PAUSE = Input.Keys.SPACE; // public static int KEY_PAN_FORWARD = Input.Keys.W; // public static int KEY_PAN_LEFT = Input.Keys.A; // public static int KEY_PAN_BACKWARD = Input.Keys.S; // public static int KEY_PAN_RIGHT = Input.Keys.D; // // public static float SOUND_VOLUME = 1f; // public static float MUSIC_VOLUME = 1f; // } // Path: core/src/com/mygdx/game/ui/GameSpeedController.java import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.mygdx.game.settings.GameSettings; /******************************************************************************* * Copyright 2015 See AUTHORS file. * <p/> * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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. ******************************************************************************/ package com.mygdx.game.ui; /** * @author jsjolund */ public class GameSpeedController extends Table { private final ImageButton imageButton; private final ImageButton.ImageButtonStyle btnPauseStyle; private final ImageButton.ImageButtonStyle btnPlayStyle; private final ImageButton.ImageButtonStyle btnSlowStyle; public GameSpeedController(TextureAtlas buttonAtlas) { btnPauseStyle = new ImageButton.ImageButtonStyle(); btnPauseStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("pause-up")); btnPauseStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("pause-down")); btnPlayStyle = new ImageButton.ImageButtonStyle(); btnPlayStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("play-up")); btnPlayStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("play-down")); btnSlowStyle = new ImageButton.ImageButtonStyle(); btnSlowStyle.up = new TextureRegionDrawable(buttonAtlas.findRegion("slow-up")); btnSlowStyle.down = new TextureRegionDrawable(buttonAtlas.findRegion("slow-down")); imageButton = new ImageButton(btnPauseStyle); add(imageButton); imageButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { setGameSpeed(); event.cancel(); } }); } public void setGameSpeed() {
if (GameSettings.GAME_SPEED == GameSettings.GAME_SPEED_PLAY) {
jsjolund/GdxDemo3D
core/src/com/mygdx/game/objects/dog/TaskAnimation.java
// Path: core/src/com/mygdx/game/objects/DogCharacter.java // public static class DogSteerSettings implements SteerSettings { // public static float maxLinearAcceleration = 50f; // public static float maxLinearSpeed = 2f; // public static float maxAngularAcceleration = 100f; // public static float maxAngularSpeed = 15f; // public static float idleFriction = 0.9f; // public static float zeroLinearSpeedThreshold = 0.001f; // public static float runMultiplier = 3f; // public static float timeToTarget = 0.1f; // public static float arrivalTolerance = 0.1f; // public static float decelerationRadius = 0.5f; // public static float predictionTime = 0f; // public static float pathOffset = 1f; // // @Override // public float getTimeToTarget() { // return timeToTarget; // } // // @Override // public float getArrivalTolerance() { // return arrivalTolerance; // } // // @Override // public float getDecelerationRadius() { // return decelerationRadius; // } // // @Override // public float getPredictionTime() { // return predictionTime; // } // // @Override // public float getPathOffset() { // return pathOffset; // } // // @Override // public float getZeroLinearSpeedThreshold() { // return zeroLinearSpeedThreshold; // } // // @Override // public float getIdleFriction() { // return idleFriction; // } // }
import com.mygdx.game.objects.DogCharacter.DogSteerSettings;
/******************************************************************************* * Copyright 2015 See AUTHORS file. * <p/> * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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. ******************************************************************************/ package com.mygdx.game.objects.dog; /** * An enumeration of task animations. * * @author davebaol */ public enum TaskAnimation { Stand("armature|idle_stand"), Sit("armature|idle_sit"), LieDown("armature|idle_lie_down"), Piss("armature|action_piss"), SpinAround("armature|idle_search"), Walk("armature|move_walk", 0.7f, Stand) { @Override public float getSteeringMultiplier() { return 1f; } }, Run("armature|move_run", 0.2f, Stand) { @Override public float getSteeringMultiplier() {
// Path: core/src/com/mygdx/game/objects/DogCharacter.java // public static class DogSteerSettings implements SteerSettings { // public static float maxLinearAcceleration = 50f; // public static float maxLinearSpeed = 2f; // public static float maxAngularAcceleration = 100f; // public static float maxAngularSpeed = 15f; // public static float idleFriction = 0.9f; // public static float zeroLinearSpeedThreshold = 0.001f; // public static float runMultiplier = 3f; // public static float timeToTarget = 0.1f; // public static float arrivalTolerance = 0.1f; // public static float decelerationRadius = 0.5f; // public static float predictionTime = 0f; // public static float pathOffset = 1f; // // @Override // public float getTimeToTarget() { // return timeToTarget; // } // // @Override // public float getArrivalTolerance() { // return arrivalTolerance; // } // // @Override // public float getDecelerationRadius() { // return decelerationRadius; // } // // @Override // public float getPredictionTime() { // return predictionTime; // } // // @Override // public float getPathOffset() { // return pathOffset; // } // // @Override // public float getZeroLinearSpeedThreshold() { // return zeroLinearSpeedThreshold; // } // // @Override // public float getIdleFriction() { // return idleFriction; // } // } // Path: core/src/com/mygdx/game/objects/dog/TaskAnimation.java import com.mygdx.game.objects.DogCharacter.DogSteerSettings; /******************************************************************************* * Copyright 2015 See AUTHORS file. * <p/> * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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. ******************************************************************************/ package com.mygdx.game.objects.dog; /** * An enumeration of task animations. * * @author davebaol */ public enum TaskAnimation { Stand("armature|idle_stand"), Sit("armature|idle_sit"), LieDown("armature|idle_lie_down"), Piss("armature|action_piss"), SpinAround("armature|idle_search"), Walk("armature|move_walk", 0.7f, Stand) { @Override public float getSteeringMultiplier() { return 1f; } }, Run("armature|move_run", 0.2f, Stand) { @Override public float getSteeringMultiplier() {
return DogSteerSettings.runMultiplier;
jsjolund/GdxDemo3D
android/src/com/mygdx/game/android/AndroidLauncher.java
// Path: core/src/com/mygdx/game/GdxDemo3D.java // public class GdxDemo3D extends GdxGame { // // private static final String TAG = "GdxDemo3D"; // // public static final int WIDTH = 1280; // public static final int HEIGHT = 720; // // public void toggleFullscreen() { // if (Gdx.graphics.isFullscreen()) { // Gdx.app.debug(TAG, "Disabling fullscreen w=" + WIDTH + ", h=" + HEIGHT); // Gdx.graphics.setWindowedMode(WIDTH, HEIGHT); // } else { // Gdx.app.debug(TAG, "Enabling fullscreen w=" + Gdx.graphics.getDisplayMode().width + ", h=" // + Gdx.graphics.getDisplayMode().height); // Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); // } // } // // @Override // public void create() { // Gdx.app.setLogLevel(Application.LOG_DEBUG); // // getAssetManager().getLogger().setLevel(Logger.DEBUG); // // Screen currentScreen = new LoadingGameScreen(this, new GameScreen(this)); // setScreen(currentScreen); // } // // }
import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.mygdx.game.GdxDemo3D;
package com.mygdx.game.android; public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Path: core/src/com/mygdx/game/GdxDemo3D.java // public class GdxDemo3D extends GdxGame { // // private static final String TAG = "GdxDemo3D"; // // public static final int WIDTH = 1280; // public static final int HEIGHT = 720; // // public void toggleFullscreen() { // if (Gdx.graphics.isFullscreen()) { // Gdx.app.debug(TAG, "Disabling fullscreen w=" + WIDTH + ", h=" + HEIGHT); // Gdx.graphics.setWindowedMode(WIDTH, HEIGHT); // } else { // Gdx.app.debug(TAG, "Enabling fullscreen w=" + Gdx.graphics.getDisplayMode().width + ", h=" // + Gdx.graphics.getDisplayMode().height); // Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); // } // } // // @Override // public void create() { // Gdx.app.setLogLevel(Application.LOG_DEBUG); // // getAssetManager().getLogger().setLevel(Logger.DEBUG); // // Screen currentScreen = new LoadingGameScreen(this, new GameScreen(this)); // setScreen(currentScreen); // } // // } // Path: android/src/com/mygdx/game/android/AndroidLauncher.java import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.mygdx.game.GdxDemo3D; package com.mygdx.game.android; public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new GdxDemo3D(), config);
shiburagi/Stylish-Widget-for-Android
stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AProgressBar.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/Utils.java // public class Utils { // public static float convertPixelsToDp(float px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float dp = px / (metrics.densityDpi / 160f); // return Math.round(dp); // } // // public static float convertDpToPixel(float dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float px = dp * (metrics.densityDpi / 160f); // return Math.round(px); // } // // public static int adjustAlpha(int color, int alpha) { // int red = Color.red(color); // int green = Color.green(color); // int blue = Color.blue(color); // return Color.argb(alpha, red, green, blue); // } // }
import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.app.infideap.stylishwidget.R; import com.app.infideap.stylishwidget.util.Utils; import com.nineoldandroids.animation.AnimatorSet; import com.nineoldandroids.animation.ObjectAnimator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List;
return 0; return progress.get(index).value; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } private void addView(Context context) { if (progress == null) return; removeAllViews(); setOrientation(HORIZONTAL); LinearLayout progressLayout = null; boolean isRightAlign = isRightAlign(); if (progressLayouts.size() > 0) progressLayout = progressLayouts.get(progressLayouts.size() - 1); for (int i = progressLayouts.size(); i < progress.size(); i++) { progressLayouts.add(new LinearLayout(context)); progressLayouts.get(i).setOrientation(HORIZONTAL); ATextView textView = new ATextView(getContext()); textView.setId(i);
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/Utils.java // public class Utils { // public static float convertPixelsToDp(float px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float dp = px / (metrics.densityDpi / 160f); // return Math.round(dp); // } // // public static float convertDpToPixel(float dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float px = dp * (metrics.densityDpi / 160f); // return Math.round(px); // } // // public static int adjustAlpha(int color, int alpha) { // int red = Color.red(color); // int green = Color.green(color); // int blue = Color.blue(color); // return Color.argb(alpha, red, green, blue); // } // } // Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AProgressBar.java import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.app.infideap.stylishwidget.R; import com.app.infideap.stylishwidget.util.Utils; import com.nineoldandroids.animation.AnimatorSet; import com.nineoldandroids.animation.ObjectAnimator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; return 0; return progress.get(index).value; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } private void addView(Context context) { if (progress == null) return; removeAllViews(); setOrientation(HORIZONTAL); LinearLayout progressLayout = null; boolean isRightAlign = isRightAlign(); if (progressLayouts.size() > 0) progressLayout = progressLayouts.get(progressLayouts.size() - 1); for (int i = progressLayouts.size(); i < progress.size(); i++) { progressLayouts.add(new LinearLayout(context)); progressLayouts.get(i).setOrientation(HORIZONTAL); ATextView textView = new ATextView(getContext()); textView.setId(i);
int padding = (int) Utils.convertDpToPixel(16);
shiburagi/Stylish-Widget-for-Android
stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AMeter.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/Utils.java // public class Utils { // public static float convertPixelsToDp(float px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float dp = px / (metrics.densityDpi / 160f); // return Math.round(dp); // } // // public static float convertDpToPixel(float dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float px = dp * (metrics.densityDpi / 160f); // return Math.round(px); // } // // public static int adjustAlpha(int color, int alpha) { // int red = Color.red(color); // int green = Color.green(color); // int blue = Color.blue(color); // return Color.argb(alpha, red, green, blue); // } // }
import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuff; import android.graphics.RectF; import android.graphics.Typeface; import android.os.Build; import androidx.annotation.Px; import androidx.annotation.RequiresApi; import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import com.app.infideap.stylishwidget.R; import com.app.infideap.stylishwidget.util.Utils; import java.util.Locale;
package com.app.infideap.stylishwidget.view; /** * Created by Zariman on 13/4/2016. */ public class AMeter extends LinearLayout { private static final String TAG = AMeter.class.getSimpleName(); private float value; private int meterColor; private View view; private float startAngle = 130; private float sweepAngle = 280; private float maxValue; private View needle1View; private View needle2View; private int textStyle; private float textSize;
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/Utils.java // public class Utils { // public static float convertPixelsToDp(float px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float dp = px / (metrics.densityDpi / 160f); // return Math.round(dp); // } // // public static float convertDpToPixel(float dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // float px = dp * (metrics.densityDpi / 160f); // return Math.round(px); // } // // public static int adjustAlpha(int color, int alpha) { // int red = Color.red(color); // int green = Color.green(color); // int blue = Color.blue(color); // return Color.argb(alpha, red, green, blue); // } // } // Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AMeter.java import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuff; import android.graphics.RectF; import android.graphics.Typeface; import android.os.Build; import androidx.annotation.Px; import androidx.annotation.RequiresApi; import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import com.app.infideap.stylishwidget.R; import com.app.infideap.stylishwidget.util.Utils; import java.util.Locale; package com.app.infideap.stylishwidget.view; /** * Created by Zariman on 13/4/2016. */ public class AMeter extends LinearLayout { private static final String TAG = AMeter.class.getSimpleName(); private float value; private int meterColor; private View view; private float startAngle = 130; private float sweepAngle = 280; private float maxValue; private View needle1View; private View needle2View; private int textStyle; private float textSize;
private int gapBottom = (int) Utils.convertDpToPixel(30);
shiburagi/Stylish-Widget-for-Android
app/src/main/java/com/app/infideap/mystylishexample/WidgetFragment.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/TextViewUtils.java // public class TextViewUtils { // private static final String TAG = TextViewUtils.class.getSimpleName(); // private static TextViewUtils instance; // // static { // instance = new TextViewUtils(); // } // // public static TextViewUtils getInstance() { // return instance; // } // // public Thread printIncrement(TextView textView, long endNumber, long millis) { // return printIncrement(textView, 0, endNumber, millis); // } // // public Thread printIncrement(TextView textView, long startNumber, long endNumber, long millis) { // return printIncrement(textView, "%d", startNumber, endNumber, millis); // } // // public Thread printIncrement(TextView textView, String format, long endNumber, long millis) { // return printIncrement(textView, Locale.getDefault(), format, endNumber, millis); // // } // // public Thread printIncrement(TextView textView, String format, long startNumber, long endNumber, long millis) { // return printIncrement(textView, Locale.getDefault(), format, startNumber, endNumber, millis); // // } // // public Thread printIncrement(TextView textView, Locale locale, String format, long endNumber, long millis) { // return printIncrement(textView, locale, format, 0, endNumber, millis); // // } // // public Thread printIncrement(final TextView textView, final Locale locale, final String format, final long startNumber, final long endNumber, final long millis) { // final Thread thread = printIncrementPostDelayed(textView, locale, format, startNumber, endNumber, millis); // textView.post(new Runnable() { // @Override // public void run() { // thread.start(); // } // }); // // return thread; // // } // // // private Thread printIncrementPostDelayed(final TextView textView, final Locale locale, // final String format, final long startNumber, // final long endNumber, final long millis) { // // return new Thread() { // @Override // public void run() { // try { // long start; // long end; // // if (startNumber > endNumber) { // start = endNumber; // end = startNumber; // } else { // start = startNumber; // end = endNumber; // } // long counter = start; // double delayDuration = (double) millis / (double) (end - start); // long increment; // if (delayDuration < 1) { // increment = (long) Math.ceil(1f / delayDuration); // delayDuration *= increment; // } else // increment = 1; // // displayText(textView, locale, format, // startNumber < endNumber ? counter : startNumber - (counter - start)); // while (counter < end) { // sleep((long) delayDuration); // counter += increment; // counter = counter > end ? end : counter; // displayText(textView, locale, format, // startNumber < endNumber ? counter : startNumber - (counter - start)); // } // } catch (InterruptedException e) { // e.printStackTrace(); // } // } // }; // // // } // // private void displayText(final TextView textView, Locale locale, String format, long counter) { // // final String displayText = getString(locale, format, counter); // textView.post(new Runnable() { // @Override // public void run() { // textView.setText(displayText); // } // }); // } // // private String getString(Locale locale, String format, long counter) { // return String.format( // locale, format, counter // ); // } // // // }
import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.app.infideap.stylishwidget.util.TextViewUtils;
package com.app.infideap.mystylishexample; /** * A simple {@link Fragment} subclass. * Use the {@link WidgetFragment#newInstance} factory method to * create an instance of this fragment. */ public class WidgetFragment extends Fragment { private TextView incrementTextView; private TextView decrementTextView; private Thread incrementThread; private Thread decrementTread; public WidgetFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @return A new instance of fragment WidgetFragment. */ // TODO: Rename and change types and number of parameters public static WidgetFragment newInstance() { return new WidgetFragment(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.layout_widget, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); incrementTextView = (TextView) view.findViewById(R.id.textView_increment); decrementTextView = (TextView) view.findViewById(R.id.textView_decrement); startCounter(); } private void startCounter() { if (incrementThread != null) { incrementThread.interrupt(); } if (decrementTread != null) { decrementTread.interrupt(); }
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/util/TextViewUtils.java // public class TextViewUtils { // private static final String TAG = TextViewUtils.class.getSimpleName(); // private static TextViewUtils instance; // // static { // instance = new TextViewUtils(); // } // // public static TextViewUtils getInstance() { // return instance; // } // // public Thread printIncrement(TextView textView, long endNumber, long millis) { // return printIncrement(textView, 0, endNumber, millis); // } // // public Thread printIncrement(TextView textView, long startNumber, long endNumber, long millis) { // return printIncrement(textView, "%d", startNumber, endNumber, millis); // } // // public Thread printIncrement(TextView textView, String format, long endNumber, long millis) { // return printIncrement(textView, Locale.getDefault(), format, endNumber, millis); // // } // // public Thread printIncrement(TextView textView, String format, long startNumber, long endNumber, long millis) { // return printIncrement(textView, Locale.getDefault(), format, startNumber, endNumber, millis); // // } // // public Thread printIncrement(TextView textView, Locale locale, String format, long endNumber, long millis) { // return printIncrement(textView, locale, format, 0, endNumber, millis); // // } // // public Thread printIncrement(final TextView textView, final Locale locale, final String format, final long startNumber, final long endNumber, final long millis) { // final Thread thread = printIncrementPostDelayed(textView, locale, format, startNumber, endNumber, millis); // textView.post(new Runnable() { // @Override // public void run() { // thread.start(); // } // }); // // return thread; // // } // // // private Thread printIncrementPostDelayed(final TextView textView, final Locale locale, // final String format, final long startNumber, // final long endNumber, final long millis) { // // return new Thread() { // @Override // public void run() { // try { // long start; // long end; // // if (startNumber > endNumber) { // start = endNumber; // end = startNumber; // } else { // start = startNumber; // end = endNumber; // } // long counter = start; // double delayDuration = (double) millis / (double) (end - start); // long increment; // if (delayDuration < 1) { // increment = (long) Math.ceil(1f / delayDuration); // delayDuration *= increment; // } else // increment = 1; // // displayText(textView, locale, format, // startNumber < endNumber ? counter : startNumber - (counter - start)); // while (counter < end) { // sleep((long) delayDuration); // counter += increment; // counter = counter > end ? end : counter; // displayText(textView, locale, format, // startNumber < endNumber ? counter : startNumber - (counter - start)); // } // } catch (InterruptedException e) { // e.printStackTrace(); // } // } // }; // // // } // // private void displayText(final TextView textView, Locale locale, String format, long counter) { // // final String displayText = getString(locale, format, counter); // textView.post(new Runnable() { // @Override // public void run() { // textView.setText(displayText); // } // }); // } // // private String getString(Locale locale, String format, long counter) { // return String.format( // locale, format, counter // ); // } // // // } // Path: app/src/main/java/com/app/infideap/mystylishexample/WidgetFragment.java import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.app.infideap.stylishwidget.util.TextViewUtils; package com.app.infideap.mystylishexample; /** * A simple {@link Fragment} subclass. * Use the {@link WidgetFragment#newInstance} factory method to * create an instance of this fragment. */ public class WidgetFragment extends Fragment { private TextView incrementTextView; private TextView decrementTextView; private Thread incrementThread; private Thread decrementTread; public WidgetFragment() { // Required empty public constructor } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @return A new instance of fragment WidgetFragment. */ // TODO: Rename and change types and number of parameters public static WidgetFragment newInstance() { return new WidgetFragment(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.layout_widget, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); incrementTextView = (TextView) view.findViewById(R.id.textView_increment); decrementTextView = (TextView) view.findViewById(R.id.textView_decrement); startCounter(); } private void startCounter() { if (incrementThread != null) { incrementThread.interrupt(); } if (decrementTread != null) { decrementTread.interrupt(); }
TextViewUtils utils = TextViewUtils.getInstance();
shiburagi/Stylish-Widget-for-Android
stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AEditText.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/Log.java // public class Log { // public static final boolean LOG = true; // // public static void i(String tag, String string) { // if (LOG) android.util.Log.i(tag, string); // } // // public static void e(String tag, String string) { // if (LOG) android.util.Log.e(tag, string); // } // // public static void d(String tag, String string) { // if (LOG) android.util.Log.d(tag, string); // } // // public static void v(String tag, String string) { // if (LOG) android.util.Log.v(tag, string); // } // // public static void w(String tag, String string) { // if (LOG) android.util.Log.w(tag, string); // } // }
import android.annotation.SuppressLint; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Typeface; import android.os.Build; import androidx.appcompat.widget.AppCompatEditText; import android.text.InputType; import android.util.AttributeSet; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.DatePicker; import android.widget.TimePicker; import com.app.infideap.stylishwidget.Log; import com.app.infideap.stylishwidget.R; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextAppearance); int style = a.getInt(R.styleable.TextAppearance_android_textStyle, Typeface.NORMAL); setTextStyle(style); a.recycle(); // a = context.obtainStyledAttributes(attrs, android.support.v7.appcompat.R.styleable.AppCompatTextView); // // int inputType = a.getInt(android.support.v7.appcompat.R.styleable.Inpu, Typeface.NORMAL); // // setInputType(inputType); // a.recycle(); } public void setTextStyle(int style) { Stylish.getInstance().setTextStyle(this, style); } public void setSupportTextAppearance(int resId) { if (Build.VERSION.SDK_INT >= 23) this.setTextAppearance(resId); else this.setTextAppearance(getContext(), resId); } @Override public void setRawInputType(int type) {
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/Log.java // public class Log { // public static final boolean LOG = true; // // public static void i(String tag, String string) { // if (LOG) android.util.Log.i(tag, string); // } // // public static void e(String tag, String string) { // if (LOG) android.util.Log.e(tag, string); // } // // public static void d(String tag, String string) { // if (LOG) android.util.Log.d(tag, string); // } // // public static void v(String tag, String string) { // if (LOG) android.util.Log.v(tag, string); // } // // public static void w(String tag, String string) { // if (LOG) android.util.Log.w(tag, string); // } // } // Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/AEditText.java import android.annotation.SuppressLint; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Typeface; import android.os.Build; import androidx.appcompat.widget.AppCompatEditText; import android.text.InputType; import android.util.AttributeSet; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.DatePicker; import android.widget.TimePicker; import com.app.infideap.stylishwidget.Log; import com.app.infideap.stylishwidget.R; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextAppearance); int style = a.getInt(R.styleable.TextAppearance_android_textStyle, Typeface.NORMAL); setTextStyle(style); a.recycle(); // a = context.obtainStyledAttributes(attrs, android.support.v7.appcompat.R.styleable.AppCompatTextView); // // int inputType = a.getInt(android.support.v7.appcompat.R.styleable.Inpu, Typeface.NORMAL); // // setInputType(inputType); // a.recycle(); } public void setTextStyle(int style) { Stylish.getInstance().setTextStyle(this, style); } public void setSupportTextAppearance(int resId) { if (Build.VERSION.SDK_INT >= 23) this.setTextAppearance(resId); else this.setTextAppearance(getContext(), resId); } @Override public void setRawInputType(int type) {
Log.e(this.getClass().getSimpleName(), "Type : "+type);
shiburagi/Stylish-Widget-for-Android
app/src/main/java/com/app/infideap/mystylishexample/MainActivity.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/Stylish.java // public class Stylish { // // static final Map<String, Typeface> TYPEFACE = new HashMap<>(); // private static final String TAG = Stylish.class.getSimpleName(); // static String FONT_REGULAR = ""; // static String FONT_BOLD = ""; // static String FONT_ITALIC = ""; // static String FONT_BOLD_ITALIC = ""; // // private static final Stylish instance; // // static { // instance = new Stylish(); // } // // private float fontScale = 1.0f; // // private Stylish() { // } // // public void set(String regular, String bold, String italic) { // FONT_REGULAR = regular; // FONT_BOLD = bold; // FONT_ITALIC = italic; // } // // public void set(String regular, String bold, String italic, String boldItalic) { // FONT_REGULAR = regular; // FONT_BOLD = bold; // FONT_ITALIC = italic; // FONT_BOLD_ITALIC = boldItalic; // } // // public void setFontRegular(String fontRegular) { // FONT_REGULAR = fontRegular; // } // // public void setFontBold(String fontBold) { // FONT_BOLD = fontBold; // } // // public void setFontItalic(String fontItalic) { // FONT_ITALIC = fontItalic; // } // // public void setFontBoldItalic(String fontBoldItalic) { // FONT_BOLD_ITALIC = fontBoldItalic; // } // // public static Stylish getInstance() { // return instance; // } // // public Typeface getTypeface(Context context, String font, int style) { // // Typeface typeface; // if (!Stylish.TYPEFACE.containsKey(font)) { // try { // typeface = Typeface.createFromAsset(context.getAssets(), // font); // Stylish.TYPEFACE.put(font, typeface); // // } catch (Exception e) { // typeface = Typeface.defaultFromStyle(style); // } // // // } else // typeface = Stylish.TYPEFACE.get(font); // // return typeface; // } // // public Typeface reqular(Context context) { // return getTypeface(context, FONT_REGULAR, Typeface.NORMAL); // } // // public Typeface bold(Context context) { // return getTypeface(context, FONT_BOLD, Typeface.BOLD); // } // // // public Typeface italic(Context context) { // return getTypeface(context, FONT_ITALIC, Typeface.ITALIC); // } // // public Typeface boldItalic(Context context) { // return getTypeface(context, FONT_BOLD_ITALIC, Typeface.BOLD_ITALIC); // } // // boolean isExist(Context context, String font) { // try { // return Arrays.asList(context.getResources().getAssets().list("")).contains(font); // } catch (IOException e) { // return false; // } // } // // public float getFontScale() { // return fontScale; // } // // public void setFontScale(float fontScale) { // this.fontScale = fontScale; // } // // // public Typeface getRegular() { // return TYPEFACE.get(FONT_REGULAR); // } // // public Typeface getBold() { // return TYPEFACE.get(FONT_BOLD); // } // // public Typeface getItalic() { // return TYPEFACE.get(FONT_ITALIC); // } // // public Typeface getBoldItalic() { // return TYPEFACE.get(FONT_BOLD_ITALIC); // } // // public void setTextStyle(TextView textView, int style) { // String font; // switch (style) { // case Typeface.BOLD: // font = Stylish.FONT_BOLD; // break; // case Typeface.ITALIC: // font = Stylish.FONT_ITALIC; // break; // case Typeface.NORMAL: // font = Stylish.FONT_REGULAR; // break; // case Typeface.BOLD_ITALIC: // font = Stylish.FONT_BOLD_ITALIC; // break; // default: // font = Stylish.FONT_REGULAR; // } // // try { // // textView.setTypeface(Stylish.getInstance().getTypeface(textView.getContext(), font, style)); // } catch (Exception e) { // // e.printStackTrace(); // } // } // }
import android.os.Bundle; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.AppCompatActivity; import com.app.infideap.stylishwidget.view.Stylish;
package com.app.infideap.mystylishexample; public class MainActivity extends AppCompatActivity { private TabLayout tabLayout; private ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { // Initial this before setContentView or declare in onCreate() of Custom Application String fontFolder = "Exo_2/Exo2-";
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/Stylish.java // public class Stylish { // // static final Map<String, Typeface> TYPEFACE = new HashMap<>(); // private static final String TAG = Stylish.class.getSimpleName(); // static String FONT_REGULAR = ""; // static String FONT_BOLD = ""; // static String FONT_ITALIC = ""; // static String FONT_BOLD_ITALIC = ""; // // private static final Stylish instance; // // static { // instance = new Stylish(); // } // // private float fontScale = 1.0f; // // private Stylish() { // } // // public void set(String regular, String bold, String italic) { // FONT_REGULAR = regular; // FONT_BOLD = bold; // FONT_ITALIC = italic; // } // // public void set(String regular, String bold, String italic, String boldItalic) { // FONT_REGULAR = regular; // FONT_BOLD = bold; // FONT_ITALIC = italic; // FONT_BOLD_ITALIC = boldItalic; // } // // public void setFontRegular(String fontRegular) { // FONT_REGULAR = fontRegular; // } // // public void setFontBold(String fontBold) { // FONT_BOLD = fontBold; // } // // public void setFontItalic(String fontItalic) { // FONT_ITALIC = fontItalic; // } // // public void setFontBoldItalic(String fontBoldItalic) { // FONT_BOLD_ITALIC = fontBoldItalic; // } // // public static Stylish getInstance() { // return instance; // } // // public Typeface getTypeface(Context context, String font, int style) { // // Typeface typeface; // if (!Stylish.TYPEFACE.containsKey(font)) { // try { // typeface = Typeface.createFromAsset(context.getAssets(), // font); // Stylish.TYPEFACE.put(font, typeface); // // } catch (Exception e) { // typeface = Typeface.defaultFromStyle(style); // } // // // } else // typeface = Stylish.TYPEFACE.get(font); // // return typeface; // } // // public Typeface reqular(Context context) { // return getTypeface(context, FONT_REGULAR, Typeface.NORMAL); // } // // public Typeface bold(Context context) { // return getTypeface(context, FONT_BOLD, Typeface.BOLD); // } // // // public Typeface italic(Context context) { // return getTypeface(context, FONT_ITALIC, Typeface.ITALIC); // } // // public Typeface boldItalic(Context context) { // return getTypeface(context, FONT_BOLD_ITALIC, Typeface.BOLD_ITALIC); // } // // boolean isExist(Context context, String font) { // try { // return Arrays.asList(context.getResources().getAssets().list("")).contains(font); // } catch (IOException e) { // return false; // } // } // // public float getFontScale() { // return fontScale; // } // // public void setFontScale(float fontScale) { // this.fontScale = fontScale; // } // // // public Typeface getRegular() { // return TYPEFACE.get(FONT_REGULAR); // } // // public Typeface getBold() { // return TYPEFACE.get(FONT_BOLD); // } // // public Typeface getItalic() { // return TYPEFACE.get(FONT_ITALIC); // } // // public Typeface getBoldItalic() { // return TYPEFACE.get(FONT_BOLD_ITALIC); // } // // public void setTextStyle(TextView textView, int style) { // String font; // switch (style) { // case Typeface.BOLD: // font = Stylish.FONT_BOLD; // break; // case Typeface.ITALIC: // font = Stylish.FONT_ITALIC; // break; // case Typeface.NORMAL: // font = Stylish.FONT_REGULAR; // break; // case Typeface.BOLD_ITALIC: // font = Stylish.FONT_BOLD_ITALIC; // break; // default: // font = Stylish.FONT_REGULAR; // } // // try { // // textView.setTypeface(Stylish.getInstance().getTypeface(textView.getContext(), font, style)); // } catch (Exception e) { // // e.printStackTrace(); // } // } // } // Path: app/src/main/java/com/app/infideap/mystylishexample/MainActivity.java import android.os.Bundle; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.AppCompatActivity; import com.app.infideap.stylishwidget.view.Stylish; package com.app.infideap.mystylishexample; public class MainActivity extends AppCompatActivity { private TabLayout tabLayout; private ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { // Initial this before setContentView or declare in onCreate() of Custom Application String fontFolder = "Exo_2/Exo2-";
Stylish.getInstance().set(
shiburagi/Stylish-Widget-for-Android
stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/ARadioGroup.java
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/Log.java // public class Log { // public static final boolean LOG = true; // // public static void i(String tag, String string) { // if (LOG) android.util.Log.i(tag, string); // } // // public static void e(String tag, String string) { // if (LOG) android.util.Log.e(tag, string); // } // // public static void d(String tag, String string) { // if (LOG) android.util.Log.d(tag, string); // } // // public static void v(String tag, String string) { // if (LOG) android.util.Log.v(tag, string); // } // // public static void w(String tag, String string) { // if (LOG) android.util.Log.w(tag, string); // } // }
import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; import com.app.infideap.stylishwidget.Log; import java.util.ArrayList;
package com.app.infideap.stylishwidget.view; /** * Created by Shiburagi on 23/06/2016. */ public class ARadioGroup extends RadioGroup { private static final String TAG = ARadioGroup.class.getSimpleName(); private ArrayList<RadioButton> radioButtons; private OnCheckedChangeListener listener; private RadioButton selected; private int selectedId; private boolean trigger; public ARadioGroup(Context context) { super(context); init(context, null); } public ARadioGroup(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } private void init(Context context, AttributeSet attrs) { radioButtons = new ArrayList<>(); search(context, this);
// Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/Log.java // public class Log { // public static final boolean LOG = true; // // public static void i(String tag, String string) { // if (LOG) android.util.Log.i(tag, string); // } // // public static void e(String tag, String string) { // if (LOG) android.util.Log.e(tag, string); // } // // public static void d(String tag, String string) { // if (LOG) android.util.Log.d(tag, string); // } // // public static void v(String tag, String string) { // if (LOG) android.util.Log.v(tag, string); // } // // public static void w(String tag, String string) { // if (LOG) android.util.Log.w(tag, string); // } // } // Path: stylishwidget/src/main/java/com/app/infideap/stylishwidget/view/ARadioGroup.java import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; import com.app.infideap.stylishwidget.Log; import java.util.ArrayList; package com.app.infideap.stylishwidget.view; /** * Created by Shiburagi on 23/06/2016. */ public class ARadioGroup extends RadioGroup { private static final String TAG = ARadioGroup.class.getSimpleName(); private ArrayList<RadioButton> radioButtons; private OnCheckedChangeListener listener; private RadioButton selected; private int selectedId; private boolean trigger; public ARadioGroup(Context context) { super(context); init(context, null); } public ARadioGroup(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } private void init(Context context, AttributeSet attrs) { radioButtons = new ArrayList<>(); search(context, this);
Log.d(TAG, "Size : " + radioButtons.size() + ", " + getChildCount());
vy/log4j2-logstash-layout
layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/MessageResolver.java
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // }
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.message.*; import org.apache.logging.log4j.util.TriConsumer; import java.io.IOException;
// Get the formatted message, if there is any. if (!jsonSupported) { writeObject(message, jsonGenerator); return true; } // Write the formatted JSON. String messageJson = multiformatMessage.getFormattedMessage(FORMATS); JsonNode jsonNode = readMessageJson(context, messageJson); boolean nodeExcluded = isNodeExcluded(jsonNode); if (nodeExcluded) { jsonGenerator.writeNull(); } else { jsonGenerator.writeTree(jsonNode); } return true; } private static void writeMapMessage(JsonGenerator jsonGenerator, MapMessage<?, Object> mapMessage) throws IOException { jsonGenerator.writeStartObject(); mapMessage.forEach(MAP_MESSAGE_ENTRY_WRITER, jsonGenerator); jsonGenerator.writeEndObject(); } private static TriConsumer<String, Object, JsonGenerator> MAP_MESSAGE_ENTRY_WRITER = (key, value, jsonGenerator) -> { try { jsonGenerator.writeFieldName(key);
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // } // Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/MessageResolver.java import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.message.*; import org.apache.logging.log4j.util.TriConsumer; import java.io.IOException; // Get the formatted message, if there is any. if (!jsonSupported) { writeObject(message, jsonGenerator); return true; } // Write the formatted JSON. String messageJson = multiformatMessage.getFormattedMessage(FORMATS); JsonNode jsonNode = readMessageJson(context, messageJson); boolean nodeExcluded = isNodeExcluded(jsonNode); if (nodeExcluded) { jsonGenerator.writeNull(); } else { jsonGenerator.writeTree(jsonNode); } return true; } private static void writeMapMessage(JsonGenerator jsonGenerator, MapMessage<?, Object> mapMessage) throws IOException { jsonGenerator.writeStartObject(); mapMessage.forEach(MAP_MESSAGE_ENTRY_WRITER, jsonGenerator); jsonGenerator.writeEndObject(); } private static TriConsumer<String, Object, JsonGenerator> MAP_MESSAGE_ENTRY_WRITER = (key, value, jsonGenerator) -> { try { jsonGenerator.writeFieldName(key);
JsonGenerators.writeObject(jsonGenerator, value);
vy/log4j2-logstash-layout
layout/src/main/java/com/vlkan/log4j2/logstash/layout/LogstashLayoutSerializationContexts.java
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/ByteBufferOutputStream.java // public class ByteBufferOutputStream extends OutputStream { // // private final ByteBuffer byteBuffer; // // public ByteBufferOutputStream(int byteCount) { // this.byteBuffer = ByteBuffer.allocate(byteCount); // } // // public ByteBuffer getByteBuffer() { // return byteBuffer; // } // // @Override // public void write(int codeInt) { // byte codeByte = (byte) codeInt; // byteBuffer.put(codeByte); // } // // @Override // public void write(byte[] buf) { // byteBuffer.put(buf); // } // // @Override // public void write(byte[] buf, int off, int len) { // byteBuffer.put(buf, off, len); // } // // public byte[] toByteArray() { // @SuppressWarnings("RedundantCast") // for Java 8 compatibility // int size = ((Buffer) byteBuffer).position(); // byte[] buffer = new byte[size]; // System.arraycopy(byteBuffer.array(), 0, buffer, 0, size); // return buffer; // } // // public String toString(Charset charset) { // // noinspection RedundantCast (for Java 8 compatibility) // return new String(byteBuffer.array(), 0, ((Buffer) byteBuffer).position(), charset); // } // // }
import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.function.Supplier; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.filter.FilteringGeneratorDelegate; import com.fasterxml.jackson.core.filter.TokenFilter; import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.JsonGeneratorDelegate; import com.fasterxml.jackson.databind.ObjectMapper; import com.vlkan.log4j2.logstash.layout.util.ByteBufferOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringReader;
/* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout; enum LogstashLayoutSerializationContexts {; private static final SerializedString EMPTY_SERIALIZED_STRING = new SerializedString(""); private static final PrettyPrinter PRETTY_PRINTER = new DefaultPrettyPrinter(""); static Supplier<LogstashLayoutSerializationContext> createSupplier( ObjectMapper objectMapper, int maxByteCount, boolean prettyPrintEnabled, boolean emptyPropertyExclusionEnabled, int maxStringLength) { JsonFactory jsonFactory = new JsonFactory(objectMapper); return () -> {
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/ByteBufferOutputStream.java // public class ByteBufferOutputStream extends OutputStream { // // private final ByteBuffer byteBuffer; // // public ByteBufferOutputStream(int byteCount) { // this.byteBuffer = ByteBuffer.allocate(byteCount); // } // // public ByteBuffer getByteBuffer() { // return byteBuffer; // } // // @Override // public void write(int codeInt) { // byte codeByte = (byte) codeInt; // byteBuffer.put(codeByte); // } // // @Override // public void write(byte[] buf) { // byteBuffer.put(buf); // } // // @Override // public void write(byte[] buf, int off, int len) { // byteBuffer.put(buf, off, len); // } // // public byte[] toByteArray() { // @SuppressWarnings("RedundantCast") // for Java 8 compatibility // int size = ((Buffer) byteBuffer).position(); // byte[] buffer = new byte[size]; // System.arraycopy(byteBuffer.array(), 0, buffer, 0, size); // return buffer; // } // // public String toString(Charset charset) { // // noinspection RedundantCast (for Java 8 compatibility) // return new String(byteBuffer.array(), 0, ((Buffer) byteBuffer).position(), charset); // } // // } // Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/LogstashLayoutSerializationContexts.java import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.function.Supplier; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.filter.FilteringGeneratorDelegate; import com.fasterxml.jackson.core.filter.TokenFilter; import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.JsonGeneratorDelegate; import com.fasterxml.jackson.databind.ObjectMapper; import com.vlkan.log4j2.logstash.layout.util.ByteBufferOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringReader; /* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout; enum LogstashLayoutSerializationContexts {; private static final SerializedString EMPTY_SERIALIZED_STRING = new SerializedString(""); private static final PrettyPrinter PRETTY_PRINTER = new DefaultPrettyPrinter(""); static Supplier<LogstashLayoutSerializationContext> createSupplier( ObjectMapper objectMapper, int maxByteCount, boolean prettyPrintEnabled, boolean emptyPropertyExclusionEnabled, int maxStringLength) { JsonFactory jsonFactory = new JsonFactory(objectMapper); return () -> {
ByteBufferOutputStream outputStream = new ByteBufferOutputStream(maxByteCount);
vy/log4j2-logstash-layout
layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/TimestampResolver.java
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // }
import java.util.regex.Pattern; import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.core.util.Constants; import org.apache.logging.log4j.core.util.datetime.FastDateFormat; import java.io.IOException; import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Matcher;
FormatResolverContext.fromEventResolverContext(eventResolverContext); } @Override FormatResolverContext acquireContext() { lock.lock(); return formatResolverContext; } @Override void releaseContext() { lock.unlock(); } } private static EventResolver createFormatResolver(EventResolverContext eventResolverContext) { return Constants.ENABLE_THREADLOCALS ? new ThreadLocalFormatResolver(eventResolverContext) : new LockingFormatResolver(eventResolverContext); } private static final EventResolver SECS_LONG_RESOLVER = (logEvent, jsonGenerator) -> { Instant logEventInstant = logEvent.getInstant(); long epochSecs = logEventInstant.getEpochSecond(); jsonGenerator.writeNumber(epochSecs); }; private static final EventResolver SECS_DOUBLE_RESOLVER = (logEvent, jsonGenerator) -> { Instant logEventInstant = logEvent.getInstant();
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // } // Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/TimestampResolver.java import java.util.regex.Pattern; import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.core.util.Constants; import org.apache.logging.log4j.core.util.datetime.FastDateFormat; import java.io.IOException; import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Matcher; FormatResolverContext.fromEventResolverContext(eventResolverContext); } @Override FormatResolverContext acquireContext() { lock.lock(); return formatResolverContext; } @Override void releaseContext() { lock.unlock(); } } private static EventResolver createFormatResolver(EventResolverContext eventResolverContext) { return Constants.ENABLE_THREADLOCALS ? new ThreadLocalFormatResolver(eventResolverContext) : new LockingFormatResolver(eventResolverContext); } private static final EventResolver SECS_LONG_RESOLVER = (logEvent, jsonGenerator) -> { Instant logEventInstant = logEvent.getInstant(); long epochSecs = logEventInstant.getEpochSecond(); jsonGenerator.writeNumber(epochSecs); }; private static final EventResolver SECS_DOUBLE_RESOLVER = (logEvent, jsonGenerator) -> { Instant logEventInstant = logEvent.getInstant();
JsonGenerators.writeDouble(
vy/log4j2-logstash-layout
layout/src/test/java/com/vlkan/log4j2/logstash/layout/util/JsonGeneratorsTest.java
// Path: layout/src/test/java/com/vlkan/log4j2/logstash/layout/ObjectMapperFixture.java // public enum ObjectMapperFixture {; // // public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); // // }
import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.ObjectMapperFixture; import org.assertj.core.api.Assertions; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; import java.util.Map;
/* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.util; public class JsonGeneratorsTest { private static final class WriteDoubleTestCase { private final long integralPart; private final int fractionalPart; private WriteDoubleTestCase(long integralPart, int fractionalPart) { this.integralPart = integralPart; this.fractionalPart = fractionalPart; } private String write() throws IOException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Path: layout/src/test/java/com/vlkan/log4j2/logstash/layout/ObjectMapperFixture.java // public enum ObjectMapperFixture {; // // public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); // // } // Path: layout/src/test/java/com/vlkan/log4j2/logstash/layout/util/JsonGeneratorsTest.java import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.ObjectMapperFixture; import org.assertj.core.api.Assertions; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; import java.util.Map; /* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.util; public class JsonGeneratorsTest { private static final class WriteDoubleTestCase { private final long integralPart; private final int fractionalPart; private WriteDoubleTestCase(long integralPart, int fractionalPart) { this.integralPart = integralPart; this.fractionalPart = fractionalPart; } private String write() throws IOException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonGenerator jsonGenerator = ObjectMapperFixture
vy/log4j2-logstash-layout
layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/ExceptionRootCauseResolver.java
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/Throwables.java // public enum Throwables {; // // public static Throwable getRootCause(Throwable throwable) { // // // Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches // // the slower pointer, then there's a loop. // Throwable slowPointer = throwable; // boolean advanceSlowPointer = false; // // Throwable cause; // while ((cause = throwable.getCause()) != null) { // throwable = cause; // if (throwable == slowPointer) { // throw new IllegalArgumentException("loop in causal chain", throwable); // } // if (advanceSlowPointer) { // slowPointer = slowPointer.getCause(); // } // advanceSlowPointer = !advanceSlowPointer; // only advance every other iteration // } // return throwable; // // } // // }
import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.Throwables; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.core.LogEvent; import java.io.IOException;
/* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.resolver; class ExceptionRootCauseResolver implements EventResolver { private static final ExceptionInternalResolverFactory INTERNAL_RESOLVER_FACTORY = new ExceptionInternalResolverFactory() { @Override EventResolver createClassNameResolver() { return (logEvent, jsonGenerator) -> { Throwable exception = logEvent.getThrown(); if (exception == null) { jsonGenerator.writeNull(); } else {
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/Throwables.java // public enum Throwables {; // // public static Throwable getRootCause(Throwable throwable) { // // // Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches // // the slower pointer, then there's a loop. // Throwable slowPointer = throwable; // boolean advanceSlowPointer = false; // // Throwable cause; // while ((cause = throwable.getCause()) != null) { // throwable = cause; // if (throwable == slowPointer) { // throw new IllegalArgumentException("loop in causal chain", throwable); // } // if (advanceSlowPointer) { // slowPointer = slowPointer.getCause(); // } // advanceSlowPointer = !advanceSlowPointer; // only advance every other iteration // } // return throwable; // // } // // } // Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/ExceptionRootCauseResolver.java import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.Throwables; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.core.LogEvent; import java.io.IOException; /* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.resolver; class ExceptionRootCauseResolver implements EventResolver { private static final ExceptionInternalResolverFactory INTERNAL_RESOLVER_FACTORY = new ExceptionInternalResolverFactory() { @Override EventResolver createClassNameResolver() { return (logEvent, jsonGenerator) -> { Throwable exception = logEvent.getThrown(); if (exception == null) { jsonGenerator.writeNull(); } else {
Throwable rootCause = Throwables.getRootCause(exception);
vy/log4j2-logstash-layout
layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/ContextDataResolver.java
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // }
import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.util.IndexedStringMap; import org.apache.logging.log4j.util.ReadOnlyStringMap; import java.io.IOException; import java.util.regex.Pattern;
/* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.resolver; /** * Add Mapped Diagnostic Context (MDC). */ class ContextDataResolver implements EventResolver { private final EventResolverContext context; private final String key; ContextDataResolver(EventResolverContext context, String key) { this.context = context; this.key = key; } static String getName() { return "mdc"; } @Override public void resolve(LogEvent logEvent, JsonGenerator jsonGenerator) throws IOException { // Retrieve context data. ReadOnlyStringMap contextData = logEvent.getContextData(); if (contextData == null || contextData.isEmpty()) { jsonGenerator.writeNull(); return; } // Check if key matches. if (key != null) { Object value = contextData.getValue(key); boolean valueExcluded = isValueExcluded(context, value); if (valueExcluded) { jsonGenerator.writeNull(); } else {
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java // public enum JsonGenerators {; // // private static final class DoubleWriterContext { // // private static final int MAX_BUFFER_LENGTH = // String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length() // + 1; // // private final StringBuilder builder = new StringBuilder(); // // private char[] buffer = new char[MAX_BUFFER_LENGTH]; // // } // // private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF = // Constants.ENABLE_THREADLOCALS // ? ThreadLocal.withInitial(DoubleWriterContext::new) // : null; // // public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException { // if (fractionalPart < 0) { // throw new IllegalArgumentException("negative fraction"); // } else if (fractionalPart == 0) { // jsonGenerator.writeNumber(integralPart); // } else if (Constants.ENABLE_THREADLOCALS) { // DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get(); // context.builder.setLength(0); // context.builder.append(integralPart); // context.builder.append('.'); // context.builder.append(fractionalPart); // int length = context.builder.length(); // context.builder.getChars(0, length, context.buffer, 0); // // jackson-core version >=2.10.2 is required for the following line // // to avoid FasterXML/jackson-core#588 bug. // jsonGenerator.writeRawValue(context.buffer, 0, length); // } else { // String formattedNumber = "" + integralPart + '.' + fractionalPart; // jsonGenerator.writeNumber(formattedNumber); // } // } // // /** // * Writes given object, preferably using GC-free writers. // */ // public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException { // // if (object == null) { // jsonGenerator.writeNull(); // return; // } // // if (object instanceof String) { // jsonGenerator.writeString((String) object); // return; // } // // if (object instanceof Short) { // jsonGenerator.writeNumber((Short) object); // return; // } // // if (object instanceof Integer) { // jsonGenerator.writeNumber((Integer) object); // return; // } // // if (object instanceof Long) { // jsonGenerator.writeNumber((Long) object); // return; // } // // if (object instanceof BigDecimal) { // jsonGenerator.writeNumber((BigDecimal) object); // return; // } // // if (object instanceof Float) { // jsonGenerator.writeNumber((Float) object); // Not GC-free! // return; // } // // if (object instanceof Double) { // jsonGenerator.writeNumber((Double) object); // Not GC-free! // return; // } // // if (object instanceof byte[]) { // jsonGenerator.writeBinary((byte[]) object); // return; // } // // jsonGenerator.writeObject(object); // // } // // } // Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/ContextDataResolver.java import com.fasterxml.jackson.core.JsonGenerator; import com.vlkan.log4j2.logstash.layout.util.JsonGenerators; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.util.IndexedStringMap; import org.apache.logging.log4j.util.ReadOnlyStringMap; import java.io.IOException; import java.util.regex.Pattern; /* * Copyright 2017-2020 Volkan Yazıcı * * 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 permits and * limitations under the License. */ package com.vlkan.log4j2.logstash.layout.resolver; /** * Add Mapped Diagnostic Context (MDC). */ class ContextDataResolver implements EventResolver { private final EventResolverContext context; private final String key; ContextDataResolver(EventResolverContext context, String key) { this.context = context; this.key = key; } static String getName() { return "mdc"; } @Override public void resolve(LogEvent logEvent, JsonGenerator jsonGenerator) throws IOException { // Retrieve context data. ReadOnlyStringMap contextData = logEvent.getContextData(); if (contextData == null || contextData.isEmpty()) { jsonGenerator.writeNull(); return; } // Check if key matches. if (key != null) { Object value = contextData.getValue(key); boolean valueExcluded = isValueExcluded(context, value); if (valueExcluded) { jsonGenerator.writeNull(); } else {
JsonGenerators.writeObject(jsonGenerator, value);
google/agera
agera/src/main/java/com/google/android/agera/RepositoryCompiler.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <T> Function<T, T> identityFunction() { // @SuppressWarnings("unchecked") // final Function<T, T> identityFunction = (Function<T, T>) NULL_OPERATOR; // return identityFunction; // }
import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.CompiledRepository.addBindWith; import static com.google.android.agera.CompiledRepository.addCheck; import static com.google.android.agera.CompiledRepository.addEnd; import static com.google.android.agera.CompiledRepository.addFilterFailure; import static com.google.android.agera.CompiledRepository.addFilterSuccess; import static com.google.android.agera.CompiledRepository.addGetFrom; import static com.google.android.agera.CompiledRepository.addGoLazy; import static com.google.android.agera.CompiledRepository.addGoTo; import static com.google.android.agera.CompiledRepository.addMergeIn; import static com.google.android.agera.CompiledRepository.addSendTo; import static com.google.android.agera.CompiledRepository.addTransform; import static com.google.android.agera.CompiledRepository.compiledRepository; import static com.google.android.agera.Functions.identityFunction; import static com.google.android.agera.Mergers.objectsUnequal; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor;
} @Retention(RetentionPolicy.SOURCE) @IntDef({NOTHING, FIRST_EVENT_SOURCE, FREQUENCY_OR_MORE_EVENT_SOURCE, FLOW, TERMINATE_THEN_FLOW, TERMINATE_THEN_END, CONFIG}) private @interface Expect {} private static final int NOTHING = 0; private static final int FIRST_EVENT_SOURCE = 1; private static final int FREQUENCY_OR_MORE_EVENT_SOURCE = 2; private static final int FLOW = 3; private static final int TERMINATE_THEN_FLOW = 4; private static final int TERMINATE_THEN_END = 5; private static final int CONFIG = 6; private Object initialValue; private final ArrayList<Observable> eventSources = new ArrayList<>(); private int frequency; private final ArrayList<Object> directives = new ArrayList<>(); // 2x fields below: store caseExtractor and casePredicate for check(caseExtractor, casePredicate) // for use in terminate(); if null then terminate() is terminating an attempt directive. private Function caseExtractor; private Predicate casePredicate; private boolean goLazyUsed; private Merger notifyChecker = objectsUnequal(); @RepositoryConfig private int deactivationConfig; @RepositoryConfig private int concurrentUpdateConfig; @NonNull
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <T> Function<T, T> identityFunction() { // @SuppressWarnings("unchecked") // final Function<T, T> identityFunction = (Function<T, T>) NULL_OPERATOR; // return identityFunction; // } // Path: agera/src/main/java/com/google/android/agera/RepositoryCompiler.java import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.CompiledRepository.addBindWith; import static com.google.android.agera.CompiledRepository.addCheck; import static com.google.android.agera.CompiledRepository.addEnd; import static com.google.android.agera.CompiledRepository.addFilterFailure; import static com.google.android.agera.CompiledRepository.addFilterSuccess; import static com.google.android.agera.CompiledRepository.addGetFrom; import static com.google.android.agera.CompiledRepository.addGoLazy; import static com.google.android.agera.CompiledRepository.addGoTo; import static com.google.android.agera.CompiledRepository.addMergeIn; import static com.google.android.agera.CompiledRepository.addSendTo; import static com.google.android.agera.CompiledRepository.addTransform; import static com.google.android.agera.CompiledRepository.compiledRepository; import static com.google.android.agera.Functions.identityFunction; import static com.google.android.agera.Mergers.objectsUnequal; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor; } @Retention(RetentionPolicy.SOURCE) @IntDef({NOTHING, FIRST_EVENT_SOURCE, FREQUENCY_OR_MORE_EVENT_SOURCE, FLOW, TERMINATE_THEN_FLOW, TERMINATE_THEN_END, CONFIG}) private @interface Expect {} private static final int NOTHING = 0; private static final int FIRST_EVENT_SOURCE = 1; private static final int FREQUENCY_OR_MORE_EVENT_SOURCE = 2; private static final int FLOW = 3; private static final int TERMINATE_THEN_FLOW = 4; private static final int TERMINATE_THEN_END = 5; private static final int CONFIG = 6; private Object initialValue; private final ArrayList<Observable> eventSources = new ArrayList<>(); private int frequency; private final ArrayList<Object> directives = new ArrayList<>(); // 2x fields below: store caseExtractor and casePredicate for check(caseExtractor, casePredicate) // for use in terminate(); if null then terminate() is terminating an attempt directive. private Function caseExtractor; private Predicate casePredicate; private boolean goLazyUsed; private Merger notifyChecker = objectsUnequal(); @RepositoryConfig private int deactivationConfig; @RepositoryConfig private int concurrentUpdateConfig; @NonNull
private Receiver discardedValueDisposer = NULL_OPERATOR;
google/agera
agera/src/main/java/com/google/android/agera/RepositoryCompiler.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <T> Function<T, T> identityFunction() { // @SuppressWarnings("unchecked") // final Function<T, T> identityFunction = (Function<T, T>) NULL_OPERATOR; // return identityFunction; // }
import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.CompiledRepository.addBindWith; import static com.google.android.agera.CompiledRepository.addCheck; import static com.google.android.agera.CompiledRepository.addEnd; import static com.google.android.agera.CompiledRepository.addFilterFailure; import static com.google.android.agera.CompiledRepository.addFilterSuccess; import static com.google.android.agera.CompiledRepository.addGetFrom; import static com.google.android.agera.CompiledRepository.addGoLazy; import static com.google.android.agera.CompiledRepository.addGoTo; import static com.google.android.agera.CompiledRepository.addMergeIn; import static com.google.android.agera.CompiledRepository.addSendTo; import static com.google.android.agera.CompiledRepository.addTransform; import static com.google.android.agera.CompiledRepository.compiledRepository; import static com.google.android.agera.Functions.identityFunction; import static com.google.android.agera.Mergers.objectsUnequal; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor;
//region RSyncFlow @NonNull @Override public RepositoryCompiler getFrom(@NonNull final Supplier supplier) { checkExpect(FLOW); addGetFrom(supplier, directives); return this; } @NonNull @Override public RepositoryCompiler mergeIn(@NonNull final Supplier supplier, @NonNull final Merger merger) { checkExpect(FLOW); addMergeIn(supplier, merger, directives); return this; } @NonNull @Override public RepositoryCompiler transform(@NonNull final Function function) { checkExpect(FLOW); addTransform(function, directives); return this; } @NonNull @Override public RepositoryCompiler check(@NonNull final Predicate predicate) {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <T> Function<T, T> identityFunction() { // @SuppressWarnings("unchecked") // final Function<T, T> identityFunction = (Function<T, T>) NULL_OPERATOR; // return identityFunction; // } // Path: agera/src/main/java/com/google/android/agera/RepositoryCompiler.java import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.CompiledRepository.addBindWith; import static com.google.android.agera.CompiledRepository.addCheck; import static com.google.android.agera.CompiledRepository.addEnd; import static com.google.android.agera.CompiledRepository.addFilterFailure; import static com.google.android.agera.CompiledRepository.addFilterSuccess; import static com.google.android.agera.CompiledRepository.addGetFrom; import static com.google.android.agera.CompiledRepository.addGoLazy; import static com.google.android.agera.CompiledRepository.addGoTo; import static com.google.android.agera.CompiledRepository.addMergeIn; import static com.google.android.agera.CompiledRepository.addSendTo; import static com.google.android.agera.CompiledRepository.addTransform; import static com.google.android.agera.CompiledRepository.compiledRepository; import static com.google.android.agera.Functions.identityFunction; import static com.google.android.agera.Mergers.objectsUnequal; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.concurrent.Executor; //region RSyncFlow @NonNull @Override public RepositoryCompiler getFrom(@NonNull final Supplier supplier) { checkExpect(FLOW); addGetFrom(supplier, directives); return this; } @NonNull @Override public RepositoryCompiler mergeIn(@NonNull final Supplier supplier, @NonNull final Merger merger) { checkExpect(FLOW); addMergeIn(supplier, merger, directives); return this; } @NonNull @Override public RepositoryCompiler transform(@NonNull final Function function) { checkExpect(FLOW); addTransform(function, directives); return this; } @NonNull @Override public RepositoryCompiler check(@NonNull final Predicate predicate) {
return check(identityFunction(), predicate);
google/agera
extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // }
import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // } // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock
private Binder<String, View> binder;
google/agera
extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // }
import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this);
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // } // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this);
setDataBinding(viewDataBinding, LAYOUT_ID);
google/agera
extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // }
import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this); setDataBinding(viewDataBinding, LAYOUT_ID); when(view.getTag()).thenReturn("string"); } @Test public void shouldReturnLayoutForLayoutResId() {
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // } // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this); setDataBinding(viewDataBinding, LAYOUT_ID); when(view.getTag()).thenReturn("string"); } @Test public void shouldReturnLayoutForLayoutResId() {
final LayoutPresenter layoutPresenter =
google/agera
extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // }
import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this); setDataBinding(viewDataBinding, LAYOUT_ID); when(view.getTag()).thenReturn("string"); } @Test public void shouldReturnLayoutForLayoutResId() { final LayoutPresenter layoutPresenter =
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // } // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvdatabinding; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class DataBindingLayoutPresentersTest { private static final Object HANDLER = new Object(); private static final Object SECOND_HANDLER = new Object(); @LayoutRes private static final int LAYOUT_ID = 1; private static final int HANDLER_ID = 4; private static final int SECOND_HANDLER_ID = 5; @Mock private Binder<String, View> binder; @Mock private ViewDataBinding viewDataBinding; @Mock private View view; @Before public void setUp() { initMocks(this); setDataBinding(viewDataBinding, LAYOUT_ID); when(view.getTag()).thenReturn("string"); } @Test public void shouldReturnLayoutForLayoutResId() { final LayoutPresenter layoutPresenter =
dataBindingLayoutPresenterFor(LAYOUT_ID)
google/agera
extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // }
import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
.handler(SECOND_HANDLER_ID, SECOND_HANDLER) .onRecycle(CLEAR_HANDLERS) .build(); layoutPresenter.recycle(view); verify(viewDataBinding).setVariable(HANDLER_ID, null); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, null); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); } @Test public void shouldBindLayoutPresenter() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .build(); layoutPresenter.bind(view); verify(viewDataBinding).setVariable(HANDLER_ID, HANDLER); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, SECOND_HANDLER); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); } @Test public void shouldHavePrivateConstructor() {
// Path: extensions/rvdatabinding/src/test/java/android/databinding/DataBinderMapper.java // public static void setDataBinding(ViewDataBinding dataBinding, int layoutId) { // bindings.put(layoutId, dataBinding); // } // // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/rvdatabinding/src/main/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { // return new Builder(layoutId); // } // // Path: agera/src/main/java/com/google/android/agera/Binder.java // public interface Binder<TFirst, TSecond> { // // /** // * Accepts the given values {@code first} and {@code second}. // */ // void bind(@NonNull TFirst first, @NonNull TSecond second); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenter.java // public abstract class LayoutPresenter { // /** // * Returns the layout resource ID to inflate. // */ // @LayoutRes // public abstract int getLayoutResId(); // // /** // * Updates the view to present. The view is inflated from the layout resource specified by // * {@link #getLayoutResId}, but may have been previously updated with a different presenter. // * Therefore, implementation should take care of resetting the view state. // * // * @param view The view to present. // */ // public abstract void bind(@NonNull final View view); // // /** // * Called when the given {@code view} is recycled. // * // * @param view The view to recycle. // */ // public void recycle(@NonNull final View view) {} // } // Path: extensions/rvdatabinding/src/test/java/com/google/android/agera/rvdatabinding/DataBindingLayoutPresentersTest.java import static android.databinding.DataBinderMapper.setDataBinding; import static com.google.android.agera.rvdatabinding.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.rvdatabinding.DataBindingLayoutPresenters.dataBindingLayoutPresenterFor; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ALL; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_HANDLERS; import static com.google.android.agera.rvdatabinding.RecycleConfig.CLEAR_ITEM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import android.databinding.ViewDataBinding; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Binder; import com.google.android.agera.rvadapter.LayoutPresenter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .onRecycle(CLEAR_HANDLERS) .build(); layoutPresenter.recycle(view); verify(viewDataBinding).setVariable(HANDLER_ID, null); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, null); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); } @Test public void shouldBindLayoutPresenter() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .build(); layoutPresenter.bind(view); verify(viewDataBinding).setVariable(HANDLER_ID, HANDLER); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, SECOND_HANDLER); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); } @Test public void shouldHavePrivateConstructor() {
assertThat(DataBindingLayoutPresenters.class, hasPrivateConstructor());
google/agera
extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java
// Path: agera/src/main/java/com/google/android/agera/Receivers.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Receiver<T> nullReceiver() { // return NULL_OPERATOR; // }
import static com.google.android.agera.Receivers.nullReceiver; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.view.View; import com.google.android.agera.Receiver;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; /** * Contains a basic implementation of {@link LayoutPresenter}. */ public final class LayoutPresenters { /** * Starts the creation of a {@link LayoutPresenter}. */ @SuppressWarnings("unchecked") @NonNull public static Builder layoutPresenterFor(@LayoutRes int layoutId) { return new Builder(layoutId); } /** * Creates a simple {@link LayoutPresenter} for the {@code layoutId}. */ @SuppressWarnings("unchecked") @NonNull public static LayoutPresenter layout(@LayoutRes int layoutId) { return new Builder(layoutId).build(); } public static final class Builder { @NonNull
// Path: agera/src/main/java/com/google/android/agera/Receivers.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Receiver<T> nullReceiver() { // return NULL_OPERATOR; // } // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java import static com.google.android.agera.Receivers.nullReceiver; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.view.View; import com.google.android.agera.Receiver; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; /** * Contains a basic implementation of {@link LayoutPresenter}. */ public final class LayoutPresenters { /** * Starts the creation of a {@link LayoutPresenter}. */ @SuppressWarnings("unchecked") @NonNull public static Builder layoutPresenterFor(@LayoutRes int layoutId) { return new Builder(layoutId); } /** * Creates a simple {@link LayoutPresenter} for the {@code layoutId}. */ @SuppressWarnings("unchecked") @NonNull public static LayoutPresenter layout(@LayoutRes int layoutId) { return new Builder(layoutId).build(); } public static final class Builder { @NonNull
private Receiver recycler = nullReceiver();
google/agera
extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static Observable compositeObservable(@NonNull final Observable... observables) { // return compositeObservable(0, observables); // }
import static com.google.android.agera.Observables.compositeObservable; import static com.google.android.agera.Preconditions.checkArgument; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.annotation.TargetApi; import android.app.Activity; import android.app.Application.ActivityLifecycleCallbacks; import android.os.Bundle; import android.support.annotation.IntDef; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.Adapter; import android.support.v7.widget.RecyclerView.ViewHolder; import android.view.LayoutInflater; import android.view.ViewGroup; import com.google.android.agera.Observable; import com.google.android.agera.Repository; import com.google.android.agera.Updatable; import java.util.ArrayList; import java.util.Arrays; import java.util.IdentityHashMap; import java.util.List; import java.util.Map;
private final Part[] parts; @NonNull private final Map<ViewHolder, Part> partForViewHolder; @NonNull private final Observable additionalObservables; @NonNull private final int[] endPositions; /** * Whether getItemCount has not been called since adapter creation or since the last * notifyDataSetChanged event. This flag being true suppresses all adapter events; and data * updates will be performed at getItemCount. */ private boolean dataInvalid; private int resolvedPartIndex; private int resolvedItemIndex; public RepositoryAdapter(@NonNull final Builder builder) { final int partCount = builder.parts.size(); checkArgument(partCount > 0, "Must add at least one part"); this.partCount = partCount; this.staticItemCount = builder.staticItemCount; this.parts = new Part[partCount]; for (int i = 0; i < partCount; i++) { final Part part = builder.parts.get(i); parts[i] = part; part.attach(this, i); } this.partForViewHolder = new IdentityHashMap<>();
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static Observable compositeObservable(@NonNull final Observable... observables) { // return compositeObservable(0, observables); // } // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java import static com.google.android.agera.Observables.compositeObservable; import static com.google.android.agera.Preconditions.checkArgument; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.annotation.TargetApi; import android.app.Activity; import android.app.Application.ActivityLifecycleCallbacks; import android.os.Bundle; import android.support.annotation.IntDef; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.Adapter; import android.support.v7.widget.RecyclerView.ViewHolder; import android.view.LayoutInflater; import android.view.ViewGroup; import com.google.android.agera.Observable; import com.google.android.agera.Repository; import com.google.android.agera.Updatable; import java.util.ArrayList; import java.util.Arrays; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; private final Part[] parts; @NonNull private final Map<ViewHolder, Part> partForViewHolder; @NonNull private final Observable additionalObservables; @NonNull private final int[] endPositions; /** * Whether getItemCount has not been called since adapter creation or since the last * notifyDataSetChanged event. This flag being true suppresses all adapter events; and data * updates will be performed at getItemCount. */ private boolean dataInvalid; private int resolvedPartIndex; private int resolvedItemIndex; public RepositoryAdapter(@NonNull final Builder builder) { final int partCount = builder.parts.size(); checkArgument(partCount > 0, "Must add at least one part"); this.partCount = partCount; this.staticItemCount = builder.staticItemCount; this.parts = new Part[partCount]; for (int i = 0; i < partCount; i++) { final Part part = builder.parts.get(i); parts[i] = part; part.attach(this, i); } this.partForViewHolder = new IdentityHashMap<>();
this.additionalObservables = compositeObservable(
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/LayoutPresentersTest.java
// Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static LayoutPresenter layout(@LayoutRes int layoutId) { // return new Builder(layoutId).build(); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder layoutPresenterFor(@LayoutRes int layoutId) { // return new Builder(layoutId); // }
import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static com.google.android.agera.rvadapter.LayoutPresenters.layout; import static com.google.android.agera.rvadapter.LayoutPresenters.layoutPresenterFor; import static com.google.android.agera.rvadapter.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Receiver; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class LayoutPresentersTest { @LayoutRes private static final int LAYOUT_ID = 0; @Mock private Receiver<View> binder; @Mock private Receiver<View> recycler; @Mock private View view; @Before public void setUp() { initMocks(this); } @Test public void shouldReturnLayoutIdForCompiledLayout() { final LayoutPresenter layoutPresenter =
// Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static LayoutPresenter layout(@LayoutRes int layoutId) { // return new Builder(layoutId).build(); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder layoutPresenterFor(@LayoutRes int layoutId) { // return new Builder(layoutId); // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/LayoutPresentersTest.java import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static com.google.android.agera.rvadapter.LayoutPresenters.layout; import static com.google.android.agera.rvadapter.LayoutPresenters.layoutPresenterFor; import static com.google.android.agera.rvadapter.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Receiver; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class LayoutPresentersTest { @LayoutRes private static final int LAYOUT_ID = 0; @Mock private Receiver<View> binder; @Mock private Receiver<View> recycler; @Mock private View view; @Before public void setUp() { initMocks(this); } @Test public void shouldReturnLayoutIdForCompiledLayout() { final LayoutPresenter layoutPresenter =
layoutPresenterFor(LAYOUT_ID)
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/LayoutPresentersTest.java
// Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static LayoutPresenter layout(@LayoutRes int layoutId) { // return new Builder(layoutId).build(); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder layoutPresenterFor(@LayoutRes int layoutId) { // return new Builder(layoutId); // }
import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static com.google.android.agera.rvadapter.LayoutPresenters.layout; import static com.google.android.agera.rvadapter.LayoutPresenters.layoutPresenterFor; import static com.google.android.agera.rvadapter.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Receiver; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class LayoutPresentersTest { @LayoutRes private static final int LAYOUT_ID = 0; @Mock private Receiver<View> binder; @Mock private Receiver<View> recycler; @Mock private View view; @Before public void setUp() { initMocks(this); } @Test public void shouldReturnLayoutIdForCompiledLayout() { final LayoutPresenter layoutPresenter = layoutPresenterFor(LAYOUT_ID) .build(); assertThat(layoutPresenter.getLayoutResId(), is(LAYOUT_ID)); } @Test public void shouldReturnLayoutIdForLayout() {
// Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static LayoutPresenter layout(@LayoutRes int layoutId) { // return new Builder(layoutId).build(); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/LayoutPresenters.java // @SuppressWarnings("unchecked") // @NonNull // public static Builder layoutPresenterFor(@LayoutRes int layoutId) { // return new Builder(layoutId); // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/LayoutPresentersTest.java import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static com.google.android.agera.rvadapter.LayoutPresenters.layout; import static com.google.android.agera.rvadapter.LayoutPresenters.layoutPresenterFor; import static com.google.android.agera.rvadapter.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; import android.support.annotation.LayoutRes; import android.view.View; import com.google.android.agera.Receiver; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class LayoutPresentersTest { @LayoutRes private static final int LAYOUT_ID = 0; @Mock private Receiver<View> binder; @Mock private Receiver<View> recycler; @Mock private View view; @Before public void setUp() { initMocks(this); } @Test public void shouldReturnLayoutIdForCompiledLayout() { final LayoutPresenter layoutPresenter = layoutPresenterFor(LAYOUT_ID) .build(); assertThat(layoutPresenter.getLayoutResId(), is(LAYOUT_ID)); } @Test public void shouldReturnLayoutIdForLayout() {
final LayoutPresenter layoutPresenter = layout(LAYOUT_ID);
google/agera
agera/src/test/java/com/google/android/agera/SuppliersTest.java
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // }
import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() {
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // } // Path: agera/src/test/java/com/google/android/agera/SuppliersTest.java import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() {
assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM));
google/agera
agera/src/test/java/com/google/android/agera/SuppliersTest.java
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // }
import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() {
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // } // Path: agera/src/test/java/com/google/android/agera/SuppliersTest.java import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() {
assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM));
google/agera
agera/src/test/java/com/google/android/agera/SuppliersTest.java
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // }
import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() { assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM)); } @Test public void shouldReturnStaticSupplierValue() {
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // } // Path: agera/src/test/java/com/google/android/agera/SuppliersTest.java import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() { assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM)); } @Test public void shouldReturnStaticSupplierValue() {
assertThat(staticSupplier(ITEM), gives(ITEM));
google/agera
agera/src/test/java/com/google/android/agera/SuppliersTest.java
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // }
import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() { assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM)); } @Test public void shouldReturnStaticSupplierValue() { assertThat(staticSupplier(ITEM), gives(ITEM)); } @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T, F> Supplier<T> functionAsSupplier( // @NonNull final Function<F, T> function, @NonNull final F from) { // return new FunctionToSupplierConverter<>(function, from); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> gives(@NonNull final T value) { // return new SupplierGives<>(value); // } // Path: agera/src/test/java/com/google/android/agera/SuppliersTest.java import static com.google.android.agera.Suppliers.functionAsSupplier; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.SupplierGives.gives; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class SuppliersTest { private static final Object ITEM = new Object(); private static final Object RETURN_ITEM = new Object(); @Mock private Function<Object, Object> mockFunction; @Before public void setUp() { initMocks(this); when(mockFunction.apply(ITEM)).thenReturn(RETURN_ITEM); } @Test public void shouldRunFactoryWithFromObjectAndReturnFactoryOutputForFunctionWithSupplier() { assertThat(functionAsSupplier(mockFunction, ITEM), gives(RETURN_ITEM)); } @Test public void shouldReturnStaticSupplierValue() { assertThat(staticSupplier(ITEM), gives(ITEM)); } @Test public void shouldHavePrivateConstructor() {
assertThat(Suppliers.class, hasPrivateConstructor());
google/agera
agera/src/main/java/com/google/android/agera/FunctionCompiler.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FItem<TPrev, TFrom> extends FBase<TPrev, TFrom> { // /** // * Adds a {@link Function} to the behavior chain to unpack an item into a {@link List}, allowing // * list behaviors to be used from this point on. // * // * @param function the unpack function // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> unpack(@NonNull Function<? super TPrev, List<TTo>> function); // } // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FList<TPrev, TPrevList, TFrom> extends FBase<TPrevList, TFrom> { // // /** // * Adds a {@link Function} to the behavior chain to change the entire list to a new list. // * // * <p>The {@code morph} directive is functionally equivalent to {@code apply}, which treats the // * input list as a single item. But {@code morph} is aware of the list-typed output and allows // * list behaviors to follow immediately. Since the only difference between {@link #apply} and // * {@code morph} is the next state of the compiler, {@code thenMorph} does not exist since // * {@link #thenApply} can be used in its place. // * // * @param function the function to apply to the list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> morph(@NonNull Function<List<TPrev>, List<TTo>> function); // // /** // * Adds a {@link Function} to the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> map(@NonNull Function<TPrev, TTo> function); // // /** // * Adds a {@link Function} to the end of the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> Function<TFrom, List<TTo>> thenMap(@NonNull Function<? super TPrev, TTo> function); // // /** // * Adds a {@link Predicate} to the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // FList<TPrev, TPrevList, TFrom> filter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // FList<TPrev, TPrevList, TFrom> limit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // FList<TPrev, TPrevList, TFrom> sort(@NonNull Comparator<TPrev> comparator); // // /** // * Adds a {@link Predicate} to the end of the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // Function<TFrom, TPrevList> thenFilter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the end of the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // Function<TFrom, TPrevList> thenLimit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // Function<TFrom, TPrevList> thenSort(@NonNull Comparator<TPrev> comparator); // }
import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import android.support.annotation.NonNull; import com.google.android.agera.FunctionCompilerStates.FItem; import com.google.android.agera.FunctionCompilerStates.FList; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @SuppressWarnings({"unchecked, rawtypes"}) final class FunctionCompiler implements FList, FItem { private static final ThreadLocal<FunctionCompiler> compilers = new ThreadLocal<>(); @NonNull static FunctionCompiler functionCompiler() { FunctionCompiler compiler = compilers.get(); if (compiler == null) { compiler = new FunctionCompiler(); } else { // Remove compiler from the ThreadLocal to prevent reuse in the middle of a compilation. // recycle(), called by compile(), will return the compiler here. ThreadLocal.set(null) keeps // the entry (with a null value) whereas remove() removes the entry; because we expect the // return of the compiler, don't use the heavier remove(). compilers.set(null); } return compiler; } private static void recycle(@NonNull final FunctionCompiler compiler) { compiler.functions.clear(); compilers.set(compiler); } @NonNull private final List<Function> functions; FunctionCompiler() { this.functions = new ArrayList<>(); } private void addFunction(@NonNull final Function function) {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FItem<TPrev, TFrom> extends FBase<TPrev, TFrom> { // /** // * Adds a {@link Function} to the behavior chain to unpack an item into a {@link List}, allowing // * list behaviors to be used from this point on. // * // * @param function the unpack function // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> unpack(@NonNull Function<? super TPrev, List<TTo>> function); // } // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FList<TPrev, TPrevList, TFrom> extends FBase<TPrevList, TFrom> { // // /** // * Adds a {@link Function} to the behavior chain to change the entire list to a new list. // * // * <p>The {@code morph} directive is functionally equivalent to {@code apply}, which treats the // * input list as a single item. But {@code morph} is aware of the list-typed output and allows // * list behaviors to follow immediately. Since the only difference between {@link #apply} and // * {@code morph} is the next state of the compiler, {@code thenMorph} does not exist since // * {@link #thenApply} can be used in its place. // * // * @param function the function to apply to the list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> morph(@NonNull Function<List<TPrev>, List<TTo>> function); // // /** // * Adds a {@link Function} to the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> map(@NonNull Function<TPrev, TTo> function); // // /** // * Adds a {@link Function} to the end of the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> Function<TFrom, List<TTo>> thenMap(@NonNull Function<? super TPrev, TTo> function); // // /** // * Adds a {@link Predicate} to the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // FList<TPrev, TPrevList, TFrom> filter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // FList<TPrev, TPrevList, TFrom> limit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // FList<TPrev, TPrevList, TFrom> sort(@NonNull Comparator<TPrev> comparator); // // /** // * Adds a {@link Predicate} to the end of the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // Function<TFrom, TPrevList> thenFilter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the end of the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // Function<TFrom, TPrevList> thenLimit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // Function<TFrom, TPrevList> thenSort(@NonNull Comparator<TPrev> comparator); // } // Path: agera/src/main/java/com/google/android/agera/FunctionCompiler.java import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import android.support.annotation.NonNull; import com.google.android.agera.FunctionCompilerStates.FItem; import com.google.android.agera.FunctionCompilerStates.FList; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @SuppressWarnings({"unchecked, rawtypes"}) final class FunctionCompiler implements FList, FItem { private static final ThreadLocal<FunctionCompiler> compilers = new ThreadLocal<>(); @NonNull static FunctionCompiler functionCompiler() { FunctionCompiler compiler = compilers.get(); if (compiler == null) { compiler = new FunctionCompiler(); } else { // Remove compiler from the ThreadLocal to prevent reuse in the middle of a compilation. // recycle(), called by compile(), will return the compiler here. ThreadLocal.set(null) keeps // the entry (with a null value) whereas remove() removes the entry; because we expect the // return of the compiler, don't use the heavier remove(). compilers.set(null); } return compiler; } private static void recycle(@NonNull final FunctionCompiler compiler) { compiler.functions.clear(); compilers.set(compiler); } @NonNull private final List<Function> functions; FunctionCompiler() { this.functions = new ArrayList<>(); } private void addFunction(@NonNull final Function function) {
if (function != NULL_OPERATOR) {
google/agera
agera/src/main/java/com/google/android/agera/FunctionCompiler.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FItem<TPrev, TFrom> extends FBase<TPrev, TFrom> { // /** // * Adds a {@link Function} to the behavior chain to unpack an item into a {@link List}, allowing // * list behaviors to be used from this point on. // * // * @param function the unpack function // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> unpack(@NonNull Function<? super TPrev, List<TTo>> function); // } // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FList<TPrev, TPrevList, TFrom> extends FBase<TPrevList, TFrom> { // // /** // * Adds a {@link Function} to the behavior chain to change the entire list to a new list. // * // * <p>The {@code morph} directive is functionally equivalent to {@code apply}, which treats the // * input list as a single item. But {@code morph} is aware of the list-typed output and allows // * list behaviors to follow immediately. Since the only difference between {@link #apply} and // * {@code morph} is the next state of the compiler, {@code thenMorph} does not exist since // * {@link #thenApply} can be used in its place. // * // * @param function the function to apply to the list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> morph(@NonNull Function<List<TPrev>, List<TTo>> function); // // /** // * Adds a {@link Function} to the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> map(@NonNull Function<TPrev, TTo> function); // // /** // * Adds a {@link Function} to the end of the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> Function<TFrom, List<TTo>> thenMap(@NonNull Function<? super TPrev, TTo> function); // // /** // * Adds a {@link Predicate} to the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // FList<TPrev, TPrevList, TFrom> filter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // FList<TPrev, TPrevList, TFrom> limit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // FList<TPrev, TPrevList, TFrom> sort(@NonNull Comparator<TPrev> comparator); // // /** // * Adds a {@link Predicate} to the end of the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // Function<TFrom, TPrevList> thenFilter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the end of the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // Function<TFrom, TPrevList> thenLimit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // Function<TFrom, TPrevList> thenSort(@NonNull Comparator<TPrev> comparator); // }
import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import android.support.annotation.NonNull; import com.google.android.agera.FunctionCompilerStates.FItem; import com.google.android.agera.FunctionCompilerStates.FList; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List;
} final Function[] newFunctions = functions.toArray(new Function[functions.size()]); recycle(this); return new ChainFunction(newFunctions); } @NonNull @Override public FList unpack(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FItem apply(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FList morph(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FList filter(@NonNull final Predicate filter) {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FItem<TPrev, TFrom> extends FBase<TPrev, TFrom> { // /** // * Adds a {@link Function} to the behavior chain to unpack an item into a {@link List}, allowing // * list behaviors to be used from this point on. // * // * @param function the unpack function // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> unpack(@NonNull Function<? super TPrev, List<TTo>> function); // } // // Path: agera/src/main/java/com/google/android/agera/FunctionCompilerStates.java // interface FList<TPrev, TPrevList, TFrom> extends FBase<TPrevList, TFrom> { // // /** // * Adds a {@link Function} to the behavior chain to change the entire list to a new list. // * // * <p>The {@code morph} directive is functionally equivalent to {@code apply}, which treats the // * input list as a single item. But {@code morph} is aware of the list-typed output and allows // * list behaviors to follow immediately. Since the only difference between {@link #apply} and // * {@code morph} is the next state of the compiler, {@code thenMorph} does not exist since // * {@link #thenApply} can be used in its place. // * // * @param function the function to apply to the list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> morph(@NonNull Function<List<TPrev>, List<TTo>> function); // // /** // * Adds a {@link Function} to the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> FList<TTo, List<TTo>, TFrom> map(@NonNull Function<TPrev, TTo> function); // // /** // * Adds a {@link Function} to the end of the behavior chain to map each item into a new type. // * // * @param function the function to apply to each item to create a new list // */ // @NonNull // <TTo> Function<TFrom, List<TTo>> thenMap(@NonNull Function<? super TPrev, TTo> function); // // /** // * Adds a {@link Predicate} to the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // FList<TPrev, TPrevList, TFrom> filter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // FList<TPrev, TPrevList, TFrom> limit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // FList<TPrev, TPrevList, TFrom> sort(@NonNull Comparator<TPrev> comparator); // // /** // * Adds a {@link Predicate} to the end of the behavior chain to filter out items. // * // * @param filter the predicate to filter by // */ // @NonNull // Function<TFrom, TPrevList> thenFilter(@NonNull Predicate<? super TPrev> filter); // // /** // * Adds a max number of item limit to the end of the behavior chain. // * // * @param limit the max number of items the list is limited to // */ // @NonNull // Function<TFrom, TPrevList> thenLimit(int limit); // // /** // * Adds a {@link Comparator} to the behavior chain to sort the items. // * // * @param comparator the comparator to sort the items // */ // @NonNull // Function<TFrom, TPrevList> thenSort(@NonNull Comparator<TPrev> comparator); // } // Path: agera/src/main/java/com/google/android/agera/FunctionCompiler.java import static com.google.android.agera.Common.NULL_OPERATOR; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import android.support.annotation.NonNull; import com.google.android.agera.FunctionCompilerStates.FItem; import com.google.android.agera.FunctionCompilerStates.FList; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; } final Function[] newFunctions = functions.toArray(new Function[functions.size()]); recycle(this); return new ChainFunction(newFunctions); } @NonNull @Override public FList unpack(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FItem apply(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FList morph(@NonNull final Function function) { addFunction(function); return this; } @NonNull @Override public FList filter(@NonNull final Predicate filter) {
if (filter != TRUE_CONDICATE) {
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // }
import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map;
@NonNull private final String method; @NonNull private final Map<String, String> header; @NonNull private final String url; @NonNull private byte[] body; private boolean compiled; private boolean useCaches; private boolean followRedirects; private int connectTimeoutMs; private int readTimeoutMs; HttpRequestCompiler(@NonNull final String method, @NonNull final String url) { this.compiled = false; this.followRedirects = true; this.useCaches = true; this.connectTimeoutMs = CONNECT_TIMEOUT_MS; this.readTimeoutMs = READ_TIMEOUT_MS; this.url = url; this.method = checkNotNull(method); this.header = new HashMap<>(); this.body = EMPTY_BODY; } @NonNull @Override
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map; @NonNull private final String method; @NonNull private final Map<String, String> header; @NonNull private final String url; @NonNull private byte[] body; private boolean compiled; private boolean useCaches; private boolean followRedirects; private int connectTimeoutMs; private int readTimeoutMs; HttpRequestCompiler(@NonNull final String method, @NonNull final String url) { this.compiled = false; this.followRedirects = true; this.useCaches = true; this.connectTimeoutMs = CONNECT_TIMEOUT_MS; this.readTimeoutMs = READ_TIMEOUT_MS; this.url = url; this.method = checkNotNull(method); this.header = new HashMap<>(); this.body = EMPTY_BODY; } @NonNull @Override
public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile body(
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // }
import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map;
this.followRedirects = true; this.useCaches = true; this.connectTimeoutMs = CONNECT_TIMEOUT_MS; this.readTimeoutMs = READ_TIMEOUT_MS; this.url = url; this.method = checkNotNull(method); this.header = new HashMap<>(); this.body = EMPTY_BODY; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile body( @NonNull final byte[] body) { checkState(!compiled, ERROR_MESSAGE); this.body = checkNotNull(body); return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map; this.followRedirects = true; this.useCaches = true; this.connectTimeoutMs = CONNECT_TIMEOUT_MS; this.readTimeoutMs = READ_TIMEOUT_MS; this.url = url; this.method = checkNotNull(method); this.header = new HashMap<>(); this.body = EMPTY_BODY; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile body( @NonNull final byte[] body) { checkState(!compiled, ERROR_MESSAGE); this.body = checkNotNull(body); return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override
public HTConnectionTimeoutReadTimeoutCompile noCaches() {
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // }
import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map;
} @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile body( @NonNull final byte[] body) { checkState(!compiled, ERROR_MESSAGE); this.body = checkNotNull(body); return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile body( @NonNull final byte[] body) { checkState(!compiled, ERROR_MESSAGE); this.body = checkNotNull(body); return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override
public HTReadTimeoutCompile connectTimeoutMs(final int connectTimeoutMs) {
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // }
import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map;
return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override public HTReadTimeoutCompile connectTimeoutMs(final int connectTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.connectTimeoutMs = connectTimeoutMs; return this; } @NonNull @Override
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map; return this; } @NonNull @Override public HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( @NonNull final String name, @NonNull final String value) { checkState(!compiled, ERROR_MESSAGE); header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override public HTReadTimeoutCompile connectTimeoutMs(final int connectTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.connectTimeoutMs = connectTimeoutMs; return this; } @NonNull @Override
public HTCompile readTimeoutMs(final int readTimeoutMs) {
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // }
import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map;
header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override public HTReadTimeoutCompile connectTimeoutMs(final int connectTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.connectTimeoutMs = connectTimeoutMs; return this; } @NonNull @Override public HTCompile readTimeoutMs(final int readTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.readTimeoutMs = readTimeoutMs; return this; } @NonNull @Override
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCachesConnectionTimeoutReadTimeoutCompile // extends HTConnectionTimeoutReadTimeoutCompile { // // /** // * Turns off http caches. // */ // @NonNull // HTConnectionTimeoutReadTimeoutCompile noCaches(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTCompile { // // /** // * Compiles a {@link HttpRequest} that containing the previously specified data. // */ // @NonNull // HttpRequest compile(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTConnectionTimeoutReadTimeoutCompile extends HTReadTimeoutCompile { // // /** // * Sets a connection timeout in milliseconds. // */ // @NonNull // HTReadTimeoutCompile connectTimeoutMs(int connectionTimeoutMs); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTReadTimeoutCompile extends HTCompile { // // /** // * Sets a read timeout in milliseconds. // */ // @NonNull // HTCompile readTimeoutMs(int readTimeoutMs); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompiler.java import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTReadTimeoutCompile; import java.util.HashMap; import java.util.Map; header.put(name, value); return this; } @NonNull @Override public HTConnectionTimeoutReadTimeoutCompile noCaches() { checkState(!compiled, ERROR_MESSAGE); useCaches = false; return this; } @NonNull @Override public HTReadTimeoutCompile connectTimeoutMs(final int connectTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.connectTimeoutMs = connectTimeoutMs; return this; } @NonNull @Override public HTCompile readTimeoutMs(final int readTimeoutMs) { checkState(!compiled, ERROR_MESSAGE); this.readTimeoutMs = readTimeoutMs; return this; } @NonNull @Override
public HTCachesConnectionTimeoutReadTimeoutCompile noRedirects() {
google/agera
agera/src/main/java/com/google/android/agera/Repositories.java
// Path: agera/src/main/java/com/google/android/agera/RepositoryCompilerStates.java // interface REventSource<TVal, TStart> { // // /** // * Specifies the event source of the compiled repository. // */ // @NonNull // RFrequency<TVal, TStart> observe(@NonNull Observable... observables); // }
import static com.google.android.agera.Preconditions.checkNotNull; import android.os.Looper; import android.support.annotation.NonNull; import com.google.android.agera.RepositoryCompilerStates.REventSource;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Repository} instances. * * <p>Any {@link Repository} created by this class have to be created from a {@link Looper} thread * or they will throw an {@link IllegalStateException} */ public final class Repositories { /** * Returns a static {@link Repository} of the given {@code object}. */ @NonNull public static <T> Repository<T> repository(@NonNull final T object) { return new SimpleRepository<>(object); } /** * Starts the declaration of a compiled repository. See more at {@link RepositoryCompilerStates}. */ @NonNull
// Path: agera/src/main/java/com/google/android/agera/RepositoryCompilerStates.java // interface REventSource<TVal, TStart> { // // /** // * Specifies the event source of the compiled repository. // */ // @NonNull // RFrequency<TVal, TStart> observe(@NonNull Observable... observables); // } // Path: agera/src/main/java/com/google/android/agera/Repositories.java import static com.google.android.agera.Preconditions.checkNotNull; import android.os.Looper; import android.support.annotation.NonNull; import com.google.android.agera.RepositoryCompilerStates.REventSource; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Repository} instances. * * <p>Any {@link Repository} created by this class have to be created from a {@link Looper} thread * or they will throw an {@link IllegalStateException} */ public final class Repositories { /** * Returns a static {@link Repository} of the given {@code object}. */ @NonNull public static <T> Repository<T> repository(@NonNull final T object) { return new SimpleRepository<>(object); } /** * Starts the declaration of a compiled repository. See more at {@link RepositoryCompilerStates}. */ @NonNull
public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) {
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object();
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object();
private MockUpdatable updatable;
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable;
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable;
private SingleSlotDelayedExecutor executor;
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable; private SingleSlotDelayedExecutor executor; @Mock private Predicate<Object> mockPredicate; @Mock private Receiver<Object> mockDisposer; @Before public void setUp() { initMocks(this);
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryDisposerTest { private static final Object INITIAL_VALUE = new Object(); private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable; private SingleSlotDelayedExecutor executor; @Mock private Predicate<Object> mockPredicate; @Mock private Receiver<Object> mockDisposer; @Before public void setUp() { initMocks(this);
updatable = mockUpdatable();
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable; private SingleSlotDelayedExecutor executor; @Mock private Predicate<Object> mockPredicate; @Mock private Receiver<Object> mockDisposer; @Before public void setUp() { initMocks(this); updatable = mockUpdatable(); executor = new SingleSlotDelayedExecutor(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldNotDiscardInitialValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(falsePredicate()).orSkip()
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; private static final Object FIRST_VALUE = new Object(); private static final Object SECOND_VALUE = new Object(); private static final Object BREAK_VALUE = new Object(); private static final Object FINAL_VALUE = new Object(); private MockUpdatable updatable; private SingleSlotDelayedExecutor executor; @Mock private Predicate<Object> mockPredicate; @Mock private Receiver<Object> mockDisposer; @Before public void setUp() { initMocks(this); updatable = mockUpdatable(); executor = new SingleSlotDelayedExecutor(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldNotDiscardInitialValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(falsePredicate()).orSkip()
.thenGetFrom(staticSupplier(FINAL_VALUE))
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
updatable = mockUpdatable(); executor = new SingleSlotDelayedExecutor(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldNotDiscardInitialValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(falsePredicate()).orSkip() .thenGetFrom(staticSupplier(FINAL_VALUE)) .sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer, never()).accept(any()); } @Test public void shouldNotDiscardPublishedValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip()
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; updatable = mockUpdatable(); executor = new SingleSlotDelayedExecutor(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldNotDiscardInitialValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(falsePredicate()).orSkip() .thenGetFrom(staticSupplier(FINAL_VALUE)) .sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer, never()).accept(any()); } @Test public void shouldNotDiscardPublishedValue() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip()
.thenTransform(staticFunction(FINAL_VALUE))
google/agera
agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
.sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer).accept(FIRST_VALUE); } @Test public void shouldDiscardFirstValueDueToEndClause() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .getFrom(staticSupplier(FIRST_VALUE)) .check(falsePredicate()).orEnd(staticFunction(BREAK_VALUE)) .thenGetFrom(staticSupplier(FINAL_VALUE)) .sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer).accept(FIRST_VALUE); } @Test public void shouldDiscardSecondValueDueToSkipDirective() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .getFrom(staticSupplier(FIRST_VALUE))
// Path: agera/src/main/java/com/google/android/agera/Functions.java // @NonNull // public static <F, T> Function<F, T> staticFunction(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Suppliers.java // @NonNull // public static <T> Supplier<T> staticSupplier(@NonNull final T object) { // return new StaticProducer<>(object); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/SingleSlotDelayedExecutor.java // public final class SingleSlotDelayedExecutor implements Executor { // @Nullable // private Runnable runnable; // // @Override // public void execute(@NonNull final Runnable command) { // assertThat("delayedExecutor cannot queue more than one Runnable", runnable, is(nullValue())); // runnable = command; // } // // public boolean hasRunnable() { // return runnable != null; // } // // public void resumeOrThrow() { // final Runnable runnable = this.runnable; // assertThat("delayedExecutor should have queued a Runnable for resumeOrThrow()", // runnable, is(notNullValue())); // this.runnable = null; // //noinspection ConstantConditions // runnable.run(); // } // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryDisposerTest.java import static com.google.android.agera.Functions.staticFunction; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.RepositoryConfig.CANCEL_FLOW; import static com.google.android.agera.Suppliers.staticSupplier; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.SingleSlotDelayedExecutor; import com.google.android.agera.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; .sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer).accept(FIRST_VALUE); } @Test public void shouldDiscardFirstValueDueToEndClause() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .getFrom(staticSupplier(FIRST_VALUE)) .check(falsePredicate()).orEnd(staticFunction(BREAK_VALUE)) .thenGetFrom(staticSupplier(FINAL_VALUE)) .sendDiscardedValuesTo(mockDisposer) .compile(); updatable.addToObservable(repository); verify(mockDisposer).accept(FIRST_VALUE); } @Test public void shouldDiscardSecondValueDueToSkipDirective() { Repository<Object> repository = repositoryWithInitialValue(INITIAL_VALUE) .observe() .onUpdatesPerLoop() .getFrom(staticSupplier(FIRST_VALUE))
.check(truePredicate()).orEnd(staticFunction(BREAK_VALUE))
google/agera
agera/src/main/java/com/google/android/agera/Suppliers.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final class StaticProducer<TFirst, TSecond, TTo> // implements Supplier<TTo>, Function<TFirst, TTo>, Merger<TFirst, TSecond, TTo> { // @NonNull // private final TTo staticValue; // // StaticProducer(@NonNull final TTo staticValue) { // this.staticValue = checkNotNull(staticValue); // } // // @NonNull // @Override // public TTo apply(@NonNull final TFirst input) { // return staticValue; // } // // @NonNull // @Override // public TTo merge(@NonNull final TFirst o, @NonNull final TSecond o2) { // return staticValue; // } // // @NonNull // @Override // public TTo get() { // return staticValue; // } // }
import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; import com.google.android.agera.Common.StaticProducer;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Supplier} instances. */ public final class Suppliers { /** * Returns a {@link Supplier} that always supplies the given {@code object} when its * {@link Supplier#get()} is called. */ @NonNull public static <T> Supplier<T> staticSupplier(@NonNull final T object) {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final class StaticProducer<TFirst, TSecond, TTo> // implements Supplier<TTo>, Function<TFirst, TTo>, Merger<TFirst, TSecond, TTo> { // @NonNull // private final TTo staticValue; // // StaticProducer(@NonNull final TTo staticValue) { // this.staticValue = checkNotNull(staticValue); // } // // @NonNull // @Override // public TTo apply(@NonNull final TFirst input) { // return staticValue; // } // // @NonNull // @Override // public TTo merge(@NonNull final TFirst o, @NonNull final TSecond o2) { // return staticValue; // } // // @NonNull // @Override // public TTo get() { // return staticValue; // } // } // Path: agera/src/main/java/com/google/android/agera/Suppliers.java import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; import com.google.android.agera.Common.StaticProducer; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Supplier} instances. */ public final class Suppliers { /** * Returns a {@link Supplier} that always supplies the given {@code object} when its * {@link Supplier#get()} is called. */ @NonNull public static <T> Supplier<T> staticSupplier(@NonNull final T object) {
return new StaticProducer<>(object);
google/agera
extensions/database/src/test/java/com/google/android/agera/database/SqlRequestsTest.java
// Path: extensions/database/src/test/java/com/google/android/agera/database/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBArgumentCompile<T, TC> extends DBArgument<TC>, DBCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumn<T> { // // /** // * Adds a {@code column} with a {@link String} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable String value); // // /** // * Adds a {@code column} with a {@link Byte} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Byte value); // // /** // * Adds a {@code column} with a {@link Short} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Short value); // // /** // * Adds a {@code column} with a {@link Integer} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Integer value); // // /** // * Adds a {@code column} with a {@link Long} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Long value); // // /** // * Adds a {@code column} with a {@link Float} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Float value); // // /** // * Adds a {@code column} with a {@link Double} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Double value); // // /** // * Adds a {@code column} with a {@link Boolean} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Boolean value); // // /** // * Adds a {@code column} with a {@code byte} array {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable byte[] value); // // /** // * Adds an empty {@code column}. // */ // @NonNull // T emptyColumn(@NonNull String column); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumnConflictCompile<T, TSelf extends DBColumnConflictCompile<T, TSelf>> // extends DBColumn<TSelf>, DBConflictCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBCompile<T> { // // /** // * Compiles a sql request that containing the previously specified data. // */ // @NonNull // T compile(); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBSql<T> { // // /** // * Sets sql string. // */ // @NonNull // T sql(@NonNull String sql); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBTable<T> { // // /** // * Sets a table. // */ // @NonNull // T table(@NonNull String table); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBWhereCompile<T, TAc> extends DBWhere<TAc>, DBCompile<T> {}
import static com.google.android.agera.database.SqlRequests.sqlDeleteRequest; import static com.google.android.agera.database.SqlRequests.sqlInsertRequest; import static com.google.android.agera.database.SqlRequests.sqlRequest; import static com.google.android.agera.database.SqlRequests.sqlUpdateRequest; import static com.google.android.agera.database.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.database.SqlRequestCompilerStates.DBArgumentCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumn; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumnConflictCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBSql; import com.google.android.agera.database.SqlRequestCompilerStates.DBTable; import com.google.android.agera.database.SqlRequestCompilerStates.DBWhereCompile; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
.column("column", "value") .compile(); sqlInsertRequest2 = sqlInsertRequest() .table(TABLE_2) .column("column", "value") .compile(); } @Test public void shouldCreateStringRepresentationForRequest() { assertThat(sqlRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForDelete() { assertThat(sqlDeleteRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForInsert() { assertThat(sqlInsertRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForUpdate() { assertThat(sqlUpdateRequest, hasToString(not(isEmptyOrNullString()))); } @Test(expected = IllegalStateException.class) public void shouldThrowExceptionForReuseOfCompilerOfCompile() {
// Path: extensions/database/src/test/java/com/google/android/agera/database/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBArgumentCompile<T, TC> extends DBArgument<TC>, DBCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumn<T> { // // /** // * Adds a {@code column} with a {@link String} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable String value); // // /** // * Adds a {@code column} with a {@link Byte} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Byte value); // // /** // * Adds a {@code column} with a {@link Short} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Short value); // // /** // * Adds a {@code column} with a {@link Integer} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Integer value); // // /** // * Adds a {@code column} with a {@link Long} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Long value); // // /** // * Adds a {@code column} with a {@link Float} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Float value); // // /** // * Adds a {@code column} with a {@link Double} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Double value); // // /** // * Adds a {@code column} with a {@link Boolean} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Boolean value); // // /** // * Adds a {@code column} with a {@code byte} array {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable byte[] value); // // /** // * Adds an empty {@code column}. // */ // @NonNull // T emptyColumn(@NonNull String column); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumnConflictCompile<T, TSelf extends DBColumnConflictCompile<T, TSelf>> // extends DBColumn<TSelf>, DBConflictCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBCompile<T> { // // /** // * Compiles a sql request that containing the previously specified data. // */ // @NonNull // T compile(); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBSql<T> { // // /** // * Sets sql string. // */ // @NonNull // T sql(@NonNull String sql); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBTable<T> { // // /** // * Sets a table. // */ // @NonNull // T table(@NonNull String table); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBWhereCompile<T, TAc> extends DBWhere<TAc>, DBCompile<T> {} // Path: extensions/database/src/test/java/com/google/android/agera/database/SqlRequestsTest.java import static com.google.android.agera.database.SqlRequests.sqlDeleteRequest; import static com.google.android.agera.database.SqlRequests.sqlInsertRequest; import static com.google.android.agera.database.SqlRequests.sqlRequest; import static com.google.android.agera.database.SqlRequests.sqlUpdateRequest; import static com.google.android.agera.database.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.database.SqlRequestCompilerStates.DBArgumentCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumn; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumnConflictCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBSql; import com.google.android.agera.database.SqlRequestCompilerStates.DBTable; import com.google.android.agera.database.SqlRequestCompilerStates.DBWhereCompile; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; .column("column", "value") .compile(); sqlInsertRequest2 = sqlInsertRequest() .table(TABLE_2) .column("column", "value") .compile(); } @Test public void shouldCreateStringRepresentationForRequest() { assertThat(sqlRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForDelete() { assertThat(sqlDeleteRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForInsert() { assertThat(sqlInsertRequest, hasToString(not(isEmptyOrNullString()))); } @Test public void shouldCreateStringRepresentationForUpdate() { assertThat(sqlUpdateRequest, hasToString(not(isEmptyOrNullString()))); } @Test(expected = IllegalStateException.class) public void shouldThrowExceptionForReuseOfCompilerOfCompile() {
final DBColumnConflictCompile<SqlInsertRequest, ?> incompleteRequest =
google/agera
extensions/database/src/test/java/com/google/android/agera/database/SqlRequestsTest.java
// Path: extensions/database/src/test/java/com/google/android/agera/database/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBArgumentCompile<T, TC> extends DBArgument<TC>, DBCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumn<T> { // // /** // * Adds a {@code column} with a {@link String} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable String value); // // /** // * Adds a {@code column} with a {@link Byte} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Byte value); // // /** // * Adds a {@code column} with a {@link Short} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Short value); // // /** // * Adds a {@code column} with a {@link Integer} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Integer value); // // /** // * Adds a {@code column} with a {@link Long} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Long value); // // /** // * Adds a {@code column} with a {@link Float} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Float value); // // /** // * Adds a {@code column} with a {@link Double} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Double value); // // /** // * Adds a {@code column} with a {@link Boolean} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Boolean value); // // /** // * Adds a {@code column} with a {@code byte} array {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable byte[] value); // // /** // * Adds an empty {@code column}. // */ // @NonNull // T emptyColumn(@NonNull String column); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumnConflictCompile<T, TSelf extends DBColumnConflictCompile<T, TSelf>> // extends DBColumn<TSelf>, DBConflictCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBCompile<T> { // // /** // * Compiles a sql request that containing the previously specified data. // */ // @NonNull // T compile(); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBSql<T> { // // /** // * Sets sql string. // */ // @NonNull // T sql(@NonNull String sql); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBTable<T> { // // /** // * Sets a table. // */ // @NonNull // T table(@NonNull String table); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBWhereCompile<T, TAc> extends DBWhere<TAc>, DBCompile<T> {}
import static com.google.android.agera.database.SqlRequests.sqlDeleteRequest; import static com.google.android.agera.database.SqlRequests.sqlInsertRequest; import static com.google.android.agera.database.SqlRequests.sqlRequest; import static com.google.android.agera.database.SqlRequests.sqlUpdateRequest; import static com.google.android.agera.database.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.database.SqlRequestCompilerStates.DBArgumentCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumn; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumnConflictCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBSql; import com.google.android.agera.database.SqlRequestCompilerStates.DBTable; import com.google.android.agera.database.SqlRequestCompilerStates.DBWhereCompile; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
DBArgumentCompile<SqlDeleteRequest, DBCompile<SqlDeleteRequest>>> incompleteRequest = sqlDeleteRequest() .table(TABLE); incompleteRequest.where("column=a").compile(); incompleteRequest.where("column=a"); } @Test public void shouldVerifyEqualsForSqlRequest() { EqualsVerifier.forClass(SqlRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlDeleteRequest() { EqualsVerifier.forClass(SqlDeleteRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlUpdateRequest() { EqualsVerifier.forClass(SqlUpdateRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlInsertRequest() { EqualsVerifier.forClass(SqlInsertRequest.class).verify(); } @Test public void shouldHavePrivateConstructor() {
// Path: extensions/database/src/test/java/com/google/android/agera/database/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBArgumentCompile<T, TC> extends DBArgument<TC>, DBCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumn<T> { // // /** // * Adds a {@code column} with a {@link String} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable String value); // // /** // * Adds a {@code column} with a {@link Byte} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Byte value); // // /** // * Adds a {@code column} with a {@link Short} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Short value); // // /** // * Adds a {@code column} with a {@link Integer} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Integer value); // // /** // * Adds a {@code column} with a {@link Long} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Long value); // // /** // * Adds a {@code column} with a {@link Float} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Float value); // // /** // * Adds a {@code column} with a {@link Double} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Double value); // // /** // * Adds a {@code column} with a {@link Boolean} {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable Boolean value); // // /** // * Adds a {@code column} with a {@code byte} array {@code value}. // */ // @NonNull // T column(@NonNull String column, @Nullable byte[] value); // // /** // * Adds an empty {@code column}. // */ // @NonNull // T emptyColumn(@NonNull String column); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBColumnConflictCompile<T, TSelf extends DBColumnConflictCompile<T, TSelf>> // extends DBColumn<TSelf>, DBConflictCompile<T> {} // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBCompile<T> { // // /** // * Compiles a sql request that containing the previously specified data. // */ // @NonNull // T compile(); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBSql<T> { // // /** // * Sets sql string. // */ // @NonNull // T sql(@NonNull String sql); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBTable<T> { // // /** // * Sets a table. // */ // @NonNull // T table(@NonNull String table); // } // // Path: extensions/database/src/main/java/com/google/android/agera/database/SqlRequestCompilerStates.java // interface DBWhereCompile<T, TAc> extends DBWhere<TAc>, DBCompile<T> {} // Path: extensions/database/src/test/java/com/google/android/agera/database/SqlRequestsTest.java import static com.google.android.agera.database.SqlRequests.sqlDeleteRequest; import static com.google.android.agera.database.SqlRequests.sqlInsertRequest; import static com.google.android.agera.database.SqlRequests.sqlRequest; import static com.google.android.agera.database.SqlRequests.sqlUpdateRequest; import static com.google.android.agera.database.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.database.SqlRequestCompilerStates.DBArgumentCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumn; import com.google.android.agera.database.SqlRequestCompilerStates.DBColumnConflictCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBCompile; import com.google.android.agera.database.SqlRequestCompilerStates.DBSql; import com.google.android.agera.database.SqlRequestCompilerStates.DBTable; import com.google.android.agera.database.SqlRequestCompilerStates.DBWhereCompile; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; DBArgumentCompile<SqlDeleteRequest, DBCompile<SqlDeleteRequest>>> incompleteRequest = sqlDeleteRequest() .table(TABLE); incompleteRequest.where("column=a").compile(); incompleteRequest.where("column=a"); } @Test public void shouldVerifyEqualsForSqlRequest() { EqualsVerifier.forClass(SqlRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlDeleteRequest() { EqualsVerifier.forClass(SqlDeleteRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlUpdateRequest() { EqualsVerifier.forClass(SqlUpdateRequest.class).verify(); } @Test public void shouldVerifyEqualsForSqlInsertRequest() { EqualsVerifier.forClass(SqlInsertRequest.class).verify(); } @Test public void shouldHavePrivateConstructor() {
assertThat(SqlRequests.class, hasPrivateConstructor());
google/agera
agera/src/test/java/com/google/android/agera/ResultTest.java
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // }
import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2;
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // Path: agera/src/test/java/com/google/android/agera/ResultTest.java import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2;
private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE);
google/agera
agera/src/test/java/com/google/android/agera/ResultTest.java
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // }
import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE);
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // Path: agera/src/test/java/com/google/android/agera/ResultTest.java import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE);
private static final Result<Integer> FAILURE_WITH_THROWABLE = failure(THROWABLE);
google/agera
agera/src/test/java/com/google/android/agera/ResultTest.java
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // }
import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE); private static final Result<Integer> FAILURE_WITH_THROWABLE = failure(THROWABLE); private static final Result<Integer> FAILURE = failure();
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // Path: agera/src/test/java/com/google/android/agera/ResultTest.java import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE); private static final Result<Integer> FAILURE_WITH_THROWABLE = failure(THROWABLE); private static final Result<Integer> FAILURE = failure();
private static final Result<Integer> PRESENT_WITH_VALUE = present(VALUE);
google/agera
agera/src/test/java/com/google/android/agera/ResultTest.java
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // }
import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE); private static final Result<Integer> FAILURE_WITH_THROWABLE = failure(THROWABLE); private static final Result<Integer> FAILURE = failure(); private static final Result<Integer> PRESENT_WITH_VALUE = present(VALUE);
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // Path: agera/src/test/java/com/google/android/agera/ResultTest.java import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ResultTest { @SuppressWarnings("ThrowableInstanceNeverThrown") private static final Throwable THROWABLE = new Throwable(); private static final int VALUE = 42; private static final String STRING_VALUE = "stringvalue"; private static final int OTHER_VALUE = 1; private static final float FLOAT_VALUE = 2; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> SUCCESS_WITH_OTHER_VALUE = success(OTHER_VALUE); private static final Result<Float> SUCCESS_WITH_FLOAT_VALUE = success(FLOAT_VALUE); private static final Result<Integer> FAILURE_WITH_THROWABLE = failure(THROWABLE); private static final Result<Integer> FAILURE = failure(); private static final Result<Integer> PRESENT_WITH_VALUE = present(VALUE);
private static final Result<Integer> ABSENT = absent();
google/agera
agera/src/test/java/com/google/android/agera/ResultTest.java
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // }
import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock;
assertThat(ABSENT.isPresent(), equalTo(false)); } @Test public void shouldReturnTrueForIsPresentWithValue() { assertThat(PRESENT_WITH_VALUE.isPresent(), equalTo(true)); } @Test public void shouldReturnTrueForIsAbsentOfAbsent() { assertThat(ABSENT.isAbsent(), equalTo(true)); } @Test public void shouldReturnFalseForIsAbsentWithValue() { assertThat(PRESENT_WITH_VALUE.isAbsent(), equalTo(false)); } @Test public void shouldReturnFalseForIsAbsentOfNonAbsentFailure() { assertThat(FAILURE.isAbsent(), equalTo(false)); } @Test public void shouldReturnAbsentForFailureWithAbsentFailure() { assertThat(Result.<Integer>failure(ABSENT.getFailure()), sameInstance(ABSENT)); } @Test public void shouldReturnAbsentForOfNullableWithNull() {
// Path: agera/src/main/java/com/google/android/agera/Result.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Result<T> absent() { // return (Result<T>) ABSENT; // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> absentIfNull(@Nullable final T value) { // return value == null ? Result.<T>absent() : present(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> present(@NonNull final T value) { // return success(value); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // Path: agera/src/test/java/com/google/android/agera/ResultTest.java import static com.google.android.agera.Result.absent; import static com.google.android.agera.Result.absentIfNull; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.present; import static com.google.android.agera.Result.success; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; assertThat(ABSENT.isPresent(), equalTo(false)); } @Test public void shouldReturnTrueForIsPresentWithValue() { assertThat(PRESENT_WITH_VALUE.isPresent(), equalTo(true)); } @Test public void shouldReturnTrueForIsAbsentOfAbsent() { assertThat(ABSENT.isAbsent(), equalTo(true)); } @Test public void shouldReturnFalseForIsAbsentWithValue() { assertThat(PRESENT_WITH_VALUE.isAbsent(), equalTo(false)); } @Test public void shouldReturnFalseForIsAbsentOfNonAbsentFailure() { assertThat(FAILURE.isAbsent(), equalTo(false)); } @Test public void shouldReturnAbsentForFailureWithAbsentFailure() { assertThat(Result.<Integer>failure(ABSENT.getFailure()), sameInstance(ABSENT)); } @Test public void shouldReturnAbsentForOfNullableWithNull() {
assertThat(Result.<Integer>absentIfNull(null), sameInstance(ABSENT));
google/agera
agera/src/main/java/com/google/android/agera/Receivers.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator();
import static com.google.android.agera.Common.NULL_OPERATOR; import android.support.annotation.NonNull;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Receiver} instances. */ public final class Receivers { /** * Returns a {@link Receiver} that does nothing. */ @SuppressWarnings("unchecked") @NonNull public static <T> Receiver<T> nullReceiver() {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // Path: agera/src/main/java/com/google/android/agera/Receivers.java import static com.google.android.agera.Common.NULL_OPERATOR; import android.support.annotation.NonNull; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Receiver} instances. */ public final class Receivers { /** * Returns a {@link Receiver} that does nothing. */ @SuppressWarnings("unchecked") @NonNull public static <T> Receiver<T> nullReceiver() {
return NULL_OPERATOR;
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // }
import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = NONE) @SuppressWarnings("unchecked") public final class RepositoryAdapterFineGrainedEventsTest { private static final Object REPOSITORY_VALUE_A = new Object(); private static final Object REPOSITORY_VALUE_B = new Object(); private static final Object STATIC_ITEM = new Object(); private static final int PRESENTER_1_A_ITEM_COUNT = 1; private static final int PRESENTER_1_B_ITEM_COUNT = 3; private static final int STATIC_ITEM_COUNT = 2; private static final int PRESENTER_2_A_ITEM_COUNT = 4; private static final int PRESENTER_2_B_ITEM_COUNT = 5; private static final Object PAYLOAD_PRESENTER_1_VALUE_A_TO_B = new Object(); private static final Object PAYLOAD_PRESENTER_1_VALUE_B_REFRESH = new Object(); private static final Object PAYLOAD_PRESENTER_2_VALUE_B_REFRESH = new Object(); @Mock private RepositoryPresenter mockPresenter1; @Mock private RepositoryPresenter mockStaticItemPresenter; @Mock private RepositoryPresenter mockPresenter2; @Mock private ListUpdateCallback fineGrainedEvents; @Mock private Runnable onChangeEvent; private AdapterDataObserver redirectingObserver;
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = NONE) @SuppressWarnings("unchecked") public final class RepositoryAdapterFineGrainedEventsTest { private static final Object REPOSITORY_VALUE_A = new Object(); private static final Object REPOSITORY_VALUE_B = new Object(); private static final Object STATIC_ITEM = new Object(); private static final int PRESENTER_1_A_ITEM_COUNT = 1; private static final int PRESENTER_1_B_ITEM_COUNT = 3; private static final int STATIC_ITEM_COUNT = 2; private static final int PRESENTER_2_A_ITEM_COUNT = 4; private static final int PRESENTER_2_B_ITEM_COUNT = 5; private static final Object PAYLOAD_PRESENTER_1_VALUE_A_TO_B = new Object(); private static final Object PAYLOAD_PRESENTER_1_VALUE_B_REFRESH = new Object(); private static final Object PAYLOAD_PRESENTER_2_VALUE_B_REFRESH = new Object(); @Mock private RepositoryPresenter mockPresenter1; @Mock private RepositoryPresenter mockStaticItemPresenter; @Mock private RepositoryPresenter mockPresenter2; @Mock private ListUpdateCallback fineGrainedEvents; @Mock private Runnable onChangeEvent; private AdapterDataObserver redirectingObserver;
private UpdateDispatcher updateDispatcher;
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // }
import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = NONE) @SuppressWarnings("unchecked") public final class RepositoryAdapterFineGrainedEventsTest { private static final Object REPOSITORY_VALUE_A = new Object(); private static final Object REPOSITORY_VALUE_B = new Object(); private static final Object STATIC_ITEM = new Object(); private static final int PRESENTER_1_A_ITEM_COUNT = 1; private static final int PRESENTER_1_B_ITEM_COUNT = 3; private static final int STATIC_ITEM_COUNT = 2; private static final int PRESENTER_2_A_ITEM_COUNT = 4; private static final int PRESENTER_2_B_ITEM_COUNT = 5; private static final Object PAYLOAD_PRESENTER_1_VALUE_A_TO_B = new Object(); private static final Object PAYLOAD_PRESENTER_1_VALUE_B_REFRESH = new Object(); private static final Object PAYLOAD_PRESENTER_2_VALUE_B_REFRESH = new Object(); @Mock private RepositoryPresenter mockPresenter1; @Mock private RepositoryPresenter mockStaticItemPresenter; @Mock private RepositoryPresenter mockPresenter2; @Mock private ListUpdateCallback fineGrainedEvents; @Mock private Runnable onChangeEvent; private AdapterDataObserver redirectingObserver; private UpdateDispatcher updateDispatcher; private MutableRepository repository1; private MutableRepository repository2;
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.rvadapter; @RunWith(RobolectricTestRunner.class) @Config(manifest = NONE) @SuppressWarnings("unchecked") public final class RepositoryAdapterFineGrainedEventsTest { private static final Object REPOSITORY_VALUE_A = new Object(); private static final Object REPOSITORY_VALUE_B = new Object(); private static final Object STATIC_ITEM = new Object(); private static final int PRESENTER_1_A_ITEM_COUNT = 1; private static final int PRESENTER_1_B_ITEM_COUNT = 3; private static final int STATIC_ITEM_COUNT = 2; private static final int PRESENTER_2_A_ITEM_COUNT = 4; private static final int PRESENTER_2_B_ITEM_COUNT = 5; private static final Object PAYLOAD_PRESENTER_1_VALUE_A_TO_B = new Object(); private static final Object PAYLOAD_PRESENTER_1_VALUE_B_REFRESH = new Object(); private static final Object PAYLOAD_PRESENTER_2_VALUE_B_REFRESH = new Object(); @Mock private RepositoryPresenter mockPresenter1; @Mock private RepositoryPresenter mockStaticItemPresenter; @Mock private RepositoryPresenter mockPresenter2; @Mock private ListUpdateCallback fineGrainedEvents; @Mock private Runnable onChangeEvent; private AdapterDataObserver redirectingObserver; private UpdateDispatcher updateDispatcher; private MutableRepository repository1; private MutableRepository repository2;
private RepositoryAdapter repositoryAdapter;
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // }
import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
@Override public void onItemRangeChanged(final int positionStart, final int itemCount) { fineGrainedEvents.onChanged(positionStart, itemCount, null); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final Object payload) { fineGrainedEvents.onChanged(positionStart, itemCount, payload); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { fineGrainedEvents.onInserted(positionStart, itemCount); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { fineGrainedEvents.onRemoved(positionStart, itemCount); } @Override public void onItemRangeMoved(final int fromPosition, final int toPosition, final int itemCount) { assertThat(itemCount, is(1)); fineGrainedEvents.onMoved(fromPosition, toPosition); } }; updateDispatcher = updateDispatcher();
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Override public void onItemRangeChanged(final int positionStart, final int itemCount) { fineGrainedEvents.onChanged(positionStart, itemCount, null); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final Object payload) { fineGrainedEvents.onChanged(positionStart, itemCount, payload); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { fineGrainedEvents.onInserted(positionStart, itemCount); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { fineGrainedEvents.onRemoved(positionStart, itemCount); } @Override public void onItemRangeMoved(final int fromPosition, final int toPosition, final int itemCount) { assertThat(itemCount, is(1)); fineGrainedEvents.onMoved(fromPosition, toPosition); } }; updateDispatcher = updateDispatcher();
repository1 = mutableRepository(REPOSITORY_VALUE_A);
google/agera
extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // }
import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
repository2.accept(REPOSITORY_VALUE_B); runUiThreadTasksIncludingDelayedTasks(); verify(mockPresenter1, never()).getItemCount(any()); final int itemCount = repositoryAdapter.getItemCount(); verify(mockPresenter2, never()).getItemCount(REPOSITORY_VALUE_A); verify(mockPresenter2).getItemCount(REPOSITORY_VALUE_B); assertThat(itemCount, is( PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_B_ITEM_COUNT)); assertThat(repositoryAdapter.getItemId(PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + 4), is(100L + STATIC_ITEM_COUNT)); verify(mockPresenter2, never()).getUpdates(any(), any(), any(ListUpdateCallback.class)); } @Test public void shouldApplyPresenter1ChangesWithEventsWhenObserved() { repositoryAdapter.getItemCount(); // usage when(mockPresenter1.getItemId(REPOSITORY_VALUE_B, 2)).thenReturn(10L); repository1.accept(REPOSITORY_VALUE_B); runUiThreadTasksIncludingDelayedTasks(); assertThat(repositoryAdapter.getItemCount(), is( PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_A_ITEM_COUNT)); assertThat(repositoryAdapter.getItemId(2), is(10L + STATIC_ITEM_COUNT)); verify(mockPresenter1).getUpdates(eq(REPOSITORY_VALUE_A), eq(REPOSITORY_VALUE_B), any(ListUpdateCallback.class));
// Path: agera/src/main/java/com/google/android/agera/Observables.java // @NonNull // public static UpdateDispatcher updateDispatcher() { // return new AsyncUpdateDispatcher(null); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: extensions/rvadapter/src/main/java/com/google/android/agera/rvadapter/RepositoryAdapter.java // @NonNull // public static Builder repositoryAdapter() { // return new Builder(); // } // // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/test/VerifyingWrappers.java // @NonNull // public static ListUpdateCallback verifyingWrapper( // @NonNull final ListUpdateCallback mockCallback) { // // 'verify()' turns only the next method call on that mock to a verification call, so using // // this wrapper to insert 'verify()' for each call when verifying the diff results. // return new ListUpdateCallback() { // @Override // public void onInserted(final int position, final int count) { // verify(mockCallback).onInserted(position, count); // } // // @Override // public void onRemoved(final int position, final int count) { // verify(mockCallback).onRemoved(position, count); // } // // @Override // public void onMoved(final int fromPosition, final int toPosition) { // verify(mockCallback).onMoved(fromPosition, toPosition); // } // // @Override // public void onChanged(final int position, final int count, final Object payload) { // verify(mockCallback).onChanged(position, count, payload); // } // }; // } // Path: extensions/rvadapter/src/test/java/com/google/android/agera/rvadapter/RepositoryAdapterFineGrainedEventsTest.java import static com.google.android.agera.Observables.updateDispatcher; import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.rvadapter.RepositoryAdapter.repositoryAdapter; import static com.google.android.agera.rvadapter.test.VerifyingWrappers.verifyingWrapper; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isOneOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import static org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks; import android.support.annotation.NonNull; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView.AdapterDataObserver; import com.google.android.agera.MutableRepository; import com.google.android.agera.UpdateDispatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; repository2.accept(REPOSITORY_VALUE_B); runUiThreadTasksIncludingDelayedTasks(); verify(mockPresenter1, never()).getItemCount(any()); final int itemCount = repositoryAdapter.getItemCount(); verify(mockPresenter2, never()).getItemCount(REPOSITORY_VALUE_A); verify(mockPresenter2).getItemCount(REPOSITORY_VALUE_B); assertThat(itemCount, is( PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_B_ITEM_COUNT)); assertThat(repositoryAdapter.getItemId(PRESENTER_1_A_ITEM_COUNT + STATIC_ITEM_COUNT + 4), is(100L + STATIC_ITEM_COUNT)); verify(mockPresenter2, never()).getUpdates(any(), any(), any(ListUpdateCallback.class)); } @Test public void shouldApplyPresenter1ChangesWithEventsWhenObserved() { repositoryAdapter.getItemCount(); // usage when(mockPresenter1.getItemId(REPOSITORY_VALUE_B, 2)).thenReturn(10L); repository1.accept(REPOSITORY_VALUE_B); runUiThreadTasksIncludingDelayedTasks(); assertThat(repositoryAdapter.getItemCount(), is( PRESENTER_1_B_ITEM_COUNT + STATIC_ITEM_COUNT + PRESENTER_2_A_ITEM_COUNT)); assertThat(repositoryAdapter.getItemId(2), is(10L + STATIC_ITEM_COUNT)); verify(mockPresenter1).getUpdates(eq(REPOSITORY_VALUE_A), eq(REPOSITORY_VALUE_B), any(ListUpdateCallback.class));
applyPresenter1FromAToBChanges(verifyingWrapper(fineGrainedEvents));
google/agera
extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // }
import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION";
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // } // Path: extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION";
private MockUpdatable updatable;
google/agera
extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // }
import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // } // Path: extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock
private ActivationHandler mockActivationHandler;
google/agera
extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // }
import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock private ActivationHandler mockActivationHandler; @Mock private SharedPreferences sharedPreferences; @Before public void setUp() { initMocks(this); sharedPreferenceListenerCaptor = ArgumentCaptor.forClass(OnSharedPreferenceChangeListener.class); doNothing().when(sharedPreferences).registerOnSharedPreferenceChangeListener( sharedPreferenceListenerCaptor.capture());
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // } // Path: extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.content; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class ContentObservablesTest { private static final String TEST_KEY = "test key"; private static final String NOT_TEST_KEY = "not test key"; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock private ActivationHandler mockActivationHandler; @Mock private SharedPreferences sharedPreferences; @Before public void setUp() { initMocks(this); sharedPreferenceListenerCaptor = ArgumentCaptor.forClass(OnSharedPreferenceChangeListener.class); doNothing().when(sharedPreferences).registerOnSharedPreferenceChangeListener( sharedPreferenceListenerCaptor.capture());
updatable = mockUpdatable();
google/agera
extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // }
import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config;
private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock private ActivationHandler mockActivationHandler; @Mock private SharedPreferences sharedPreferences; @Before public void setUp() { initMocks(this); sharedPreferenceListenerCaptor = ArgumentCaptor.forClass(OnSharedPreferenceChangeListener.class); doNothing().when(sharedPreferences).registerOnSharedPreferenceChangeListener( sharedPreferenceListenerCaptor.capture()); updatable = mockUpdatable(); secondUpdatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); secondUpdatable.removeFromObservables(); } @Test public void shouldUpdateSharedPreferencesWhenKeyChanges() {
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // } // Path: extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; private static final String TEST_ACTION = "TEST_ACTION"; private static final String PRIMARY_ACTION = "PRIMARY_ACTION"; private MockUpdatable updatable; private MockUpdatable secondUpdatable; private ArgumentCaptor<OnSharedPreferenceChangeListener> sharedPreferenceListenerCaptor; @Mock private ActivationHandler mockActivationHandler; @Mock private SharedPreferences sharedPreferences; @Before public void setUp() { initMocks(this); sharedPreferenceListenerCaptor = ArgumentCaptor.forClass(OnSharedPreferenceChangeListener.class); doNothing().when(sharedPreferences).registerOnSharedPreferenceChangeListener( sharedPreferenceListenerCaptor.capture()); updatable = mockUpdatable(); secondUpdatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); secondUpdatable.removeFromObservables(); } @Test public void shouldUpdateSharedPreferencesWhenKeyChanges() {
updatable.addToObservable(sharedPreferencesObservable(sharedPreferences, TEST_KEY));
google/agera
extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // }
import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config;
} @After public void tearDown() { updatable.removeFromObservables(); secondUpdatable.removeFromObservables(); } @Test public void shouldUpdateSharedPreferencesWhenKeyChanges() { updatable.addToObservable(sharedPreferencesObservable(sharedPreferences, TEST_KEY)); sharedPreferenceListenerCaptor.getValue() .onSharedPreferenceChanged(sharedPreferences, TEST_KEY); assertThat(updatable, wasUpdated()); } @Test public void shouldNotUpdateSharedPreferencesWhenOtherKeyChanges() { updatable.addToObservable(sharedPreferencesObservable(sharedPreferences, TEST_KEY)); sharedPreferenceListenerCaptor.getValue() .onSharedPreferenceChanged(sharedPreferences, NOT_TEST_KEY); assertThat(updatable, UpdatableUpdated.wasNotUpdated()); } @Test public void shouldBeAbleToObserveBroadcasts() {
// Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable broadcastObservable(@NonNull final Context context, // @NonNull final String... actions) { // return new BroadcastObservable(context, actions); // } // // Path: extensions/content/src/main/java/com/google/android/agera/content/ContentObservables.java // @NonNull // public static Observable sharedPreferencesObservable(@NonNull final SharedPreferences preferences, // @NonNull final String... keys) { // return new SharedPreferencesObservable(preferences, keys); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/main/java/com/google/android/agera/ActivationHandler.java // public interface ActivationHandler { // // /** // * Called when the the {@code caller} changes state from having no {@link Updatable}s to // * having at least one {@link Updatable}. // */ // void observableActivated(@NonNull UpdateDispatcher caller); // // /** // * Called when the the {@code caller} changes state from having {@link Updatable}s to // * no longer having {@link Updatable}s. // */ // void observableDeactivated(@NonNull UpdateDispatcher caller); // } // // Path: extensions/content/src/test/java/com/google/android/agera/content/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables = new ArrayList<>(); // // private boolean updated = false; // // private MockUpdatable() {} // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // runUiThreadTasksIncludingDelayedTasks(); // } // } // Path: extensions/content/src/test/java/com/google/android/agera/content/ContentObservablesTest.java import static com.google.android.agera.content.ContentObservables.broadcastObservable; import static com.google.android.agera.content.ContentObservables.sharedPreferencesObservable; import static com.google.android.agera.content.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.content.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.content.test.mocks.MockUpdatable.mockUpdatable; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import android.app.Application; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import com.google.android.agera.ActivationHandler; import com.google.android.agera.content.test.matchers.UpdatableUpdated; import com.google.android.agera.content.test.mocks.MockUpdatable; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; } @After public void tearDown() { updatable.removeFromObservables(); secondUpdatable.removeFromObservables(); } @Test public void shouldUpdateSharedPreferencesWhenKeyChanges() { updatable.addToObservable(sharedPreferencesObservable(sharedPreferences, TEST_KEY)); sharedPreferenceListenerCaptor.getValue() .onSharedPreferenceChanged(sharedPreferences, TEST_KEY); assertThat(updatable, wasUpdated()); } @Test public void shouldNotUpdateSharedPreferencesWhenOtherKeyChanges() { updatable.addToObservable(sharedPreferencesObservable(sharedPreferences, TEST_KEY)); sharedPreferenceListenerCaptor.getValue() .onSharedPreferenceChanged(sharedPreferences, NOT_TEST_KEY); assertThat(updatable, UpdatableUpdated.wasNotUpdated()); } @Test public void shouldBeAbleToObserveBroadcasts() {
updatable.addToObservable(broadcastObservable(getApplication(), TEST_ACTION));
google/agera
agera/src/main/java/com/google/android/agera/Predicates.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true);
import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Predicate} instances. */ public final class Predicates { private static final Predicate<CharSequence> EMPTY_STRING_PREDICATE = new EmptyStringPredicate(); /** * Returns a {@link Predicate} from a {@link Condition}. * * <p>When applied the {@link Predicate} input parameter will be ignored and the result of * {@code condition} will be returned. */ @NonNull public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // Path: agera/src/main/java/com/google/android/agera/Predicates.java import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Predicate} instances. */ public final class Predicates { private static final Predicate<CharSequence> EMPTY_STRING_PREDICATE = new EmptyStringPredicate(); /** * Returns a {@link Predicate} from a {@link Condition}. * * <p>When applied the {@link Predicate} input parameter will be ignored and the result of * {@code condition} will be returned. */ @NonNull public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) {
if (condition == TRUE_CONDICATE) {
google/agera
agera/src/main/java/com/google/android/agera/Predicates.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true);
import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Predicate} instances. */ public final class Predicates { private static final Predicate<CharSequence> EMPTY_STRING_PREDICATE = new EmptyStringPredicate(); /** * Returns a {@link Predicate} from a {@link Condition}. * * <p>When applied the {@link Predicate} input parameter will be ignored and the result of * {@code condition} will be returned. */ @NonNull public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { if (condition == TRUE_CONDICATE) { return truePredicate(); }
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // Path: agera/src/main/java/com/google/android/agera/Predicates.java import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Predicate} instances. */ public final class Predicates { private static final Predicate<CharSequence> EMPTY_STRING_PREDICATE = new EmptyStringPredicate(); /** * Returns a {@link Predicate} from a {@link Condition}. * * <p>When applied the {@link Predicate} input parameter will be ignored and the result of * {@code condition} will be returned. */ @NonNull public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { if (condition == TRUE_CONDICATE) { return truePredicate(); }
if (condition == FALSE_CONDICATE) {
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // }
import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; /** * Creates instances of {@link HttpRequest}. */ public final class HttpRequests { /** * Starts the creation of a GET {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked")
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; /** * Creates instances of {@link HttpRequest}. */ public final class HttpRequests { /** * Starts the creation of a GET {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked")
public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile
google/agera
extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // }
import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; /** * Creates instances of {@link HttpRequest}. */ public final class HttpRequests { /** * Starts the creation of a GET {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked") public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile httpGetRequest(@NonNull final String url) { return new HttpRequestCompiler("GET", url); } /** * Starts the creation of a PUT {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked")
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTBody, HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile {} // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequestCompilerStates.java // interface HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // extends HTCachesConnectionTimeoutReadTimeoutCompile { // // /** // * Adds a header field to the {@link HttpRequest}. // */ // @NonNull // HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile headerField( // @NonNull String name, @NonNull String value); // // // /** // * Turns off follow redirects. // */ // @NonNull // HTCachesConnectionTimeoutReadTimeoutCompile noRedirects(); // } // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java import android.support.annotation.NonNull; import com.google.android.agera.net.HttpRequestCompilerStates.HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; import com.google.android.agera.net.HttpRequestCompilerStates.HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; /** * Creates instances of {@link HttpRequest}. */ public final class HttpRequests { /** * Starts the creation of a GET {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked") public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile httpGetRequest(@NonNull final String url) { return new HttpRequestCompiler("GET", url); } /** * Starts the creation of a PUT {@link HttpRequest}. */ @NonNull @SuppressWarnings("unchecked")
public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this);
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this);
when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true);
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() {
assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() { assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate())); } @Test public void shouldReturnFalsePredicateForFalseConditionInConditionAsPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() { assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate())); } @Test public void shouldReturnFalsePredicateForFalseConditionInConditionAsPredicate() {
assertThat(conditionAsPredicate(falseCondition()), sameInstance(falsePredicate()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() { assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate())); } @Test public void shouldReturnFalsePredicateForFalseConditionInConditionAsPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PredicatesTest { private static final String ITEM = "item"; private static final String OTHER_ITEM = "otheritem"; @Mock private Predicate<Object> mockPredicateFalse; @Mock private Predicate<Object> mockPredicateTrue; @Mock private Condition mockCondition; @Before public void setUp() { initMocks(this); when(mockPredicateTrue.apply(Mockito.any())).thenReturn(true); } @Test public void shouldReturnTruePredicateForTrueConditionInConditionAsPredicate() { assertThat(conditionAsPredicate(trueCondition()), sameInstance(truePredicate())); } @Test public void shouldReturnFalsePredicateForFalseConditionInConditionAsPredicate() {
assertThat(conditionAsPredicate(falseCondition()), sameInstance(falsePredicate()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
assertThat(not(truePredicate()), sameInstance(falsePredicate())); } @Test public void shouldNegateFalsePredicate() { assertThat(not(falsePredicate()), sameInstance(truePredicate())); } @Test public void shouldNegateNonStaticFalseCondition() { assertThat(not(mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldNegateNonStaticTrueCondition() { assertThat(not(mockPredicateTrue), doesNotApplyFor(new Object())); } @Test public void shouldNegatePredicateTwice() { assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; assertThat(not(truePredicate()), sameInstance(falsePredicate())); } @Test public void shouldNegateFalsePredicate() { assertThat(not(falsePredicate()), sameInstance(truePredicate())); } @Test public void shouldNegateNonStaticFalseCondition() { assertThat(not(mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldNegateNonStaticTrueCondition() { assertThat(not(mockPredicateTrue), doesNotApplyFor(new Object())); } @Test public void shouldNegatePredicateTwice() { assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() {
assertThat(emptyString(), appliesFor(""));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
assertThat(not(mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldNegateNonStaticTrueCondition() { assertThat(not(mockPredicateTrue), doesNotApplyFor(new Object())); } @Test public void shouldNegatePredicateTwice() { assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() { assertThat(emptyString(), appliesFor("")); } @Test public void shouldReturnFalseForStringInEmptyStringPredicate() { assertThat(emptyString(), doesNotApplyFor("A")); } @Test public void shouldReturnFalseForIncorrectInstanceInInstanceOfPredicate() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; assertThat(not(mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldNegateNonStaticTrueCondition() { assertThat(not(mockPredicateTrue), doesNotApplyFor(new Object())); } @Test public void shouldNegatePredicateTwice() { assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() { assertThat(emptyString(), appliesFor("")); } @Test public void shouldReturnFalseForStringInEmptyStringPredicate() { assertThat(emptyString(), doesNotApplyFor("A")); } @Test public void shouldReturnFalseForIncorrectInstanceInInstanceOfPredicate() {
assertThat(instanceOf(Integer.class), doesNotApplyFor(1L));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() { assertThat(emptyString(), appliesFor("")); } @Test public void shouldReturnFalseForStringInEmptyStringPredicate() { assertThat(emptyString(), doesNotApplyFor("A")); } @Test public void shouldReturnFalseForIncorrectInstanceInInstanceOfPredicate() { assertThat(instanceOf(Integer.class), doesNotApplyFor(1L)); } @Test public void shouldReturnTrueForCorrectInstanceInInstanceOfPredicate() { assertThat(instanceOf(Long.class), appliesFor(1L)); } @Test public void shouldReturnTrueForAllWithNoConditions() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; assertThat(not(not(truePredicate())), appliesFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfNegatedTwice() { assertThat(not(not(mockPredicateFalse)), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForEmptyStringInEmptyStringPredicate() { assertThat(emptyString(), appliesFor("")); } @Test public void shouldReturnFalseForStringInEmptyStringPredicate() { assertThat(emptyString(), doesNotApplyFor("A")); } @Test public void shouldReturnFalseForIncorrectInstanceInInstanceOfPredicate() { assertThat(instanceOf(Integer.class), doesNotApplyFor(1L)); } @Test public void shouldReturnTrueForCorrectInstanceInInstanceOfPredicate() { assertThat(instanceOf(Long.class), appliesFor(1L)); } @Test public void shouldReturnTrueForAllWithNoConditions() {
assertThat(all(), appliesFor(new Object()));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
assertThat(all(truePredicate(), truePredicate()), appliesFor(new Object())); } @Test public void shouldReturnFalseForAllWithOneFalseCondition() { assertThat(all(truePredicate(), falsePredicate()), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNoConditions() { assertThat(any(), doesNotApplyFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfAnyOfOne() { assertThat(any(mockPredicateFalse), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForAnyWithOneTrueCondition() { assertThat(any(truePredicate(), falsePredicate()), appliesFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNoTrueCondition() { assertThat(any(falsePredicate(), falsePredicate()), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForEqualToWhenNotEqual() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; assertThat(all(truePredicate(), truePredicate()), appliesFor(new Object())); } @Test public void shouldReturnFalseForAllWithOneFalseCondition() { assertThat(all(truePredicate(), falsePredicate()), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNoConditions() { assertThat(any(), doesNotApplyFor(new Object())); } @Test public void shouldReturnOriginalPredicateIfAnyOfOne() { assertThat(any(mockPredicateFalse), is(sameInstance(mockPredicateFalse))); } @Test public void shouldReturnTrueForAnyWithOneTrueCondition() { assertThat(any(truePredicate(), falsePredicate()), appliesFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNoTrueCondition() { assertThat(any(falsePredicate(), falsePredicate()), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForEqualToWhenNotEqual() {
assertThat(equalTo(ITEM), doesNotApplyFor(OTHER_ITEM));
google/agera
agera/src/test/java/com/google/android/agera/PredicatesTest.java
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito;
public void shouldReturnTrueForEqualToWhenEqual() { assertThat(equalTo(ITEM), appliesFor(ITEM)); } public void shouldReturnTrueForAnyWithNonStaticOneTrueCondition() { assertThat(any(mockPredicateTrue, mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNonStaticNoTrueCondition() { assertThat(any(mockPredicateFalse, mockPredicateFalse), doesNotApplyFor(new Object())); } @Test public void shouldReturnTrueForAllWithNonStaticTrueConditions() { assertThat(all(mockPredicateTrue, mockPredicateTrue), appliesFor(new Object())); } @Test public void shouldReturnFalseForAllWithNonStaticOneFalseCondition() { assertThat(all(mockPredicateTrue, mockPredicateFalse), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForAllWithNonStaticOneStaticFalseCondition() { assertThat(all(mockPredicateTrue, falsePredicate()), sameInstance(falsePredicate())); } @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition falseCondition() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Conditions.java // @NonNull // public static Condition trueCondition() { // return TRUE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SafeVarargs // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> all(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, truePredicate(), falsePredicate(), false); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @SuppressWarnings("unchecked") // @SafeVarargs // @NonNull // public static <T> Predicate<T> any(@NonNull final Predicate<? super T>... predicates) { // return composite(predicates, falsePredicate(), truePredicate(), true); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> conditionAsPredicate(@NonNull final Condition condition) { // if (condition == TRUE_CONDICATE) { // return truePredicate(); // } // if (condition == FALSE_CONDICATE) { // return falsePredicate(); // } // return new ConditionAsPredicate<>(condition); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static Predicate<CharSequence> emptyString() { // return EMPTY_STRING_PREDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> equalTo(@NonNull final T object) { // return new EqualToPredicate<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> falsePredicate() { // return FALSE_CONDICATE; // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> instanceOf(@NonNull final Class<?> type) { // return new InstanceOfPredicate<>(type); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // public static <T> Predicate<T> not(@NonNull final Predicate<T> predicate) { // if (predicate instanceof NegatedPredicate) { // return ((NegatedPredicate<T>) predicate).predicate; // } // if (predicate == truePredicate()) { // return falsePredicate(); // } // if (predicate == falsePredicate()) { // return truePredicate(); // } // return new NegatedPredicate<>(predicate); // } // // Path: agera/src/main/java/com/google/android/agera/Predicates.java // @NonNull // @SuppressWarnings("unchecked") // public static <T> Predicate<T> truePredicate() { // return TRUE_CONDICATE; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PredicatesTest.java import static com.google.android.agera.Conditions.falseCondition; import static com.google.android.agera.Conditions.trueCondition; import static com.google.android.agera.Predicates.all; import static com.google.android.agera.Predicates.any; import static com.google.android.agera.Predicates.conditionAsPredicate; import static com.google.android.agera.Predicates.emptyString; import static com.google.android.agera.Predicates.equalTo; import static com.google.android.agera.Predicates.falsePredicate; import static com.google.android.agera.Predicates.instanceOf; import static com.google.android.agera.Predicates.not; import static com.google.android.agera.Predicates.truePredicate; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static com.google.android.agera.test.matchers.PredicateApply.appliesFor; import static com.google.android.agera.test.matchers.PredicateApply.doesNotApplyFor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; public void shouldReturnTrueForEqualToWhenEqual() { assertThat(equalTo(ITEM), appliesFor(ITEM)); } public void shouldReturnTrueForAnyWithNonStaticOneTrueCondition() { assertThat(any(mockPredicateTrue, mockPredicateFalse), appliesFor(new Object())); } @Test public void shouldReturnFalseForAnyWithNonStaticNoTrueCondition() { assertThat(any(mockPredicateFalse, mockPredicateFalse), doesNotApplyFor(new Object())); } @Test public void shouldReturnTrueForAllWithNonStaticTrueConditions() { assertThat(all(mockPredicateTrue, mockPredicateTrue), appliesFor(new Object())); } @Test public void shouldReturnFalseForAllWithNonStaticOneFalseCondition() { assertThat(all(mockPredicateTrue, mockPredicateFalse), doesNotApplyFor(new Object())); } @Test public void shouldReturnFalseForAllWithNonStaticOneStaticFalseCondition() { assertThat(all(mockPredicateTrue, falsePredicate()), sameInstance(falsePredicate())); } @Test public void shouldHavePrivateConstructor() {
assertThat(Predicates.class, hasPrivateConstructor());
google/agera
agera/src/test/java/com/google/android/agera/PreconditionsTest.java
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Preconditions.checkArgument; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PreconditionsTest { @Test(expected = IllegalStateException.class) public void shouldThrowIllegalStateExceptionForCheckStateWithFalseExpression() { checkState(false, ""); } @Test public void shouldNotThrowExceptionForCheckStateWithTrueExpression() { checkState(true, ""); } @Test public void shouldNotThrowExceptionForCheckArgumentWithTrueExpression() { checkArgument(true, ""); } @Test(expected = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionForCheckArgumentWithFalseExpression() { checkArgument(false, ""); } @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionForCheckNotNullWithNull() { checkNotNull(null); } @Test public void shouldNotThrowExceptionForCheckNotNullWithValidObject() { checkNotNull(new Object()); } @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/PreconditionsTest.java import static com.google.android.agera.Preconditions.checkArgument; import static com.google.android.agera.Preconditions.checkNotNull; import static com.google.android.agera.Preconditions.checkState; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class PreconditionsTest { @Test(expected = IllegalStateException.class) public void shouldThrowIllegalStateExceptionForCheckStateWithFalseExpression() { checkState(false, ""); } @Test public void shouldNotThrowExceptionForCheckStateWithTrueExpression() { checkState(true, ""); } @Test public void shouldNotThrowExceptionForCheckArgumentWithTrueExpression() { checkArgument(true, ""); } @Test(expected = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionForCheckArgumentWithFalseExpression() { checkArgument(false, ""); } @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionForCheckNotNullWithNull() { checkNotNull(null); } @Test public void shouldNotThrowExceptionForCheckNotNullWithValidObject() { checkNotNull(new Object()); } @Test public void shouldHavePrivateConstructor() {
assertThat(Preconditions.class, hasPrivateConstructor());
google/agera
agera/src/main/java/com/google/android/agera/Conditions.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true);
import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Condition} instances. */ public final class Conditions { /** * Returns a {@link Condition} that always returns {@code true}. */ @NonNull public static Condition trueCondition() {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // Path: agera/src/main/java/com/google/android/agera/Conditions.java import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Condition} instances. */ public final class Conditions { /** * Returns a {@link Condition} that always returns {@code true}. */ @NonNull public static Condition trueCondition() {
return TRUE_CONDICATE;
google/agera
agera/src/main/java/com/google/android/agera/Conditions.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true);
import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Condition} instances. */ public final class Conditions { /** * Returns a {@link Condition} that always returns {@code true}. */ @NonNull public static Condition trueCondition() { return TRUE_CONDICATE; } /** * Returns a {@link Condition} that always returns {@code false}. */ @NonNull public static Condition falseCondition() {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate FALSE_CONDICATE = new StaticCondicate(false); // // Path: agera/src/main/java/com/google/android/agera/Common.java // static final StaticCondicate TRUE_CONDICATE = new StaticCondicate(true); // Path: agera/src/main/java/com/google/android/agera/Conditions.java import static com.google.android.agera.Common.FALSE_CONDICATE; import static com.google.android.agera.Common.TRUE_CONDICATE; import static com.google.android.agera.Preconditions.checkNotNull; import android.support.annotation.NonNull; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Condition} instances. */ public final class Conditions { /** * Returns a {@link Condition} that always returns {@code true}. */ @NonNull public static Condition trueCondition() { return TRUE_CONDICATE; } /** * Returns a {@link Condition} that always returns {@code false}. */ @NonNull public static Condition falseCondition() {
return FALSE_CONDICATE;
google/agera
agera/src/test/java/com/google/android/agera/MergersTest.java
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class MergersTest { @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/MergersTest.java import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class MergersTest { @Test public void shouldHavePrivateConstructor() {
assertThat(Mergers.class, hasPrivateConstructor());
google/agera
agera/src/test/java/com/google/android/agera/CommonTest.java
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class CommonTest { @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/CommonTest.java import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class CommonTest { @Test public void shouldHavePrivateConstructor() {
assertThat(Common.class, hasPrivateConstructor());
google/agera
extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // }
import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path";
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // } // Path: extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path";
private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile();
google/agera
extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // }
import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile();
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // } // Path: extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile();
private static final HttpRequest HTTP_POST_REQUEST = httpPostRequest(TEST_URI).compile();
google/agera
extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // }
import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile(); private static final HttpRequest HTTP_POST_REQUEST = httpPostRequest(TEST_URI).compile();
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // } // Path: extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile(); private static final HttpRequest HTTP_POST_REQUEST = httpPostRequest(TEST_URI).compile();
private static final HttpRequest HTTP_PUT_REQUEST = httpPutRequest(TEST_URI).compile();
google/agera
extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // }
import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile(); private static final HttpRequest HTTP_POST_REQUEST = httpPostRequest(TEST_URI).compile(); private static final HttpRequest HTTP_PUT_REQUEST = httpPutRequest(TEST_URI).compile(); private static final HttpRequest HTTP_DELETE_REQUEST =
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // } // Path: extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera.net; public final class HttpFunctionsTest { private static final String TEST_PROTOCOL = "httptest"; private static final String TEST_URI = TEST_PROTOCOL + "://path"; private static final HttpRequest HTTP_GET_REQUEST = httpGetRequest(TEST_URI).compile(); private static final HttpRequest HTTP_POST_REQUEST = httpPostRequest(TEST_URI).compile(); private static final HttpRequest HTTP_PUT_REQUEST = httpPutRequest(TEST_URI).compile(); private static final HttpRequest HTTP_DELETE_REQUEST =
httpDeleteRequest(TEST_URI).compile();
google/agera
extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // }
import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test;
private static final String POST_METHOD = "POST"; private static final String PUT_METHOD = "PUT"; private static final String DELETE_METHOD = "DELETE"; private static final byte[] EMPTY_BODY = new byte[0]; private static HttpURLConnection mockHttpURLConnection; @BeforeClass public static void onlyOnce() throws Throwable { mockHttpURLConnection = mock(HttpURLConnection.class); URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(final String s) { return s.equals(TEST_PROTOCOL) ? new URLStreamHandler() { @Override protected URLConnection openConnection(final URL url) throws IOException { return mockHttpURLConnection; } } : null; } }); } @After public void tearDown() { reset(mockHttpURLConnection); } @Test public void shouldPassOnGetMethod() throws Throwable {
// Path: extensions/net/src/main/java/com/google/android/agera/net/HttpFunctions.java // @NonNull // public static Function<HttpRequest, Result<HttpResponse>> httpFunction() { // return HTTP_FUNCTION; // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpDeleteRequest(@NonNull final String url) { // return new HttpRequestCompiler("DELETE", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpGetRequest(@NonNull final String url) { // return new HttpRequestCompiler("GET", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPostRequest(@NonNull final String url) { // return new HttpRequestCompiler("POST", url); // } // // Path: extensions/net/src/main/java/com/google/android/agera/net/HttpRequests.java // @NonNull // @SuppressWarnings("unchecked") // public static HTBodyHeaderFieldRedirectsCachesConnectionTimeoutReadTimeoutCompile // httpPutRequest(@NonNull final String url) { // return new HttpRequestCompiler("PUT", url); // } // Path: extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java import static com.google.android.agera.net.HttpFunctions.httpFunction; import static com.google.android.agera.net.HttpRequests.httpDeleteRequest; import static com.google.android.agera.net.HttpRequests.httpGetRequest; import static com.google.android.agera.net.HttpRequests.httpPostRequest; import static com.google.android.agera.net.HttpRequests.httpPutRequest; import static com.google.android.agera.net.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; private static final String POST_METHOD = "POST"; private static final String PUT_METHOD = "PUT"; private static final String DELETE_METHOD = "DELETE"; private static final byte[] EMPTY_BODY = new byte[0]; private static HttpURLConnection mockHttpURLConnection; @BeforeClass public static void onlyOnce() throws Throwable { mockHttpURLConnection = mock(HttpURLConnection.class); URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(final String s) { return s.equals(TEST_PROTOCOL) ? new URLStreamHandler() { @Override protected URLConnection openConnection(final URL url) throws IOException { return mockHttpURLConnection; } } : null; } }); } @After public void tearDown() { reset(mockHttpURLConnection); } @Test public void shouldPassOnGetMethod() throws Throwable {
assertThat(httpFunction()
google/agera
agera/src/main/java/com/google/android/agera/Binders.java
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator();
import static com.google.android.agera.Common.NULL_OPERATOR; import android.support.annotation.NonNull;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Binder} instances. */ public final class Binders { /** * Returns a {@link Binder} that does nothing. */ @SuppressWarnings("unchecked") @NonNull public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() {
// Path: agera/src/main/java/com/google/android/agera/Common.java // static final NullOperator NULL_OPERATOR = new NullOperator(); // Path: agera/src/main/java/com/google/android/agera/Binders.java import static com.google.android.agera.Common.NULL_OPERATOR; import android.support.annotation.NonNull; /* * Copyright 2016 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; /** * Utility methods for obtaining {@link Binder} instances. */ public final class Binders { /** * Returns a {@link Binder} that does nothing. */ @SuppressWarnings("unchecked") @NonNull public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() {
return NULL_OPERATOR;
google/agera
agera/src/test/java/com/google/android/agera/BindersTest.java
// Path: agera/src/main/java/com/google/android/agera/Binders.java // @SuppressWarnings("unchecked") // @NonNull // public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Binders.nullBinder; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class BindersTest { private static final int VALUE = 44; private static final int SECOND_VALUE = 43; @Test public void shouldHandleCallsToNullBinder() {
// Path: agera/src/main/java/com/google/android/agera/Binders.java // @SuppressWarnings("unchecked") // @NonNull // public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/BindersTest.java import static com.google.android.agera.Binders.nullBinder; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class BindersTest { private static final int VALUE = 44; private static final int SECOND_VALUE = 43; @Test public void shouldHandleCallsToNullBinder() {
nullBinder().bind(VALUE, SECOND_VALUE);
google/agera
agera/src/test/java/com/google/android/agera/BindersTest.java
// Path: agera/src/main/java/com/google/android/agera/Binders.java // @SuppressWarnings("unchecked") // @NonNull // public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Binders.nullBinder; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class BindersTest { private static final int VALUE = 44; private static final int SECOND_VALUE = 43; @Test public void shouldHandleCallsToNullBinder() { nullBinder().bind(VALUE, SECOND_VALUE); } @Test public void shouldHavePrivateConstructor() {
// Path: agera/src/main/java/com/google/android/agera/Binders.java // @SuppressWarnings("unchecked") // @NonNull // public static <TFirst, TSecond> Binder<TFirst, TSecond> nullBinder() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/BindersTest.java import static com.google.android.agera.Binders.nullBinder; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class BindersTest { private static final int VALUE = 44; private static final int SECOND_VALUE = 43; @Test public void shouldHandleCallsToNullBinder() { nullBinder().bind(VALUE, SECOND_VALUE); } @Test public void shouldHavePrivateConstructor() {
assertThat(Binders.class, hasPrivateConstructor());
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42;
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42;
private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE);
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE);
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE);
private static final Result<Integer> FAILURE = failure();
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> FAILURE = failure(); private MutableRepository<List<Integer>> listSource; private MutableRepository<List<Integer>> otherListSource;
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; @Config(manifest = NONE) @RunWith(RobolectricTestRunner.class) public final class RepositoryTerminationTest { private static final List<Integer> INITIAL_LIST = asList(1, 2, 3); private static final List<Integer> LIST = asList(4, 5); private static final List<Integer> OTHER_LIST = asList(6, 7); private static final int INITIAL_VALUE = 8; private static final int VALUE = 42; private static final Result<Integer> SUCCESS_WITH_VALUE = success(VALUE); private static final Result<Integer> FAILURE = failure(); private MutableRepository<List<Integer>> listSource; private MutableRepository<List<Integer>> otherListSource;
private MockUpdatable updatable;
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
@Mock private Predicate<List<Integer>> mockPredicate; @Mock private Receiver<Object> mockReceiver; @Mock private Function<List<Integer>, List<Integer>> mockFunction; @Mock private Function<List<Integer>, List<Integer>> mockOtherFunction; @Mock private Supplier<Result<Integer>> mockAttemptSupplier; @Before public void setUp() { initMocks(this); listSource = mutableRepository(LIST); otherListSource = mutableRepository(OTHER_LIST); updatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldEndAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST);
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Mock private Predicate<List<Integer>> mockPredicate; @Mock private Receiver<Object> mockReceiver; @Mock private Function<List<Integer>, List<Integer>> mockFunction; @Mock private Function<List<Integer>, List<Integer>> mockOtherFunction; @Mock private Supplier<Result<Integer>> mockAttemptSupplier; @Before public void setUp() { initMocks(this); listSource = mutableRepository(LIST); otherListSource = mutableRepository(OTHER_LIST); updatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldEndAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST);
final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST)
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
private Supplier<Result<Integer>> mockAttemptSupplier; @Before public void setUp() { initMocks(this); listSource = mutableRepository(LIST); otherListSource = mutableRepository(OTHER_LIST); updatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldEndAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orEnd(mockFunction) .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository);
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; private Supplier<Result<Integer>> mockAttemptSupplier; @Before public void setUp() { initMocks(this); listSource = mutableRepository(LIST); otherListSource = mutableRepository(OTHER_LIST); updatable = mockUpdatable(); } @After public void tearDown() { updatable.removeFromObservables(); } @Test public void shouldEndAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orEnd(mockFunction) .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository);
assertThat(repository, has(LIST));
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orEnd(mockFunction) .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST)); } @Test public void shouldSkipAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(INITIAL_LIST));
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); when(mockFunction.apply(INITIAL_LIST)).thenReturn(LIST); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orEnd(mockFunction) .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST)); } @Test public void shouldSkipAfterFailedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(INITIAL_LIST));
assertThat(updatable, wasNotUpdated());
google/agera
agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // }
import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config;
when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(INITIAL_LIST)); assertThat(updatable, wasNotUpdated()); } @Test public void shouldNotSkipAfterPassedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(listSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST));
// Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> MutableRepository<T> mutableRepository(@NonNull final T object) { // return new SimpleRepository<>(object); // } // // Path: agera/src/main/java/com/google/android/agera/Repositories.java // @NonNull // public static <T> REventSource<T, T> repositoryWithInitialValue(@NonNull final T initialValue) { // return RepositoryCompiler.repositoryWithInitialValue(initialValue); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> failure(@NonNull final Throwable failure) { // return failure == ABSENT_THROWABLE // ? Result.<T>absent() : new Result<T>(null, checkNotNull(failure)); // } // // Path: agera/src/main/java/com/google/android/agera/Result.java // @NonNull // public static <T> Result<T> success(@NonNull final T value) { // return new Result<>(checkNotNull(value), null); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/SupplierGives.java // @NonNull // @Factory // public static <T> Matcher<Supplier<T>> has(@NonNull final T value) { // return new SupplierGives<>(value); // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasNotUpdated() { // return WAS_NOT_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/UpdatableUpdated.java // @NonNull // @Factory // public static UpdatableUpdated wasUpdated() { // return WAS_UPDATED; // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // Path: agera/src/test/java/com/google/android/agera/test/mocks/MockUpdatable.java // public final class MockUpdatable implements Updatable { // private final List<Observable> observables; // // private boolean updated; // // private MockUpdatable() { // this.observables = new ArrayList<>(); // this.updated = false; // } // // @NonNull // public static MockUpdatable mockUpdatable() { // return new MockUpdatable(); // } // // @Override // public void update() { // updated = true; // } // // public boolean wasUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // return updated; // } // // public void resetUpdated() { // runUiThreadTasksIncludingDelayedTasks(); // updated = false; // } // // public void addToObservable(@NonNull final Observable observable) { // observable.addUpdatable(this); // observables.add(observable); // runUiThreadTasksIncludingDelayedTasks(); // } // // public void removeFromObservables() { // for (final Observable observable : observables) { // observable.removeUpdatable(this); // } // observables.clear(); // } // } // Path: agera/src/test/java/com/google/android/agera/RepositoryTerminationTest.java import static com.google.android.agera.Repositories.mutableRepository; import static com.google.android.agera.Repositories.repositoryWithInitialValue; import static com.google.android.agera.Result.failure; import static com.google.android.agera.Result.success; import static com.google.android.agera.test.matchers.SupplierGives.has; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasNotUpdated; import static com.google.android.agera.test.matchers.UpdatableUpdated.wasUpdated; import static com.google.android.agera.test.mocks.MockUpdatable.mockUpdatable; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import static org.robolectric.annotation.Config.NONE; import com.google.android.agera.test.mocks.MockUpdatable; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); when(mockPredicate.apply(INITIAL_LIST)).thenReturn(false); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(otherListSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(INITIAL_LIST)); assertThat(updatable, wasNotUpdated()); } @Test public void shouldNotSkipAfterPassedCheck() { when(mockPredicate.apply(anyListOf(Integer.class))).thenReturn(true); final Repository<List<Integer>> repository = repositoryWithInitialValue(INITIAL_LIST) .observe() .onUpdatesPerLoop() .check(mockPredicate).orSkip() .thenGetFrom(listSource) .compile(); updatable.addToObservable(repository); assertThat(repository, has(LIST));
assertThat(updatable, wasUpdated());
google/agera
agera/src/test/java/com/google/android/agera/ReceiversTest.java
// Path: agera/src/main/java/com/google/android/agera/Receivers.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Receiver<T> nullReceiver() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // }
import static com.google.android.agera.Receivers.nullReceiver; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test;
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ReceiversTest { private static final int VALUE = 44; @Test public void shouldHandleCallsToNullReceiver() {
// Path: agera/src/main/java/com/google/android/agera/Receivers.java // @SuppressWarnings("unchecked") // @NonNull // public static <T> Receiver<T> nullReceiver() { // return NULL_OPERATOR; // } // // Path: agera/src/test/java/com/google/android/agera/test/matchers/HasPrivateConstructor.java // @NonNull // @Factory // public static Matcher<Class<?>> hasPrivateConstructor() { // return INSTANCE; // } // Path: agera/src/test/java/com/google/android/agera/ReceiversTest.java import static com.google.android.agera.Receivers.nullReceiver; import static com.google.android.agera.test.matchers.HasPrivateConstructor.hasPrivateConstructor; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.Test; /* * Copyright 2015 Google Inc. All Rights Reserved. * * 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. */ package com.google.android.agera; public final class ReceiversTest { private static final int VALUE = 44; @Test public void shouldHandleCallsToNullReceiver() {
nullReceiver().accept(VALUE);