src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
---|---|
RFXChoiceBox extends RFXComponent { @Override public void focusLost(RFXComponent next) { ChoiceBox<?> choiceBox = (ChoiceBox<?>) node; Object selectedItem = choiceBox.getSelectionModel().getSelectedItem(); if (selectedItem != null && selectedItem.equals(prevSelectedItem)) { return; } String text = getChoiceBoxText(choiceBox, choiceBox.getSelectionModel().getSelectedIndex()); if (text != null) { recorder.recordSelect(this, text); } } RFXChoiceBox(Node source, JSONOMapConfig omapConfig, Point2D point, IJSONRecorder recorder); @Override void focusGained(RFXComponent prev); @Override void focusLost(RFXComponent next); @Override String _getText(); static final Logger LOGGER; } | @Test public void select() { ChoiceBox<?> choiceBox = (ChoiceBox<?>) getPrimaryStage().getScene().getRoot().lookup(".choice-box"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getSelectionModel().select(1); rfxChoiceBox.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Cat", recording.getParameters()[0]); }
@Test public void selectOptionWithQuotes() { @SuppressWarnings("unchecked") ChoiceBox<String> choiceBox = (ChoiceBox<String>) getPrimaryStage().getScene().getRoot().lookup(".choice-box"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getItems().add(" \"Mouse \" "); choiceBox.getSelectionModel().select(" \"Mouse \" "); rfxChoiceBox.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals(" \"Mouse \" ", recording.getParameters()[0]); }
@Test public void htmlOptionSelect() { @SuppressWarnings("unchecked") ChoiceBox<String> choiceBox = (ChoiceBox<String>) getPrimaryStage().getScene().getRoot().lookup(".choice-box"); LoggingRecorder lr = new LoggingRecorder(); String text = "This is a test text"; final String htmlText = "<html><font color=\"RED\"><h1><This is also content>" + text + "</h1></html>"; Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getItems().add(htmlText); choiceBox.getSelectionModel().select(htmlText); rfxChoiceBox.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals(text, recording.getParameters()[0]); }
@Test public void selectDuplicateOption() { @SuppressWarnings("unchecked") ChoiceBox<String> choiceBox = (ChoiceBox<String>) getPrimaryStage().getScene().getRoot().lookup(".choice-box"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getSelectionModel().select(1); rfxChoiceBox.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Cat", recording.getParameters()[0]); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getItems().add(2, "Cat"); choiceBox.getSelectionModel().select(2); rfxChoiceBox.focusLost(null); }); recordings = lr.waitAndGetRecordings(2); recording = recordings.get(1); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Cat(1)", recording.getParameters()[0]); }
@Test public void selectMultipleDuplicateOption() { @SuppressWarnings("unchecked") ChoiceBox<String> choiceBox = (ChoiceBox<String>) getPrimaryStage().getScene().getRoot().lookup(".choice-box"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getSelectionModel().select(1); rfxChoiceBox.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Cat", recording.getParameters()[0]); Platform.runLater(() -> { RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr); choiceBox.getItems().add(2, "Cat"); choiceBox.getItems().add("Cat"); choiceBox.getSelectionModel().select(4); rfxChoiceBox.focusLost(null); }); recordings = lr.waitAndGetRecordings(2); recording = recordings.get(1); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Cat(2)", recording.getParameters()[0]); } |
JavaFXSliderElement extends JavaFXElement { @Override public boolean marathon_select(String value) { ((Slider) node).setValue(Double.valueOf(Double.parseDouble(value))); return true; } JavaFXSliderElement(Node component, IJavaFXAgent driver, JFXWindow window); @Override boolean marathon_select(String value); @Override String _getText(); static final Logger LOGGER; } | @Test public void setSliderValue() { Slider sliderNode = (Slider) getPrimaryStage().getScene().getRoot().lookup(".slider"); slider.marathon_select("25.0"); new Wait("Waiting for slider value to be set.") { @Override public boolean until() { return 25.0 == sliderNode.getValue(); } }; }
@Test public void getText() { List<String> text = new ArrayList<>(); Platform.runLater(() -> { slider.marathon_select("25.0"); text.add(slider.getAttribute("text")); }); new Wait("Waiting for the slider text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("25.0", text.get(0)); }
@Test(expectedExceptions = NumberFormatException.class) public void illegalArgumentException() { Slider sliderNode = (Slider) getPrimaryStage().getScene().getRoot().lookup(".slider"); slider.marathon_select("ten"); new Wait("Waiting for slider value to be set.") { @Override public boolean until() { return 25.0 == sliderNode.getValue(); } }; } |
RFXListView extends RFXComponent { @Override public void focusLost(RFXComponent next) { ListView<?> listView = (ListView<?>) node; String currentCellValue = getListCellValue(listView, index); if (currentCellValue != null && !currentCellValue.equals(cellValue)) { recorder.recordSelect2(this, currentCellValue, true); } if ((next == null || getComponent() != next.getComponent()) && listView.getSelectionModel().getSelectedIndices().size() > 1) { String currListText = getListSelectionText(listView); if (!currListText.equals(listSelectionText)) { recorder.recordSelect(this, currListText); } } } RFXListView(Node source, JSONOMapConfig omapConfig, Point2D point, IJSONRecorder recorder); @Override void focusGained(RFXComponent prev); @Override void focusLost(RFXComponent next); @Override String getCellInfo(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String _getText(); static final Logger LOGGER; } | @Test public void selectNoSelection() { ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[]", recording.getParameters()[0]); }
@Test public void selectSingleItemSelection() { ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { listView.getSelectionModel().select(2); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Long Row 3\"]", recording.getParameters()[0]); }
@Test public void getText() { ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(new Runnable() { @Override public void run() { listView.getSelectionModel().select(2); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); text.add(rfxListView.getAttribute("text")); } }); new Wait("Waiting for list text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("[\"Long Row 3\"]", text.get(0)); }
@Test public void getTextForMultipleSelection() { ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(new Runnable() { @Override public void run() { MultipleSelectionModel<?> selectionModel = listView.getSelectionModel(); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.selectIndices(2, 8); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); text.add(rfxListView.getAttribute("text")); } }); new Wait("Waiting for list text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 9\"]", text.get(0)); }
@Test public void selectMultipleItemSelection() { ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { MultipleSelectionModel<?> selectionModel = listView.getSelectionModel(); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.selectIndices(2, 6); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Long Row 3\",\"Row 7\"]", recording.getParameters()[0]); }
@Test public void selectSpecialItemSelection() { @SuppressWarnings("unchecked") ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { listView.getItems().add(7, " Special Characters ([],)"); listView.getSelectionModel().select(7); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\" Special Characters ([],)\"]", recording.getParameters()[0]); }
@Test public void selectDuplicate() { @SuppressWarnings("unchecked") ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { listView.getSelectionModel().select(8); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Row 9\"]", recording.getParameters()[0]); Platform.runLater(new Runnable() { @Override public void run() { listView.getItems().add(9, "Row 9"); listView.getSelectionModel().clearAndSelect(9); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); recordings = lr.waitAndGetRecordings(2); recording = recordings.get(1); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Row 9(1)\"]", recording.getParameters()[0]); }
@Test public void listMultipleDuplicates() { @SuppressWarnings("unchecked") ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { listView.getSelectionModel().select(8); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Row 9\"]", recording.getParameters()[0]); Platform.runLater(new Runnable() { @Override public void run() { listView.getItems().add(9, "Row 9"); listView.getItems().add(10, "Row 9"); listView.getSelectionModel().clearAndSelect(10); RFXListView rfxListView = new RFXListView(listView, null, null, lr); rfxListView.focusLost(new RFXListView(null, null, null, lr)); } }); recordings = lr.waitAndGetRecordings(2); recording = recordings.get(1); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("[\"Row 9(2)\"]", recording.getParameters()[0]); } |
RFXTabPane extends RFXComponent { @Override protected void mouseClicked(MouseEvent me) { TabPane tp = (TabPane) node; SingleSelectionModel<Tab> selectionModel = tp.getSelectionModel(); Tab selectedTab = selectionModel.getSelectedItem(); if (selectedTab != null && prevSelection != selectionModel.getSelectedIndex()) { recorder.recordSelect(this, getTextForTab(tp, selectedTab)); } prevSelection = selectionModel.getSelectedIndex(); } RFXTabPane(Node source, JSONOMapConfig omapConfig, Point2D point, IJSONRecorder recorder); @Override String _getText(); static final Logger LOGGER; } | @Test public void selectNormalTab() throws Throwable { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); rfxTabPane.mouseClicked(null); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording select = recordings.get(0); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 1", select.getParameters()[0]); Platform.runLater(new Runnable() { @Override public void run() { RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); tabPane.getSelectionModel().select(1); rfxTabPane.mouseClicked(null); } }); recordings = lr.waitAndGetRecordings(2); select = recordings.get(1); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 2", select.getParameters()[0]); }
@Test public void getText() throws Throwable { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(new Runnable() { @Override public void run() { RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); tabPane.getSelectionModel().select(1); rfxTabPane.mouseClicked(null); text.add(rfxTabPane.getAttribute("text")); } }); new Wait("Waiting for tab pane text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("Tab 2", text.get(0)); }
@Test public void selectNoTextTab() { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { Tab tab = new Tab(); tab.setGraphic(new ImageView(RFXTabPaneTest.imgURL.toString())); tabPane.getTabs().add(tab); tabPane.getSelectionModel().select(4); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); rfxTabPane.mouseClicked(null); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording select = recordings.get(0); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("middle", select.getParameters()[0]); }
@Test public void selectNoIconAndTextTab() { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { tabPane.getTabs().add(new Tab()); tabPane.getSelectionModel().select(4); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); rfxTabPane.mouseClicked(null); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording select = recordings.get(0); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("tabIndex-4", select.getParameters()[0]); }
@Test public void tabDuplicates() throws Throwable { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { tabPane.getSelectionModel().select(1); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); rfxTabPane.mouseClicked(null); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording select = recordings.get(0); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 2", select.getParameters()[0]); Platform.runLater(new Runnable() { @Override public void run() { tabPane.getTabs().add(2, new Tab("Tab 2")); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); tabPane.getSelectionModel().select(2); rfxTabPane.mouseClicked(null); } }); recordings = lr.waitAndGetRecordings(2); select = recordings.get(1); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 2(1)", select.getParameters()[0]); }
@Test public void tabMultipleDuplicates() throws Throwable { TabPane tabPane = (TabPane) getPrimaryStage().getScene().getRoot().lookup(".tab-pane"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { tabPane.getSelectionModel().select(1); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); rfxTabPane.mouseClicked(null); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording select = recordings.get(0); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 2", select.getParameters()[0]); Platform.runLater(new Runnable() { @Override public void run() { tabPane.getTabs().add(2, new Tab("Tab 2")); tabPane.getTabs().add(3, new Tab("Tab 2")); RFXTabPane rfxTabPane = new RFXTabPane(tabPane, null, null, lr); tabPane.getSelectionModel().select(3); rfxTabPane.mouseClicked(null); } }); recordings = lr.waitAndGetRecordings(2); select = recordings.get(1); AssertJUnit.assertEquals("recordSelect", select.getCall()); AssertJUnit.assertEquals("Tab 2(2)", select.getParameters()[0]); } |
ReactiveExecutionStrategy extends ExecutionStrategy { @Override public ExecutionResult execute(ExecutionContext context, ExecutionParameters parameters) throws NonNullableFieldWasNullException { Map<String, List<Field>> fields = parameters.fields(); Object source = parameters.source(); return complexChangesFlow( context, source, __ -> fields.entrySet().stream(), (entry, sourceValue) -> resolveField( new ReactiveContext(context, entry.getKey()), transformParametersSource(parameters, source == null ? null : sourceValue), entry.getValue() ), results -> { Map<Object, Object> result = new HashMap<>(); for (Object entry : results) { result.put(((SimpleEntry) entry).getKey(), ((SimpleEntry) entry).getValue()); } return result; } ); } @Override ExecutionResult execute(ExecutionContext context, ExecutionParameters parameters); } | @Test public void testPlainField() throws Exception { GraphQLSchema schema = newQuerySchema(it -> it .field(newLongField("a").dataFetcher(env -> Flowable.interval(1, SECONDS, scheduler).take(2))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }"); assertThat(executionResult) .isNotNull() .satisfies(it -> assertThat(it.<Publisher<Change>>getData()).isNotNull().isInstanceOf(Publisher.class)); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(2, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("01:000", "", ImmutableMap.of("a", 0L)), tuple("02:000", "a", 1L) )) .assertComplete(); }
@Test public void testStartWith() throws Exception { GraphQLSchema schema = newQuerySchema(it -> it .field(newLongField("a").dataFetcher(env -> Flowable.interval(1, SECONDS, scheduler).take(2).startWith(-42L))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(2, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("00:000", "", ImmutableMap.of("a", -42L)), tuple("01:000", "a", 0L), tuple("02:000", "a", 1L) )) .assertComplete(); }
@Test public void testMultipleFields() throws Exception { GraphQLSchema schema = newQuerySchema(it -> it .field(newLongField("a").dataFetcher(env -> Flowable.interval(300, MILLISECONDS, scheduler).take(8))) .field(newLongField("b").dataFetcher(env -> Flowable.timer(2, SECONDS, scheduler))) .field(newLongField("c").dataFetcher(env -> Flowable.just(42L))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a, b, c }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); subscriber.assertEmpty(); scheduler.advanceTimeBy(1, SECONDS); subscriber.assertEmpty(); scheduler.advanceTimeBy(2, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("02:000", "", ImmutableMap.of("a", 5L, "b", 0L, "c", 42L)), tuple("02:100", "a", 6L), tuple("02:400", "a", 7L) )) .assertComplete(); }
@Test public void testNested() throws Exception { GraphQLObjectType innerType = newObject() .name("Inner") .field(newStringField("b").dataFetcher(env -> Flowable.interval(300, MILLISECONDS, scheduler).take(4).map(i -> i + " " + env.getSource()))) .build(); GraphQLSchema schema = newQuerySchema(it -> it .field(newField("a", innerType).dataFetcher(env -> Flowable.interval(1, SECONDS, scheduler).take(3))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a { b } }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(5, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("01:300", "", ImmutableMap.of("a", ImmutableMap.of("b", "0 0"))), tuple("01:600", "a.b", "1 0"), tuple("01:900", "a.b", "2 0"), tuple("02:300", "a", ImmutableMap.of("b", "0 1")), tuple("02:600", "a.b", "1 1"), tuple("02:900", "a.b", "2 1"), tuple("03:300", "a", ImmutableMap.of("b", "0 2")), tuple("03:600", "a.b", "1 2"), tuple("03:900", "a.b", "2 2"), tuple("04:200", "a.b", "3 2") )) .assertComplete(); }
@Test public void testArray() throws Exception { GraphQLObjectType innerType = newObject() .name("Inner") .field(newStringField("b").dataFetcher(env -> Flowable.interval(300, MILLISECONDS, scheduler).take(4).map(i -> i + " " + env.getSource()))) .build(); GraphQLSchema schema = newQuerySchema(it -> it .field(newField("a", new GraphQLList(innerType)).dataFetcher(env -> Flowable.interval(500, MILLISECONDS, scheduler).take(3).toList().toFlowable())) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a { b } }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(3, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("01:800", "", ImmutableMap.of("a", asList(ImmutableMap.of("b", "0 0"), ImmutableMap.of("b", "0 1"), ImmutableMap.of("b", "0 2")))), tuple("02:100", "a[0].b", "1 0"), tuple("02:100", "a[1].b", "1 1"), tuple("02:100", "a[2].b", "1 2"), tuple("02:400", "a[0].b", "2 0"), tuple("02:400", "a[1].b", "2 1"), tuple("02:400", "a[2].b", "2 2"), tuple("02:700", "a[0].b", "3 0"), tuple("02:700", "a[1].b", "3 1"), tuple("02:700", "a[2].b", "3 2") )) .assertComplete(); }
@Test public void testArrayStartsWith() throws Exception { GraphQLObjectType innerType = newObject() .name("Inner") .field(newStringField("b").staticValue("foo")) .build(); GraphQLSchema schema = newQuerySchema(it -> it .field( newField("a", new GraphQLList(innerType)) .dataFetcher(env -> Flowable .just(asList(true, true, true)) .delay(1, SECONDS, scheduler) .startWith(new ArrayList<Boolean>()) ) ) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a { b } }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(2, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("00:000", "", ImmutableMap.of("a", emptyList())), tuple("01:000", "a", asList(ImmutableMap.of("b", "foo"), ImmutableMap.of("b", "foo"), ImmutableMap.of("b", "foo"))), tuple("01:000", "a[1]", ImmutableMap.of("b", "foo")), tuple("01:000", "a[2]", ImmutableMap.of("b", "foo")) )) .assertComplete(); }
@Test public void testAnyPublisher() throws Exception { Duration tick = Duration.ofSeconds(1); GraphQLSchema schema = newQuerySchema(it -> it .field(newLongField("a").dataFetcher(env -> Flux.interval(tick).take(2))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }"); StepVerifier.withVirtualTime(() -> (Publisher<Change>) executionResult.getData()) .expectSubscription() .expectNoEvent(tick) .assertNext(matchChange("", ImmutableMap.of("a", 0L))) .expectNoEvent(tick) .assertNext(matchChange("a", 1L)) .verifyComplete(); }
@Test public void testStaticValues() throws Exception { GraphQLSchema schema = newQuerySchema(it -> it .field(newStringField("a").dataFetcher(env -> "staticA")) .field(newStringField("b").dataFetcher(env -> "staticB")) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a, b }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); subscriber .assertChanges(it -> it.containsExactly( tuple("00:000", "", ImmutableMap.of("a", "staticA", "b", "staticB")) )) .assertComplete(); } |
MainPresenterImpl extends BasePresenter<MainScene> implements MainPresenter { @Override public void onSceneAdded(MainScene scene, Bundle data) { super.onSceneAdded(scene, data); disposable = pokeSource.getPokemonAbilityStringObservable("12") .subscribeOn(provider.io()) .observeOn(provider.ui()) .subscribe(new Consumer<String>() { @Override public void accept(@NonNull String pokemonAbility) throws Exception { if (getScene() != null) { getScene().setApiText(pokemonAbility); } } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) throws Exception { if (throwable instanceof HttpException) { if (((HttpException) throwable).code() == HttpURLConnection.HTTP_NOT_FOUND) { if (getScene() != null) { getScene().showErrorDialog("Lost!"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAVAILABLE) { if (getScene() != null) { getScene().showErrorDialog("Fire on the Server"); } } else if (((HttpException) throwable).code() == HttpURLConnection.HTTP_UNAUTHORIZED) { if (getScene() != null) { getScene().showErrorDialog("You shall not pass!"); } } } else { if (getScene() != null) { getScene().showErrorDialog(throwable.getMessage()); } } throwable.printStackTrace(); } }); } @Inject MainPresenterImpl(BaseSchedulerProvider schedulerProvider, PokeDataSource dataSource); @Override void onSceneAdded(MainScene scene, Bundle data); @Override void onSceneRemoved(); } | @Test public void testOnSceneAdded() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(mainSceneMock).setApiText(captor.capture()); assertEquals("Id: 12\n" + "Name: butterfreeAbility Name : tinted-lens\n" + " Is Hidden : true", captor.getValue()); }
@Test public void testDemoResponseError503() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); MockResponse response = new MockResponse(); response.setResponseCode(HttpURLConnection.HTTP_UNAVAILABLE); getErrorMockWebServer().enqueue(response); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); verify(mainSceneMock, times(0)).setApiText(anyString()); verify(mainSceneMock, times(1)).showErrorDialog("Fire on the Server"); }
@Test public void testDemoResponseError404() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); MockResponse response = new MockResponse(); response.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND); getErrorMockWebServer().enqueue(response); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); verify(mainSceneMock, times(1)).showErrorDialog("Lost!"); verify(mainSceneMock, times(0)).setApiText(anyString()); }
@Test public void testDemoResponseError403() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); MockResponse response = new MockResponse(); response.setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED); getErrorMockWebServer().enqueue(response); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); verify(mainSceneMock, times(1)).showErrorDialog("You shall not pass!"); verify(mainSceneMock, times(0)).setApiText(anyString()); }
@Test public void testDemoResponseErrorSocket() { reset(mainSceneMock); MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); MockResponse response = new MockResponse(); response.setBody("\"message\":\"Hello\"").throttleBody(1, 2, TimeUnit.SECONDS); getErrorMockWebServer().enqueue(response); presenter.onSceneAdded(mainSceneMock, null); testScheduler.triggerActions(); verify(mainSceneMock, times(1)).showErrorDialog(anyString()); verify(mainSceneMock, times(0)).setApiText(anyString()); } |
PokeDataSource { public Observable<String> getPokemonStringObservable(String id) { return pokemonService.getPokemon(id) .map(new Function<Pokemon, String>() { @Override public String apply(@NonNull Pokemon pokemon) throws Exception { return constructPokemon(pokemon); } }); } @Inject PokeDataSource(PokemonService pokemonService); Observable<String> getPokemonStringObservable(String id); Observable<String> getPokemonAbilityStringObservable(String id); } | @Test public void testOnAddedHeader() throws InterruptedException { PokeDataSource dataSource = new PokeDataSource(pokemonService); TestObserver<String> observer = new TestObserver<>(); dataSource.getPokemonStringObservable("12").subscribe(observer); RecordedRequest recordedRequest = getMockWebServer().takeRequest(); assertEquals("application/json", recordedRequest.getHeader("Content-Type")); }
@Test public void testGetPokemonStringObservable() { PokeDataSource dataSource = new PokeDataSource(pokemonService); TestObserver observer = new TestObserver(); dataSource.getPokemonStringObservable("12") .subscribe(observer); observer.assertNoErrors(); observer.awaitTerminalEvent(); observer.assertComplete(); observer.assertValue("Id: 12\n" + "Name: butterfree"); } |
PokeDataSource { public Observable<String> getPokemonAbilityStringObservable(String id) { return pokemonService.getPokemon(id) .map(new Function<Pokemon, String>() { @Override public String apply(@NonNull Pokemon pokemon) throws Exception { return constructAbility(pokemon); } }); } @Inject PokeDataSource(PokemonService pokemonService); Observable<String> getPokemonStringObservable(String id); Observable<String> getPokemonAbilityStringObservable(String id); } | @Test public void testGetPokemonAbilityStringObservable() { PokeDataSource dataSource = new PokeDataSource(pokemonService); TestObserver observer = new TestObserver(); dataSource.getPokemonAbilityStringObservable("12") .subscribe(observer); observer.assertNoErrors(); observer.awaitTerminalEvent(); observer.assertComplete(); observer.assertValue("Id: 12\n" + "Name: butterfreeAbility Name : tinted-lens\n" + " Is Hidden : true"); } |
ScrambleMove { public static ScrambleMove parse(String move) { ScrambleMoves sm = ScrambleMoves.determineMove(move); String sanitizedMove = move.replaceAll("\\s", ""); sanitizedMove = sanitizedMove.substring(sanitizedMove.lastIndexOf(":") + 1, sanitizedMove.length() - 1); String[] moveParts = sanitizedMove.split("(" + ARG_SEP + "|" + COORD_SEP + "|" + COORD_SEP_CAP + ")"); long[] args = new long[moveParts.length]; for (int i = 0; i < moveParts.length; i++) { args[i] = Long.parseLong(moveParts[i]); } return new ScrambleMove(sm, args); } ScrambleMove(ScrambleMoves move, long ... args); long getArg(int argIndex); void toReverse(); String toKeyString(StringBuilder sbIn, boolean reverse); String toKeyString(); static ScrambleMove parse(String move); static LongLinkedList<ScrambleMove> parseMulti(String moves); static synchronized boolean isUsingOpCode(); static synchronized void useOpCode(boolean use); @Override boolean equals(Object o); @Override int hashCode(); final ScrambleMoves move; } | @Test public void testParse(){ assertEquals(this.testMove, ScrambleMove.parse(this.expectedString)); } |
MoveValidator { public static void throwIfInvalidMove(Matrix matrix, ScrambleMove move) { switch (move.move) { case SWAP: MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.Swap.X1), Plane.X); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.Swap.Y1), Plane.Y); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.Swap.X2), Plane.X); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.Swap.Y2), Plane.Y); if ( move.getArg(ScrambleConstants.Swap.X1) == move.getArg(ScrambleConstants.Swap.X2) && move.getArg(ScrambleConstants.Swap.Y1) == move.getArg(ScrambleConstants.Swap.Y2) ) { throw new IllegalArgumentException("Can't swap a node's value with itself."); } break; case SWAP_ROW: MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SwapRow.ROWCOL1), Plane.Y); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SwapRow.ROWCOL2), Plane.Y); break; case SWAP_COL: MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SwapCol.ROWCOL1), Plane.X); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SwapCol.ROWCOL2), Plane.X); break; case SLIDE_ROW: MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SlideRow.ROWCOL), Plane.Y); break; case SLIDE_COL: MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.SlideCol.ROWCOL), Plane.X); break; case ROT_BOX: if (!(move.getArg(ScrambleConstants.RotateBox.ROTNUM) >= -3 && move.getArg(ScrambleConstants.RotateBox.ROTNUM) <= 3 && move.getArg(ScrambleConstants.RotateBox.ROTNUM) != 0)) { throw new IllegalArgumentException("Invalid number of rotations given. Given: " + move.getArg(ScrambleConstants.RotateBox.ROTNUM)); } MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.RotateBox.X), Plane.X); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.RotateBox.Y), Plane.Y); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.RotateBox.SIZE) + move.getArg(ScrambleConstants.RotateBox.X) - 1, Plane.X); MatrixValidator.throwIfBadIndex(matrix, move.getArg(ScrambleConstants.RotateBox.SIZE) + move.getArg(ScrambleConstants.RotateBox.Y) - 1, Plane.Y); if (move.getArg(ScrambleConstants.RotateBox.SIZE) < MIN_SIZE_FOR_ROTATION) { throw new IllegalArgumentException("Invalid size of sub matrix."); } break; default: throw new IllegalArgumentException("Unsupported move passed to validator."); } } static boolean matrixIsTooSmallForScrambling(Matrix matrix); static void throwIfMatrixTooSmallForScrambling(Matrix matrix); static void throwIfInvalidMove(Matrix matrix, ScrambleMove move); static void throwIfInvalidMove(Matrix matrix, ScrambleMove move, ScrambleMoves moveToBe); static final long MIN_SIZE_FOR_SCRAMBLING; static final long MIN_SIZE_FOR_ROTATION; } | @Test public void testIfInvalidMove(){ Matrix testMatrix = getTestMatrix(MoveValidator.MIN_SIZE_FOR_SCRAMBLING); for(Map.Entry<ScrambleMoves, ScrambleMove> curEntry : validMoves.entrySet()){ MoveValidator.throwIfInvalidMove(testMatrix, curEntry.getValue()); MoveValidator.throwIfInvalidMove(testMatrix, curEntry.getValue(), curEntry.getKey()); } for(Map.Entry<Integer, ScrambleMove> curEntry : invalidMoves.entrySet()){ try { MoveValidator.throwIfInvalidMove(testMatrix, curEntry.getValue()); Assert.fail(); }catch (IllegalArgumentException|IndexOutOfBoundsException e){ } } for(Map.Entry<ScrambleMoves, ScrambleMove> curEntry : invalidMovesBadType.entrySet()){ try { MoveValidator.throwIfInvalidMove(testMatrix, curEntry.getValue(), curEntry.getKey()); Assert.fail(); }catch (IllegalArgumentException|IndexOutOfBoundsException e){ } } } |
UserFactory { public User create(String username, String password, String salt, String role) { return new User(username, password, salt, role); } User create(String username, String password, String salt, String role); } | @Test public void testCreate() { UserFactory userFactory = new UserFactory(); assertNotNull(userFactory.create("username", "pass", "salt", "USER")); } |
AuthProviderService implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String login = authentication.getName(); String password = authentication.getCredentials().toString(); LOGGER.info("Doing login " + login); User u = userService.isLoginValid(login, password); if(u != null) { LOGGER.info("Login successful. User: " + login); return usernamePasswordAuthenticationTokenFactory.create(u); } throw new UsernameNotFoundException("Not valid login/password"); } @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> aClass); } | @Test public void testAuthenticateSuccess() { User user = new User("username", "pass", "salt", "role"); Authentication authentication = mock(UsernamePasswordAuthenticationToken.class); when(authentication.getName()).thenReturn("username"); when(authentication.getCredentials()).thenReturn("pass"); when(userService.isLoginValid("username", "pass")).thenReturn(user); when(usernamePasswordAuthenticationTokenFactory.create(user)).thenReturn((UsernamePasswordAuthenticationToken) authentication); try { Authentication a = authProviderService.authenticate(authentication); assertEquals("username", a.getName()); assertEquals("pass", a.getCredentials().toString()); } catch (UsernameNotFoundException e) { fail("This code should not be executed"); } }
@Test public void testAuthenticateInvalid() { when(userService.isLoginValid(anyString(), anyString())).thenReturn(null); Authentication authentication = mock(Authentication.class); when(authentication.getName()).thenReturn("username"); when(authentication.getCredentials()).thenReturn("pass"); try { authProviderService.authenticate(authentication); fail("This code should not be executed"); } catch (UsernameNotFoundException e) { assertNotNull(e); } } |
JwtService { public String createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } return null; } String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret); } | @Test public void testCreateTokenEmptyUsername() { assertNull(jwtService.createToken(null, SECRET, generateValidDate())); assertNull(jwtService.createToken("", SECRET, generateValidDate())); assertNull(jwtService.createToken(" ", SECRET, generateValidDate())); }
@Test public void testCreateTokenEmptySecret() { assertNull(jwtService.createToken(USERNAME, null, generateValidDate())); assertNull(jwtService.createToken(USERNAME, "", generateValidDate())); assertNull(jwtService.createToken(USERNAME, " ", generateValidDate())); }
@Test public void testCreateTokenInvalidDate() { assertNull(jwtService.createToken(USERNAME, SECRET, null)); assertNull(jwtService.createToken(USERNAME, SECRET, generateInValidDate())); }
@Test public void testCreateTokenSuccess() { Date d = generateValidDate(); String s = jwtService.createToken(USERNAME, SECRET, d); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertEquals(compactJws, s); } |
JwtService { public boolean isValid(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); Jwts.parser().setSigningKey(secret2).parseClaimsJws(token); return true; } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return false; } String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret); } | @Test public void testIsValidTokenEmptyToken() { assertFalse(jwtService.isValid(null, SECRET)); assertFalse(jwtService.isValid(" ", SECRET)); }
@Test public void testIsValidTokenEmptySecret() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertFalse(jwtService.isValid(compactJws, null)); assertFalse(jwtService.isValid(compactJws, " ")); }
@Test public void testIsValidTokenExpiredDate() { Date d = generateInValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertFalse(jwtService.isValid(compactJws, SECRET)); }
@Test public void testIsValidTokenWrongSecret() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertFalse(jwtService.isValid(compactJws, "secret2")); assertFalse(jwtService.isValid(compactJws, "secrett")); }
@Test public void testIsValidTokenSuccess() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertTrue(jwtService.isValid(compactJws, SECRET)); } |
UserService { public void create(String username, String password, String role) { String salt = stringSupport.generate(); User u = userFactory.create(username, shaPasswordEncoder.encodePassword(password, salt), salt, role); userRepository.save(u); } void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); } | @Test public void testCreate() { userService.create(USERNAME, PASS, ROLE); verify(userRepository).save(user); } |
JwtService { public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; } String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret); } | @Test public void testGetUsernameEmptyToken() { assertNull(jwtService.getUsername(null, SECRET)); assertNull(jwtService.getUsername(" ", SECRET)); }
@Test public void testGetUsernameEmptySecret() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertNull(jwtService.getUsername(compactJws, null)); assertNull(jwtService.getUsername(compactJws, " ")); }
@Test public void testGetUsernameExpired() { Date d = generateInValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertNull(jwtService.getUsername(compactJws, SECRET)); }
@Test public void testGetUsernameNoSubject() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertNull(jwtService.getUsername(compactJws, SECRET)); }
@Test public void testGetUsernameSuccess() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertEquals(USERNAME, jwtService.getUsername(compactJws, SECRET)); } |
UsernamePasswordAuthenticationTokenFactory { public UsernamePasswordAuthenticationToken create(User u) { SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(u.getRole()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), Arrays.asList(simpleGrantedAuthority)); return authentication; } UsernamePasswordAuthenticationToken create(User u); } | @Test public void testCreate() { UsernamePasswordAuthenticationTokenFactory factory = new UsernamePasswordAuthenticationTokenFactory(); User u = new User("username", "pass", "salt", "role"); UsernamePasswordAuthenticationToken auth = factory.create(u); assertNotNull(auth); assertEquals(u.getUsername(), auth.getPrincipal().toString()); assertEquals(u.getPassword(), auth.getCredentials().toString()); assertEquals(u.getRole(), auth.getAuthorities().toArray()[0].toString()); } |
JwtAuthenticationTokenFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { String authToken = request.getHeader(AUTHORIZATION); if(authToken != null) { try { authToken = new String(authToken.substring(BEGIN_INDEX).getBytes(), UTF_8); SecurityContext context = securityAppContext.getContext(); if(context.getAuthentication() == null) { logger.info("Checking authentication for token " + authToken); User u = userService.validateUser(authToken, request.getRemoteAddr()); if(u != null) { logger.info("User " + u.getUsername() + " found."); Authentication authentication = usernamePasswordAuthenticationTokenFactory.create(u); context.setAuthentication(authentication); } } } catch (StringIndexOutOfBoundsException e) { logger.error(e.getMessage()); } } chain.doFilter(request, response); } } | @Test public void doFilterInternalNullToken() throws IOException, ServletException { when(request.getHeader(AUTHORIZATION)).thenReturn(null); jwtAuthenticationTokenFilter.doFilterInternal(request, response, chain); verifyZeroInteractions(securityAppContext, userService, usernamePasswordAuthenticationTokenFactory ); verify(chain).doFilter(request, response); }
@Test public void doFilterInternalExceptionToken() throws IOException, ServletException { when(request.getHeader(AUTHORIZATION)).thenReturn("123"); jwtAuthenticationTokenFilter.doFilterInternal(request, response, chain); verifyZeroInteractions(securityAppContext, userService, usernamePasswordAuthenticationTokenFactory ); verify(chain).doFilter(request, response); }
@Test public void doFilterInternalAuthenticationNotNull() throws ServletException, IOException { String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiJ9.GE2q1gX6T-mcjf0xmIlGru1gzu-PQF1leFK4U3Kphj8ZLpQG3Rn8qyLLO38ilyvP2u03Ft7bEBAJqRS-86WXCg"; when(request.getHeader(AUTHORIZATION)).thenReturn(token); SecurityContext context = mock(SecurityContext.class); when(securityAppContext.getContext()).thenReturn(context); Authentication authentication = mock(Authentication.class); when(context.getAuthentication()).thenReturn(authentication); jwtAuthenticationTokenFilter.doFilterInternal(request, response, chain); verifyZeroInteractions(userService, usernamePasswordAuthenticationTokenFactory ); verify(chain).doFilter(request, response); verify(context, never()).setAuthentication(any(Authentication.class)); }
@Test public void doFilterInternalAuthenticationNullUser() throws ServletException, IOException { String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiJ9.GE2q1gX6T-mcjf0xmIlGru1gzu-PQF1leFK4U3Kphj8ZLpQG3Rn8qyLLO38ilyvP2u03Ft7bEBAJqRS-86WXCg"; when(request.getHeader(AUTHORIZATION)).thenReturn(token); when(request.getRemoteAddr()).thenReturn("localhost"); SecurityContext context = mock(SecurityContext.class); when(securityAppContext.getContext()).thenReturn(context); when(context.getAuthentication()).thenReturn(null); when(userService.validateUser("eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiJ9.GE2q1gX6T-mcjf0xmIlGru1gzu-PQF1leFK4U3Kphj8ZLpQG3Rn8qyLLO38ilyvP2u03Ft7bEBAJqRS-86WXCg", request.getRemoteAddr())).thenReturn(null); jwtAuthenticationTokenFilter.doFilterInternal(request, response, chain); verifyZeroInteractions(usernamePasswordAuthenticationTokenFactory); verify(context, never()).setAuthentication(any(Authentication.class)); verify(chain).doFilter(request, response); }
@Test public void doFilterInternalAuthenticationSuccess() throws ServletException, IOException { String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiJ9.GE2q1gX6T-mcjf0xmIlGru1gzu-PQF1leFK4U3Kphj8ZLpQG3Rn8qyLLO38ilyvP2u03Ft7bEBAJqRS-86WXCg"; when(request.getHeader(AUTHORIZATION)).thenReturn(token); when(request.getRemoteAddr()).thenReturn("localhost"); SecurityContext context = mock(SecurityContext.class); when(securityAppContext.getContext()).thenReturn(context); when(context.getAuthentication()).thenReturn(null); User u = new User("username", "pass", "salt", "role"); when(userService.validateUser("eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiJ9.GE2q1gX6T-mcjf0xmIlGru1gzu-PQF1leFK4U3Kphj8ZLpQG3Rn8qyLLO38ilyvP2u03Ft7bEBAJqRS-86WXCg", request.getRemoteAddr())).thenReturn(u); Authentication authentication = mock(UsernamePasswordAuthenticationToken.class); when(usernamePasswordAuthenticationTokenFactory.create(u)).thenReturn((UsernamePasswordAuthenticationToken) authentication); jwtAuthenticationTokenFilter.doFilterInternal(request, response, chain); verify(context).setAuthentication(authentication); verify(chain).doFilter(request, response); } |
UserService { public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; } void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); } | @Test public void testIsLoginValidEmptyParams() { assertNull(userService.isLoginValid(null, null) ); assertNull(userService.isLoginValid("", null)); assertNull(userService.isLoginValid(null, "")); verifyZeroInteractions(userRepository, shaPasswordEncoder); } |
AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug("Authentication Successful"); User u = userService.createUserToken(authentication.getName(), request.getRemoteAddr()); response.getWriter().print("{ \"token\" : \"" + u.getToken() + "\"}"); response.setStatus(HttpServletResponse.SC_OK); headerHandler.process(request, response); } @Override void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication); } | @Test public void testOnAuthenticationSuccess() throws IOException, ServletException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); Authentication authentication = mock(Authentication.class); when(authentication.getName()).thenReturn("name"); when(request.getRemoteAddr()).thenReturn("localhost"); PrintWriter printWriter = mock(PrintWriter.class); when(response.getWriter()).thenReturn(printWriter); String token = "token"; User u = new User("usernma", "pass", "salt", "role"); u.setToken("token"); when(userService.createUserToken(authentication.getName(), request.getRemoteAddr())).thenReturn(u); ajaxAuthenticationSuccessHandler.onAuthenticationSuccess(request, response, authentication); verify(response).setStatus(HttpServletResponse.SC_OK); verify(headerHandler).process(request, response); verify(userService).createUserToken(authentication.getName(), request.getRemoteAddr()) ; verify(printWriter).print("{ \"token\" : \"" + u.getToken() + "\"}"); } |
HeaderHandler { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } } void process(HttpServletRequest request, HttpServletResponse response); } | @Test public void testProcess() throws IOException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getMethod()).thenReturn(OPTIONS); PrintWriter printWriter = mock(PrintWriter.class); when(response.getWriter()).thenReturn(printWriter); headerHandler.process(request, response); verify(response).setHeader(ALLOW_ORIGIN, STAR); verify(response).setHeader(ALLOW_CREDENTIALS, TRUE); verify(response).setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); verify(printWriter).print(OK); verify(printWriter).flush(); }
@Test public void testProcessMethodGet() throws IOException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getMethod()).thenReturn("GET"); PrintWriter printWriter = mock(PrintWriter.class); when(response.getWriter()).thenReturn(printWriter); headerHandler.process(request, response); verify(response).setHeader(ALLOW_ORIGIN, STAR); verify(response).setHeader(ALLOW_CREDENTIALS, TRUE); verify(response).setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); verify(printWriter, never()).print(OK); verify(printWriter, never()).flush(); } |
Http401UnauthorizedEntryPoint implements AuthenticationEntryPoint { public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2) throws IOException,ServletException { LOGGER.debug("Pre-authenticated entry point called. Rejecting access:" + request.getRequestURL()); headerHandler.process(request, response); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied"); } void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2); } | @Test public void testCommence() throws IOException, ServletException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); AuthenticationException authenticationException = mock(AuthenticationException.class); http401UnauthorizedEntryPoint.commence(request, response, authenticationException); verify(response).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied"); verify(headerHandler).process(request, response); } |
AjaxAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { headerHandler.process(request, response); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed"); } @Override void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception); } | @Test public void testOnAuthenticationFailure() throws IOException, ServletException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); AuthenticationException exception = mock(AuthenticationException.class); ajaxAuthenticationFailureHandler.onAuthenticationFailure(request, response, exception); verifyZeroInteractions(request, exception); verify(response).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed"); verify(headerHandler).process(request, response); } |
AjaxLogoutSuccessHandler extends AbstractAuthenticationTargetUrlRequestHandler implements LogoutSuccessHandler { @Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { if (authentication != null && authentication.getDetails() != null) { try { headerHandler.process(request, response); request.getSession().invalidate(); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } } @Override void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication); } | @Test public void testOnLogoutSuccess() throws IOException, ServletException { ajaxLogoutSuccessHandler.onLogoutSuccess(request, response, authentication); verify(request).getSession(); verify(httpSession).invalidate(); verify(response).setStatus(HttpServletResponse.SC_OK); verify(headerHandler).process(request, response); verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }
@Test public void testOnLogoutSuccessNullAuthenticationDetails() throws IOException, ServletException { when(authentication.getDetails()).thenReturn(null); ajaxLogoutSuccessHandler.onLogoutSuccess(request, response, authentication); verify(request, never()).getSession(); verify(httpSession, never()).invalidate(); verify(response, never()).setStatus(HttpServletResponse.SC_OK); verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); verifyZeroInteractions(request, response); }
@Test public void testOnLogoutSuccessNullAuthentication() throws IOException, ServletException { ajaxLogoutSuccessHandler.onLogoutSuccess(request, response, null); verify(request, never()).getSession(); verify(httpSession, never()).invalidate(); verify(response, never()).setStatus(HttpServletResponse.SC_OK); verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); verifyZeroInteractions(request, response); }
@Test public void testOnLogoutSuccessException() throws IOException, ServletException { doThrow(new NullPointerException()).when(request).getSession(); ajaxLogoutSuccessHandler.onLogoutSuccess(request, response, authentication); verify(httpSession, never()).invalidate(); verify(response, never()).setStatus(HttpServletResponse.SC_OK); verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } |
UserService { public User findByUsername(String username) { return userRepository.findByUsername(username); } void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); } | @Test public void testFindByUsername() { User u = new User(USERNAME, PASS, SALT, ROLE); when(userRepository.findByUsername(USERNAME)).thenReturn(u); assertEquals(u, userService.findByUsername(USERNAME)); } |
SecurityAppContext { public SecurityContext getContext() { return SecurityContextHolder.getContext(); } SecurityContext getContext(); } | @Test public void testContext() { assertNotNull(securityAppContext.getContext()); } |
HelloController { @RequestMapping("/") public String index() { return "It is working!"; } @RequestMapping("/") String index(); } | @Test public void index() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(equalTo("It is working!"))); } |
StringSupport { public String generate() { return UUID.randomUUID().toString(); } String generate(); } | @Test public void testGenerate() { StringSupport stringSupport = new StringSupport(); assertNotNull(stringSupport.generate()); assertTrue(stringSupport.generate().length() > 0); } |
DateGenerator { public Date getExpirationDate() { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_WEEK, 1); return c.getTime(); } Date getExpirationDate(); } | @Test public void testExpirationDate() { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_WEEK, 1); DateGenerator dateGenerator = new DateGenerator(); Calendar c2 = Calendar.getInstance(); c2.setTime(dateGenerator.getExpirationDate()); assertEquals(c.get(Calendar.DAY_OF_WEEK), c2.get(Calendar.DAY_OF_WEEK)); assertEquals(c.get(Calendar.DAY_OF_MONTH), c2.get(Calendar.DAY_OF_MONTH)); assertEquals(c.get(Calendar.MONTH), c2.get(Calendar.MONTH)); assertEquals(c.get(Calendar.YEAR), c2.get(Calendar.YEAR)); assertEquals(c.get(Calendar.HOUR_OF_DAY), c2.get(Calendar.HOUR_OF_DAY)); } |
UserService { public User createUserToken(String username, String secret) { String token = jwtService.createToken(username, secret, dateGenerator.getExpirationDate()); User u = userRepository.findByUsername(username); u.setToken(token); return userRepository.save(u); } void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); } | @Test public void testCreateUserToken() { User u = new User(USERNAME, ENCODED_PASS, SALT, ROLE); when(jwtService.createToken(USERNAME, SECRET, date)).thenReturn(TOKEN); when(userRepository.findByUsername(USERNAME)).thenReturn(u); when(userRepository.save(u)).thenReturn(u); User u2 = userService.createUserToken(USERNAME, SECRET); verify(userRepository).save(u); assertEquals(TOKEN, u2.getToken()); } |
UserService { public User validateUser(String token, String secret) { String username = jwtService.getUsername(token, secret); if (username != null ) { User user = userRepository.findByUsername(username); if (user != null && token.equals(user.getToken()) && jwtService.isValid(token, secret)) { return user; } } return null; } void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); } | @Test public void testValidateUserNullUsername() { when(jwtService.getUsername(TOKEN, SECRET)).thenReturn(null); assertNull(userService.validateUser(TOKEN, SECRET)); } |
WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(authProvider); } @Bean ShaPasswordEncoder sha(); } | @Test public void testConfigure() throws Exception { AuthenticationManagerBuilder auth = mock(AuthenticationManagerBuilder.class); webSecurityConfig.configure(auth); verify(auth).authenticationProvider(authProvider); } |
WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public ShaPasswordEncoder sha() { ShaPasswordEncoder shaPasswordEncoder = new ShaPasswordEncoder(256); return shaPasswordEncoder; } @Bean ShaPasswordEncoder sha(); } | @Test public void testPasswordEncoder() { assertNotNull(webSecurityConfig.sha()); assertEquals("SHA-256", webSecurityConfig.sha().getAlgorithm()); } |
AuthProviderService implements AuthenticationProvider { @Override public boolean supports(Class<?> aClass) { return aClass.equals(UsernamePasswordAuthenticationToken.class); } @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> aClass); } | @Test public void testSupports() { assertFalse(authProviderService.supports(String.class)); assertTrue(authProviderService.supports(UsernamePasswordAuthenticationToken.class)); } |
FirstPresenter { public void attach(FirstFragment fragment) { firstFragment = fragment; firstFragment.initialize(text); } void attach(FirstFragment fragment); boolean hasView(); void detach(FirstFragment fragment); void updateText(String text); void restore(StateBundle stateBundle); StateBundle persist(); } | @Test public void attach() throws Exception { firstPresenter.updateText(TEST_VALUE); firstPresenter.attach(firstFragment); Mockito.verify(firstFragment, Mockito.only()).initialize(TEST_VALUE); } |
StateBundle implements Parcelable { public float getFloat(@Nonnull String key) { return getFloat(key, 0.0f); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetFloatReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getFloat("key")).isEqualTo(0.0f); } |
StateBundle implements Parcelable { public double getDouble(@Nonnull String key) { return getDouble(key, 0.0); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetDoubleReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getDouble("key")).isEqualTo(0.0); } |
StateBundle implements Parcelable { @Nullable public String getString(@Nullable String key) { final Object o = map.get(key); try { return (String) o; } catch(ClassCastException e) { typeWarning(key, o, "String", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetStringReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getString("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public CharSequence getCharSequence(@Nullable String key) { final Object o = map.get(key); try { return (CharSequence) o; } catch(ClassCastException e) { typeWarning(key, o, "CharSequence", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetCharSequenceReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getCharSequence("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public Serializable getSerializable(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (Serializable) o; } catch(ClassCastException e) { typeWarning(key, o, "Serializable", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetSerializableReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getSerializable("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public ArrayList<Integer> getIntegerArrayList(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (ArrayList<Integer>) o; } catch(ClassCastException e) { typeWarning(key, o, "ArrayList<Integer>", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetIntegerArrayListReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getIntegerArrayList("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public ArrayList<String> getStringArrayList(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (ArrayList<String>) o; } catch(ClassCastException e) { typeWarning(key, o, "ArrayList<String>", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetStringArrayListReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getStringArrayList("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (ArrayList<CharSequence>) o; } catch(ClassCastException e) { typeWarning(key, o, "ArrayList<CharSequence>", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetCharSequenceArrayListReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getCharSequenceArrayList("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public boolean[] getBooleanArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (boolean[]) o; } catch(ClassCastException e) { typeWarning(key, o, "byte[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetBooleanArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getBooleanArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public byte[] getByteArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (byte[]) o; } catch(ClassCastException e) { typeWarning(key, o, "byte[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetByteArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getByteArray("key")).isNull(); } |
FirstPresenter { public void detach(FirstFragment fragment) { this.firstFragment = null; } void attach(FirstFragment fragment); boolean hasView(); void detach(FirstFragment fragment); void updateText(String text); void restore(StateBundle stateBundle); StateBundle persist(); } | @Test public void detach() throws Exception { firstPresenter.updateText(TEST_VALUE); firstPresenter.attach(firstFragment); Mockito.verify(firstFragment, Mockito.only()).initialize(TEST_VALUE); assertThat(firstPresenter.hasView()).isTrue(); firstPresenter.detach(firstFragment); firstPresenter.updateText("BLAH"); Mockito.verify(firstFragment, Mockito.only()).initialize(TEST_VALUE); assertThat(firstPresenter.hasView()).isFalse(); } |
StateBundle implements Parcelable { @Nullable public short[] getShortArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (short[]) o; } catch(ClassCastException e) { typeWarning(key, o, "short[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetShortArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getShortArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public char[] getCharArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (char[]) o; } catch(ClassCastException e) { typeWarning(key, o, "char[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetCharArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getCharArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public int[] getIntArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (int[]) o; } catch(ClassCastException e) { typeWarning(key, o, "int[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetIntArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getIntArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public long[] getLongArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (long[]) o; } catch(ClassCastException e) { typeWarning(key, o, "long[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetLongArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getLongArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public float[] getFloatArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (float[]) o; } catch(ClassCastException e) { typeWarning(key, o, "float[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetFloatArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getFloatArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public double[] getDoubleArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (double[]) o; } catch(ClassCastException e) { typeWarning(key, o, "double[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetDoubleArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getDoubleArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public String[] getStringArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (String[]) o; } catch(ClassCastException e) { typeWarning(key, o, "String[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetStringArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getStringArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public CharSequence[] getCharSequenceArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (CharSequence[]) o; } catch(ClassCastException e) { typeWarning(key, o, "CharSequence[]", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetCharSequenceArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getCharSequenceArray("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public StateBundle getBundle(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (StateBundle) o; } catch(ClassCastException e) { typeWarning(key, o, "Bundle", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetStateBundleReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getBundle("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public <T extends Parcelable> T getParcelable(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (T) o; } catch(ClassCastException e) { typeWarning(key, o, "Parcelable", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetParcelableReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getParcelable("key")).isNull(); } |
FirstPresenter { public StateBundle persist() { StateBundle stateBundle = new StateBundle(); stateBundle.putString(TEXT, text); return stateBundle; } void attach(FirstFragment fragment); boolean hasView(); void detach(FirstFragment fragment); void updateText(String text); void restore(StateBundle stateBundle); StateBundle persist(); } | @Test public void persist() throws Exception { firstPresenter.updateText(TEST_VALUE); StateBundle stateBundle = firstPresenter.persist(); assertThat(stateBundle.getString(FirstPresenter.TEXT)).isEqualTo(TEST_VALUE); } |
StateBundle implements Parcelable { @Nullable public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (ArrayList<T>) o; } catch(ClassCastException e) { typeWarning(key, o, "ArrayList", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetParcelableArrayListReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getParcelableArrayList("key")).isNull(); } |
StateBundle implements Parcelable { @Nullable public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) { Object o = map.get(key); if(o == null) { return null; } try { return (SparseArray<T>) o; } catch(ClassCastException e) { typeWarning(key, o, "SparseArray", e); return null; } } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetSparseParcelableArrayReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getSparseParcelableArray("key")).isNull(); } |
StateBundle implements Parcelable { @Override public int hashCode() { int result = 0; Set<Map.Entry<String, Object>> entrySet = map.entrySet(); for(Map.Entry<String, Object> entry : entrySet) { result += 31 * entry.getKey().hashCode(); Integer type = typeMap.get(entry.getKey()); if(type == null) { throw new IllegalStateException("Unexpected null in hashCode for [" + entry.getKey() + "]"); } if(entry.getValue() == null) { result += 0; } else if(type == type_BooleanArray) { result += 31 * (Arrays.hashCode((boolean[]) entry.getValue())); } else if(type == type_ByteArray) { result += 31 * (Arrays.hashCode((byte[]) entry.getValue())); } else if(type == type_ShortArray) { result += 31 * (Arrays.hashCode((short[]) entry.getValue())); } else if(type == type_CharArray) { result += 31 * (Arrays.hashCode((char[]) entry.getValue())); } else if(type == type_IntArray) { result += 31 * (Arrays.hashCode((int[]) entry.getValue())); } else if(type == type_LongArray) { result += 31 * (Arrays.hashCode((long[]) entry.getValue())); } else if(type == type_FloatArray) { result += 31 * (Arrays.hashCode((float[]) entry.getValue())); } else if(type == type_DoubleArray) { result += 31 * (Arrays.hashCode((double[]) entry.getValue())); } else if(type == type_StringArray) { result += 31 * (Arrays.hashCode((String[]) entry.getValue())); } else if(type == type_CharSequenceArray) { result += 31 * (Arrays.hashCode((CharSequence[]) entry.getValue())); } else if(type == type_ParcelableArray) { result += 31 * (Arrays.hashCode((Parcelable[]) entry.getValue())); } else { result += 31 * entry.getValue().hashCode(); } } return result; } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testEqualsWorks() { StateBundle stateBundle = new StateBundle(); StateBundle stateBundle1 = new StateBundle(); setupStateBundle(stateBundle); setupStateBundle(stateBundle1); assertThat(stateBundle).isEqualTo(stateBundle1); assertThat(stateBundle.hashCode()).isEqualTo(stateBundle1.hashCode()); }
@Test public void equalsTrueWorks() { StateBundle stateBundle = new StateBundle(); StateBundle stateBundle1 = new StateBundle(); setupStateBundle(stateBundle); setupStateBundle(stateBundle1); assertThat(stateBundle).isEqualTo(stateBundle1); assertThat(stateBundle.hashCode()).isEqualTo(stateBundle1.hashCode()); } |
StateBundle implements Parcelable { @Nonnull public StateBundle putString(@Nullable String key, @Nullable String value) { map.put(key, value); typeMap.put(key, type_String); return this; } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void equalsTrueWorksInDifferentOrder() { StateBundle stateBundle = new StateBundle(); StateBundle stateBundle1 = new StateBundle(); stateBundle.putString("hello", "world"); stateBundle.putString("world", "world"); stateBundle1.putString("world", "world"); stateBundle1.putString("hello", "world"); assertThat(stateBundle).isEqualTo(stateBundle1); } |
FirstPresenter { public void restore(StateBundle stateBundle) { this.text = stateBundle.getString(TEXT); } void attach(FirstFragment fragment); boolean hasView(); void detach(FirstFragment fragment); void updateText(String text); void restore(StateBundle stateBundle); StateBundle persist(); } | @Test public void restore() throws Exception { firstPresenter.updateText(""); StateBundle stateBundle = new StateBundle(); stateBundle.putString(FirstPresenter.TEXT, TEST_VALUE); firstPresenter.restore(stateBundle); firstPresenter.attach(firstFragment); Mockito.verify(firstFragment).initialize(TEST_VALUE); } |
StateBundle implements Parcelable { public boolean getBoolean(@Nonnull String key) { return getBoolean(key, false); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetBooleanReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getBoolean("key")).isFalse(); } |
StateBundle implements Parcelable { public byte getByte(@Nonnull String key) { return getByte(key, (byte) 0); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetByteReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getByte("key")).isEqualTo((byte) 0); } |
StateBundle implements Parcelable { public char getChar(@Nonnull String key) { return getChar(key, (char) 0); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetCharReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getChar("key")).isEqualTo((char) 0); } |
StateBundle implements Parcelable { public short getShort(@Nonnull String key) { return getShort(key, (short) 0); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetShortReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getShort("key")).isEqualTo((short) 0); } |
StateBundle implements Parcelable { public int getInt(@Nonnull String key) { return getInt(key, 0); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetIntReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getInt("key")).isEqualTo(0); } |
StateBundle implements Parcelable { public long getLong(@Nonnull String key) { return getLong(key, 0L); } StateBundle(); StateBundle(@Nonnull StateBundle bundle); StateBundle(Parcel in); int size(); boolean isEmpty(); @Nonnull StateBundle clear(); boolean containsKey(String key); @Nullable Object get(String key); @Nonnull StateBundle remove(String key); @Nonnull StateBundle putAll(@Nonnull StateBundle bundle); @Nonnull Set<String> keySet(); @Nonnull StateBundle putBoolean(@Nullable String key, boolean value); @Nonnull StateBundle putByte(@Nullable String key, byte value); @Nonnull StateBundle putChar(@Nullable String key, char value); @Nonnull StateBundle putShort(@Nullable String key, short value); @Nonnull StateBundle putInt(@Nullable String key, int value); @Nonnull StateBundle putLong(@Nullable String key, long value); @Nonnull StateBundle putFloat(@Nullable String key, float value); @Nonnull StateBundle putDouble(@Nullable String key, double value); @Nonnull StateBundle putString(@Nullable String key, @Nullable String value); @Nonnull StateBundle putCharSequence(@Nullable String key, @Nullable CharSequence value); @Nonnull StateBundle putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value); @Nonnull StateBundle putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value); @Nonnull StateBundle putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList<CharSequence> value); @Nonnull StateBundle putSerializable(@Nullable String key, @Nullable Serializable value); @Nonnull StateBundle putBooleanArray(@Nullable String key, @Nullable boolean[] value); @Nonnull StateBundle putByteArray(@Nullable String key, @Nullable byte[] value); @Nonnull StateBundle putShortArray(@Nullable String key, @Nullable short[] value); @Nonnull StateBundle putCharArray(@Nullable String key, @Nullable char[] value); @Nonnull StateBundle putIntArray(@Nullable String key, @Nullable int[] value); @Nonnull StateBundle putLongArray(@Nullable String key, @Nullable long[] value); @Nonnull StateBundle putFloatArray(@Nullable String key, @Nullable float[] value); @Nonnull StateBundle putDoubleArray(@Nullable String key, @Nullable double[] value); @Nonnull StateBundle putStringArray(@Nullable String key, @Nullable String[] value); @Nonnull StateBundle putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value); @Nonnull StateBundle putParcelable(@Nullable String key, @Nullable Parcelable value); @Nonnull StateBundle putParcelableArray(@Nullable String key, @Nullable Parcelable[] value); @Nonnull StateBundle putParcelableArrayList(@Nullable String key, @Nullable ArrayList<? extends Parcelable> value); @Nonnull StateBundle putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value); @Nonnull StateBundle putBundle(@Nullable String key, @Nullable StateBundle value); boolean getBoolean(@Nonnull String key); boolean getBoolean(@Nonnull String key, boolean defaultValue); byte getByte(@Nonnull String key); @Nonnull Byte getByte(@Nonnull String key, byte defaultValue); char getChar(@Nonnull String key); char getChar(@Nonnull String key, char defaultValue); short getShort(@Nonnull String key); short getShort(@Nonnull String key, short defaultValue); int getInt(@Nonnull String key); int getInt(@Nonnull String key, int defaultValue); long getLong(@Nonnull String key); long getLong(@Nonnull String key, long defaultValue); float getFloat(@Nonnull String key); float getFloat(@Nonnull String key, float defaultValue); double getDouble(@Nonnull String key); double getDouble(@Nonnull String key, double defaultValue); @Nullable String getString(@Nullable String key); @Nonnull String getString(@Nullable String key, @Nonnull String defaultValue); @Nullable CharSequence getCharSequence(@Nullable String key); @Nonnull CharSequence getCharSequence(@Nullable String key, @Nonnull CharSequence defaultValue); @Nullable Serializable getSerializable(@Nullable String key); @Nullable ArrayList<Integer> getIntegerArrayList(@Nullable String key); @Nullable ArrayList<String> getStringArrayList(@Nullable String key); @Nullable ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key); @Nullable boolean[] getBooleanArray(@Nullable String key); @Nullable byte[] getByteArray(@Nullable String key); @Nullable short[] getShortArray(@Nullable String key); @Nullable char[] getCharArray(@Nullable String key); @Nullable int[] getIntArray(@Nullable String key); @Nullable long[] getLongArray(@Nullable String key); @Nullable float[] getFloatArray(@Nullable String key); @Nullable double[] getDoubleArray(@Nullable String key); @Nullable String[] getStringArray(@Nullable String key); @Nullable CharSequence[] getCharSequenceArray(@Nullable String key); @Nullable StateBundle getBundle(@Nullable String key); @Nullable T getParcelable(@Nullable String key); @Nullable Parcelable[] getParcelableArray(@Nullable String key); @Nullable ArrayList<T> getParcelableArrayList(@Nullable String key); @Nullable SparseArray<T> getSparseParcelableArray(@Nullable String key); void copyToBundle(@Nonnull Bundle bundle); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final Creator<StateBundle> CREATOR; } | @Test public void testGetLongReturnsDefault() { StateBundle stateBundle = new StateBundle(); assertThat(stateBundle.getLong("key")).isEqualTo(0); } |
And extends BinaryProp { @Override public Boolean eval(Context m) { Boolean r1 = p1.eval(m); Boolean r2 = p2.eval(m); if (r1 == null || r2 == null) { return null; } if (!r1) { return false; } return r2; } And(Proposition p1, Proposition p2); @Override String operator(); @Override Or not(); @Override Boolean eval(Context m); @Override String toString(); } | @Test(dataProvider = "input") public void testTruthTable(Proposition a, Proposition b, Boolean r) { And p = new And(a, b); Assert.assertEquals(p.eval(new Context()), r); } |
Ban extends SimpleConstraint { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Ban ban = (Ban) o; return isContinuous() == ban.isContinuous() && Objects.equals(vm, ban.vm) && nodes.size() == ban.nodes.size() && nodes.containsAll(ban.nodes) && ban.nodes.containsAll(nodes); } Ban(VM vm, Collection<Node> nodes); Ban(VM vm, Collection<Node> nodes, boolean continuous); Ban(VM vm, final Node node); @Override Collection<Node> getInvolvedNodes(); @Override Collection<VM> getInvolvedVMs(); @Override String toString(); @Override BanChecker getChecker(); static List<Ban> newBan(Collection<VM> vms, Collection<Node> nodes); @Override boolean equals(Object o); @Override int hashCode(); } | @Test public void testEquals() { Model m = new DefaultModel(); VM v = m.newVM(); List<Node> ns = Util.newNodes(m, 10); Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1))); Ban b = new Ban(v, nodes); Assert.assertTrue(b.equals(b)); Assert.assertTrue(new Ban(v, nodes).equals(b)); Assert.assertEquals(new Ban(v, nodes).hashCode(), b.hashCode()); Assert.assertNotEquals(new Ban(m.newVM(), nodes), b); } |
DefaultModel implements Model { @Override public void clearViews() { this.resources.clear(); } DefaultModel(); DefaultModel(ElementBuilder eb); @Override ModelView getView(String id); @Override boolean attach(ModelView v); @Override Collection<ModelView> getViews(); @Override Mapping getMapping(); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean detach(ModelView v); @Override void clearViews(); @Override Attributes getAttributes(); @Override void setAttributes(Attributes a); @Override Model copy(); @Override String toString(); @Override VM newVM(); @Override VM newVM(int id); @Override Node newNode(); @Override Node newNode(int id); @Override boolean contains(VM v); @Override boolean contains(Node n); } | @Test(dependsOnMethods = {"testAttachView", "testInstantiate"}) public void testClearViews() { Model i = new DefaultModel(); ModelView v1 = mock(ModelView.class); when(v1.getIdentifier()).thenReturn("cpu"); ModelView v2 = mock(ModelView.class); when(v2.getIdentifier()).thenReturn("mem"); i.attach(v1); i.attach(v2); i.clearViews(); Assert.assertTrue(i.getViews().isEmpty()); } |
SynchronizedElementBuilder implements ElementBuilder { @Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } } SynchronizedElementBuilder(ElementBuilder b); @Override VM newVM(); @Override VM newVM(int id); @Override Node newNode(); @Override Node newNode(int id); @Override boolean contains(VM v); @Override boolean contains(Node n); @Override ElementBuilder copy(); } | @Test public void testMultipleIDDemand() { final ElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder()); int nbThreads = 10; final int nbAllocs = 1000; final int[] used = new int[nbThreads * nbAllocs]; Thread[] ths = new Thread[nbThreads]; for (int i = 0; i < nbThreads; i++) { Thread t = new Thread(() -> { for (int x = 0; x < nbAllocs; x++) { VM v = eb.newVM(); used[v.id()]++; } }); ths[i] = t; t.start(); } try { for (int i = 0; i < nbThreads; i++) { ths[i].join(); } } catch (InterruptedException ex) { Assert.fail(ex.getMessage(), ex); } for (int i = 0; i < used.length; i++) { if (used[i] != 1) { Assert.fail("ID '" + i + "' used " + used[i] + " times"); } } } |
ShareableResource implements ModelView { public static ShareableResource get(Model mo, String id) { return (ShareableResource) mo.getView(VIEW_ID_BASE + id); } ShareableResource(String r); ShareableResource(String id, int defCapacity, int defConsumption); int getConsumption(VM vm); int getCapacity(Node n); Set<VM> getDefinedVMs(); Set<Node> getDefinedNodes(); ShareableResource setConsumption(VM vm, int val); ShareableResource setConsumption(int val, VM... vms); ShareableResource setCapacity(Node n, int val); ShareableResource setCapacity(int val, Node... nodes); void unset(VM vm); void unset(Node n); void unset(VM... vms); void unset(Node... nodes); boolean consumptionDefined(VM vm); boolean capacityDefined(Node n); @Override String getIdentifier(); static String getIdentifier(String rcId); String getResourceIdentifier(); int getDefaultConsumption(); int getDefaultCapacity(); @Override boolean equals(Object o); @Override int hashCode(); @Override ShareableResource copy(); @Override String toString(); @Override boolean substituteVM(VM oldRef, VM newRef); int sumConsumptions(Collection<VM> ids, boolean undef); int sumCapacities(Collection<Node> ids, boolean undef); static ShareableResource get(Model mo, String id); static final String VIEW_ID_BASE; static final int DEFAULT_NO_VALUE; } | @Test public void testGet() { Model mo = new DefaultModel(); Assert.assertNull(ShareableResource.get(mo, "cpu")); ShareableResource cpu = new ShareableResource("cpu"); ShareableResource mem = new ShareableResource("mem"); mo.attach(cpu); Assert.assertEquals(ShareableResource.get(mo, "cpu"), cpu); Assert.assertNull(ShareableResource.get(mo, "mem")); mo.attach(mem); Assert.assertEquals(ShareableResource.get(mo, "cpu"), cpu); Assert.assertEquals(ShareableResource.get(mo, "mem"), mem); } |
ShareableResource implements ModelView { public void unset(VM vm) { vmsConsumption.remove(vm); } ShareableResource(String r); ShareableResource(String id, int defCapacity, int defConsumption); int getConsumption(VM vm); int getCapacity(Node n); Set<VM> getDefinedVMs(); Set<Node> getDefinedNodes(); ShareableResource setConsumption(VM vm, int val); ShareableResource setConsumption(int val, VM... vms); ShareableResource setCapacity(Node n, int val); ShareableResource setCapacity(int val, Node... nodes); void unset(VM vm); void unset(Node n); void unset(VM... vms); void unset(Node... nodes); boolean consumptionDefined(VM vm); boolean capacityDefined(Node n); @Override String getIdentifier(); static String getIdentifier(String rcId); String getResourceIdentifier(); int getDefaultConsumption(); int getDefaultCapacity(); @Override boolean equals(Object o); @Override int hashCode(); @Override ShareableResource copy(); @Override String toString(); @Override boolean substituteVM(VM oldRef, VM newRef); int sumConsumptions(Collection<VM> ids, boolean undef); int sumCapacities(Collection<Node> ids, boolean undef); static ShareableResource get(Model mo, String id); static final String VIEW_ID_BASE; static final int DEFAULT_NO_VALUE; } | @Test(dependsOnMethods = {"testInstantiation", "testDefinition"}) public void testUnset() { ShareableResource rc = new ShareableResource("foo"); rc.setConsumption(vms.get(0), 3); rc.unset(vms.get(0)); Assert.assertFalse(rc.consumptionDefined(vms.get(0))); rc.setCapacity(nodes.get(0), 3); rc.unset(nodes.get(0)); Assert.assertFalse(rc.capacityDefined(nodes.get(0))); rc.unset(nodes.get(0)); rc.unset(nodes.toArray(new Node[0])); rc.unset(vms.toArray(new VM[0])); Assert.assertTrue(rc.getDefinedVMs().isEmpty()); Assert.assertTrue(rc.getDefinedNodes().isEmpty()); } |
ShareableResource implements ModelView { @Override public String toString() { StringJoiner joiner = new StringJoiner(",", String.format("rc:%s:", rcId), ""); for (Node n: nodesCapacity.keySet()) { int c = nodesCapacity.get(n); joiner.add(String.format("<node %s,%d>", n, c)); } StringJoiner vmJoiner = new StringJoiner(","); for (VM vm: vmsConsumption.keySet()) { int c = vmsConsumption.get(vm); vmJoiner.add(String.format("<VM %s,%d>", vm, c)); } return String.format("%s%s", joiner, vmJoiner); } ShareableResource(String r); ShareableResource(String id, int defCapacity, int defConsumption); int getConsumption(VM vm); int getCapacity(Node n); Set<VM> getDefinedVMs(); Set<Node> getDefinedNodes(); ShareableResource setConsumption(VM vm, int val); ShareableResource setConsumption(int val, VM... vms); ShareableResource setCapacity(Node n, int val); ShareableResource setCapacity(int val, Node... nodes); void unset(VM vm); void unset(Node n); void unset(VM... vms); void unset(Node... nodes); boolean consumptionDefined(VM vm); boolean capacityDefined(Node n); @Override String getIdentifier(); static String getIdentifier(String rcId); String getResourceIdentifier(); int getDefaultConsumption(); int getDefaultCapacity(); @Override boolean equals(Object o); @Override int hashCode(); @Override ShareableResource copy(); @Override String toString(); @Override boolean substituteVM(VM oldRef, VM newRef); int sumConsumptions(Collection<VM> ids, boolean undef); int sumCapacities(Collection<Node> ids, boolean undef); static ShareableResource get(Model mo, String id); static final String VIEW_ID_BASE; static final int DEFAULT_NO_VALUE; } | @Test(dependsOnMethods = {"testInstantiation", "testDefinition"}) public void testToString() { ShareableResource rc = new ShareableResource("foo"); rc.setConsumption(vms.get(0), 1); rc.setConsumption(vms.get(1), 2); rc.setConsumption(vms.get(2), 3); Assert.assertNotNull(rc.toString()); } |
ShareableResource implements ModelView { @Override public int hashCode() { return Objects.hash(rcId, vmsConsumption, nodesCapacity); } ShareableResource(String r); ShareableResource(String id, int defCapacity, int defConsumption); int getConsumption(VM vm); int getCapacity(Node n); Set<VM> getDefinedVMs(); Set<Node> getDefinedNodes(); ShareableResource setConsumption(VM vm, int val); ShareableResource setConsumption(int val, VM... vms); ShareableResource setCapacity(Node n, int val); ShareableResource setCapacity(int val, Node... nodes); void unset(VM vm); void unset(Node n); void unset(VM... vms); void unset(Node... nodes); boolean consumptionDefined(VM vm); boolean capacityDefined(Node n); @Override String getIdentifier(); static String getIdentifier(String rcId); String getResourceIdentifier(); int getDefaultConsumption(); int getDefaultCapacity(); @Override boolean equals(Object o); @Override int hashCode(); @Override ShareableResource copy(); @Override String toString(); @Override boolean substituteVM(VM oldRef, VM newRef); int sumConsumptions(Collection<VM> ids, boolean undef); int sumCapacities(Collection<Node> ids, boolean undef); static ShareableResource get(Model mo, String id); static final String VIEW_ID_BASE; static final int DEFAULT_NO_VALUE; } | @Test(dependsOnMethods = {"testInstantiation"}) public void testEqualsAndHashCode() { ShareableResource rc1 = new ShareableResource("foo"); ShareableResource rc2 = new ShareableResource("foo"); ShareableResource rc3 = new ShareableResource("bar"); Assert.assertEquals(rc1, rc2); Assert.assertEquals(rc2, rc2); Assert.assertEquals(rc1.hashCode(), rc2.hashCode()); Assert.assertNotEquals(rc1, rc3); Assert.assertNotEquals(rc3, rc2); Assert.assertNotEquals(rc1.hashCode(), rc3.hashCode()); Assert.assertNotEquals(rc1, "foo"); } |
VMConsumptionComparator implements Comparator<VM> { public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; } VMConsumptionComparator(ShareableResource rc); VMConsumptionComparator(ShareableResource rc, boolean asc); VMConsumptionComparator append(ShareableResource r, boolean asc); @Override int compare(VM v1, VM v2); } | @Test(dependsOnMethods = {"testSimpleResource"}) public void testCombination() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 7); ShareableResource rc = new ShareableResource("foo"); for (int i = 0; i < 4; i++) { rc.setConsumption(vms.get(i), i); } rc.setConsumption(vms.get(4), 2); rc.setConsumption(vms.get(5), 2); rc.setConsumption(vms.get(6), 3); ShareableResource rc2 = new ShareableResource("bar"); for (int i = 0; i < 4; i++) { rc2.setConsumption(vms.get(i), i / 2); } rc2.setConsumption(vms.get(4), 1); rc2.setConsumption(vms.get(5), 3); rc2.setConsumption(vms.get(6), 3); VMConsumptionComparator c1 = new VMConsumptionComparator(rc, true); c1.append(rc2, false); vms.sort(c1); for (int i = 0; i < vms.size() - 1; i++) { VM id = vms.get(i); Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1))); if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) { Assert.assertTrue(rc2.getConsumption(id) >= rc2.getConsumption(vms.get(i + 1))); } } c1 = new VMConsumptionComparator(rc, true); c1.append(rc2, true); vms.sort(c1); for (int i = 0; i < vms.size() - 1; i++) { VM id = vms.get(i); Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1))); if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) { Assert.assertTrue(rc2.getConsumption(id) <= rc2.getConsumption(vms.get(i + 1))); } } } |
DefaultMapping extends AbstractMapping { @Override public String toString() { StringBuilder buf = new StringBuilder(); for (Node n : nodeState[ONLINE_STATE]) { buf.append(n); buf.append(':'); if (this.getRunningVMs(n).isEmpty() && this.getSleepingVMs(n).isEmpty()) { buf.append(" - "); } for (VM vm : this.getRunningVMs(n)) { buf.append(' ').append(vm); } for (VM vm : this.getSleepingVMs(n)) { buf.append(" (").append(vm).append(')'); } buf.append('\n'); } for (Node n : nodeState[OFFLINE_STATE]) { buf.append('(').append(n).append(")\n"); } buf.append("READY"); for (VM vm : this.getReadyVMs()) { buf.append(' ').append(vm); } return buf.append('\n').toString(); } @SuppressWarnings("unchecked") DefaultMapping(); DefaultMapping(Mapping m); @Override boolean isRunning(VM v); @Override boolean isSleeping(VM v); @Override boolean isReady(VM v); @Override boolean isOnline(Node n); @Override boolean isOffline(Node n); @Override boolean addRunningVM(VM vm, Node n); @Override boolean addSleepingVM(VM vm, Node n); @Override boolean addReadyVM(VM vm); @Override boolean remove(VM vm); @Override boolean remove(Node n); @Override boolean addOnlineNode(Node n); @Override boolean addOfflineNode(Node n); @Override Set<Node> getOnlineNodes(); @Override Set<Node> getOfflineNodes(); @Override Set<VM> getRunningVMs(); @Override Set<VM> getSleepingVMs(); @Override Set<VM> getSleepingVMs(Node n); @Override Set<VM> getRunningVMs(Node n); @Override Set<VM> getReadyVMs(); @Override Set<VM> getAllVMs(); @Override Set<Node> getAllNodes(); @Override Node getVMLocation(VM vm); @Override Set<VM> getRunningVMs(Collection<Node> ns); @Override Set<VM> getSleepingVMs(Collection<Node> ns); @Override Mapping copy(); @Override boolean contains(Node n); @Override boolean contains(VM vm); @Override void clear(); @Override void clearNode(Node u); @Override void clearAllVMs(); @Override String toString(); @Override int getNbNodes(); @Override int getNbVMs(); } | @Test public void testToString() { Mapping c = new DefaultMapping(); c.addOnlineNode(ns.get(0)); c.addRunningVM(vms.get(0), ns.get(0)); c.addRunningVM(vms.get(1), ns.get(0)); c.addSleepingVM(vms.get(2), ns.get(0)); c.addOnlineNode(ns.get(1)); c.addSleepingVM(vms.get(3), ns.get(1)); c.addSleepingVM(vms.get(4), ns.get(1)); c.addOnlineNode(ns.get(2)); c.addOfflineNode(ns.get(3)); c.addReadyVM(vms.get(5)); c.addReadyVM(vms.get(6)); Assert.assertNotNull(c.toString()); } |
DefaultMapping extends AbstractMapping { @Override public void clear() { for (Set<Node> s : nodeState) { s.clear(); } st.clear(); vmReady.clear(); place.clear(); for (TIntObjectHashMap<Set<VM>> h : host) { h.clear(); } } @SuppressWarnings("unchecked") DefaultMapping(); DefaultMapping(Mapping m); @Override boolean isRunning(VM v); @Override boolean isSleeping(VM v); @Override boolean isReady(VM v); @Override boolean isOnline(Node n); @Override boolean isOffline(Node n); @Override boolean addRunningVM(VM vm, Node n); @Override boolean addSleepingVM(VM vm, Node n); @Override boolean addReadyVM(VM vm); @Override boolean remove(VM vm); @Override boolean remove(Node n); @Override boolean addOnlineNode(Node n); @Override boolean addOfflineNode(Node n); @Override Set<Node> getOnlineNodes(); @Override Set<Node> getOfflineNodes(); @Override Set<VM> getRunningVMs(); @Override Set<VM> getSleepingVMs(); @Override Set<VM> getSleepingVMs(Node n); @Override Set<VM> getRunningVMs(Node n); @Override Set<VM> getReadyVMs(); @Override Set<VM> getAllVMs(); @Override Set<Node> getAllNodes(); @Override Node getVMLocation(VM vm); @Override Set<VM> getRunningVMs(Collection<Node> ns); @Override Set<VM> getSleepingVMs(Collection<Node> ns); @Override Mapping copy(); @Override boolean contains(Node n); @Override boolean contains(VM vm); @Override void clear(); @Override void clearNode(Node u); @Override void clearAllVMs(); @Override String toString(); @Override int getNbNodes(); @Override int getNbVMs(); } | @Test(dependsOnMethods = {"testInstantiation", "testOnlineNode", "testOfflineNode", "testRunningVM", "testWaiting", "testSleeping"}) public void testClear() { Mapping c = new DefaultMapping(); c.addOfflineNode(ns.get(1)); c.addOnlineNode(ns.get(0)); c.addRunningVM(vms.get(0), ns.get(0)); c.addRunningVM(vms.get(1), ns.get(0)); c.addSleepingVM(vms.get(2), ns.get(0)); c.addReadyVM(vms.get(3)); c.clear(); Assert.assertEquals(c.getNbNodes(), 0); Assert.assertEquals(c.getNbVMs(), 0); Assert.assertTrue(c.getAllNodes().isEmpty()); Assert.assertTrue(c.getAllVMs().isEmpty()); Assert.assertTrue(c.getRunningVMs().isEmpty()); Assert.assertTrue(c.getSleepingVMs().isEmpty()); Assert.assertTrue(c.getReadyVMs().isEmpty()); Assert.assertTrue(c.getOnlineNodes().isEmpty()); Assert.assertTrue(c.getOfflineNodes().isEmpty()); Assert.assertTrue(c.getRunningVMs(ns.get(0)).isEmpty()); Assert.assertTrue(c.getSleepingVMs(ns.get(0)).isEmpty()); } |
BanConverter implements ConstraintConverter<Ban> { @Override public String getJSONId() { return "ban"; } @Override Class<Ban> getSupportedConstraint(); @Override String getJSONId(); @Override Ban fromJSON(Model mo, JSONObject o); @Override JSONObject toJSON(Ban o); } | @Test public void testBundle() { Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJavaConstraints().contains(Ban.class)); Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJSONConstraints().contains(new BanConverter().getJSONId())); } |
DefaultMapping extends AbstractMapping { @Override public void clearAllVMs() { place.clear(); st.clear(); vmReady.clear(); for (TIntObjectHashMap<Set<VM>> h : host) { h.clear(); } } @SuppressWarnings("unchecked") DefaultMapping(); DefaultMapping(Mapping m); @Override boolean isRunning(VM v); @Override boolean isSleeping(VM v); @Override boolean isReady(VM v); @Override boolean isOnline(Node n); @Override boolean isOffline(Node n); @Override boolean addRunningVM(VM vm, Node n); @Override boolean addSleepingVM(VM vm, Node n); @Override boolean addReadyVM(VM vm); @Override boolean remove(VM vm); @Override boolean remove(Node n); @Override boolean addOnlineNode(Node n); @Override boolean addOfflineNode(Node n); @Override Set<Node> getOnlineNodes(); @Override Set<Node> getOfflineNodes(); @Override Set<VM> getRunningVMs(); @Override Set<VM> getSleepingVMs(); @Override Set<VM> getSleepingVMs(Node n); @Override Set<VM> getRunningVMs(Node n); @Override Set<VM> getReadyVMs(); @Override Set<VM> getAllVMs(); @Override Set<Node> getAllNodes(); @Override Node getVMLocation(VM vm); @Override Set<VM> getRunningVMs(Collection<Node> ns); @Override Set<VM> getSleepingVMs(Collection<Node> ns); @Override Mapping copy(); @Override boolean contains(Node n); @Override boolean contains(VM vm); @Override void clear(); @Override void clearNode(Node u); @Override void clearAllVMs(); @Override String toString(); @Override int getNbNodes(); @Override int getNbVMs(); } | @Test(dependsOnMethods = {"testInstantiation", "testOnlineNode", "testOfflineNode", "testRunningVM", "testWaiting", "testSleeping"}) public void testClearAllVMs() { Mapping c = new DefaultMapping(); c.addOfflineNode(ns.get(0)); c.addOnlineNode(ns.get(1)); c.addRunningVM(vms.get(0), ns.get(1)); c.addRunningVM(vms.get(1), ns.get(1)); c.addSleepingVM(vms.get(2), ns.get(1)); c.addReadyVM(vms.get(3)); c.clearAllVMs(); Assert.assertEquals(c.getAllNodes().size(), 2); Assert.assertTrue(c.getAllVMs().isEmpty()); Assert.assertTrue(c.getRunningVMs().isEmpty()); Assert.assertTrue(c.getSleepingVMs().isEmpty()); Assert.assertTrue(c.getReadyVMs().isEmpty()); Assert.assertEquals(c.getOnlineNodes().size(), 1); Assert.assertEquals(c.getOfflineNodes().size(), 1); Assert.assertTrue(c.getRunningVMs(ns.get(1)).isEmpty()); Assert.assertTrue(c.getSleepingVMs(ns.get(1)).isEmpty()); Assert.assertEquals(c.getNbVMs(), 0); } |
DefaultMapping extends AbstractMapping { @Override public void clearNode(Node u) { for (TIntObjectHashMap<Set<VM>> h : host) { Set<VM> s = h.get(u.id()); if (s != null) { for (VM vm : s) { place.remove(vm.id()); st.remove(vm.id()); } s.clear(); } } } @SuppressWarnings("unchecked") DefaultMapping(); DefaultMapping(Mapping m); @Override boolean isRunning(VM v); @Override boolean isSleeping(VM v); @Override boolean isReady(VM v); @Override boolean isOnline(Node n); @Override boolean isOffline(Node n); @Override boolean addRunningVM(VM vm, Node n); @Override boolean addSleepingVM(VM vm, Node n); @Override boolean addReadyVM(VM vm); @Override boolean remove(VM vm); @Override boolean remove(Node n); @Override boolean addOnlineNode(Node n); @Override boolean addOfflineNode(Node n); @Override Set<Node> getOnlineNodes(); @Override Set<Node> getOfflineNodes(); @Override Set<VM> getRunningVMs(); @Override Set<VM> getSleepingVMs(); @Override Set<VM> getSleepingVMs(Node n); @Override Set<VM> getRunningVMs(Node n); @Override Set<VM> getReadyVMs(); @Override Set<VM> getAllVMs(); @Override Set<Node> getAllNodes(); @Override Node getVMLocation(VM vm); @Override Set<VM> getRunningVMs(Collection<Node> ns); @Override Set<VM> getSleepingVMs(Collection<Node> ns); @Override Mapping copy(); @Override boolean contains(Node n); @Override boolean contains(VM vm); @Override void clear(); @Override void clearNode(Node u); @Override void clearAllVMs(); @Override String toString(); @Override int getNbNodes(); @Override int getNbVMs(); } | @Test(dependsOnMethods = {"testInstantiation"}) public void testClearNode() { Mapping c = new DefaultMapping(); c.addOnlineNode(ns.get(0)); c.addOnlineNode(ns.get(1)); c.addRunningVM(vms.get(0), ns.get(0)); c.addRunningVM(vms.get(1), ns.get(1)); c.addSleepingVM(vms.get(2), ns.get(0)); c.addSleepingVM(vms.get(3), ns.get(1)); c.addReadyVM(vms.get(4)); c.clearNode(ns.get(0)); Assert.assertEquals(3, c.getAllVMs().size()); Assert.assertEquals(c.getNbVMs(), 3); Assert.assertTrue(c.getRunningVMs(ns.get(0)).isEmpty()); Assert.assertTrue(c.getSleepingVMs(ns.get(0)).isEmpty()); } |
TimeBasedPlanApplier extends DefaultPlanApplier { @Override public Model apply(ReconfigurationPlan p) { Model res = p.getOrigin().copy(); List<Action> actions = new ArrayList<>(p.getActions()); actions.sort(startFirstComparator); for (Action a : actions) { if (!a.apply(res)) { return null; } fireAction(a); } return res; } @Override Model apply(ReconfigurationPlan p); @Override String toString(ReconfigurationPlan p); } | @Test public void testApply() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 10); List<Node> ns = Util.newNodes(mo, 10); ReconfigurationPlan plan = makePlan(mo, ns, vms); Model res = new DependencyBasedPlanApplier().apply(plan); Mapping resMapping = res.getMapping(); Assert.assertTrue(resMapping.isOffline(ns.get(0))); Assert.assertTrue(resMapping.isOnline(ns.get(3))); ShareableResource rc = ShareableResource.get(res, "cpu"); Assert.assertEquals(rc.getConsumption(vms.get(2)), 7); Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3)); Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1)); Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2)); } |
TimeBasedPlanApplier extends DefaultPlanApplier { @Override public String toString(ReconfigurationPlan p) { Set<Action> sorted = new TreeSet<>(new TimedBasedActionComparator(true, true)); sorted.addAll(p.getActions()); StringBuilder b = new StringBuilder(); for (Action a : sorted) { b.append(a.getStart()).append(':').append(a.getEnd()).append(' ').append(a.toString()).append('\n'); } return b.toString(); } @Override Model apply(ReconfigurationPlan p); @Override String toString(ReconfigurationPlan p); } | @Test public void testToString() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 10); List<Node> ns = Util.newNodes(mo, 10); ReconfigurationPlan plan = makePlan(mo, ns, vms); Assert.assertFalse(new DependencyBasedPlanApplier().toString(plan).contains("null")); } |
DefaultReconfigurationPlanMonitor implements ReconfigurationPlanMonitor { @Override public Set<Action> commit(Action a) { Set<Action> s = new HashSet<>(); synchronized (lock) { boolean ret = a.apply(curModel); if (!ret) { throw new InfeasibleActionException(curModel, a); } nbCommitted++; Set<Dependency> deps = pre.get(a); if (deps != null) { for (Dependency dep : deps) { Set<Action> actions = dep.getDependencies(); actions.remove(a); if (actions.isEmpty()) { Action x = dep.getAction(); s.add(x); } } } } return s; } DefaultReconfigurationPlanMonitor(ReconfigurationPlan p); @Override Model getCurrentModel(); @Override Set<Action> commit(Action a); @Override int getNbCommitted(); @Override boolean isBlocked(Action a); @Override ReconfigurationPlan getReconfigurationPlan(); } | @Test(dependsOnMethods = {"testInit", "testGoodCommits"}, expectedExceptions = InfeasibleActionException.class) public void testCommitBlocked() { ReconfigurationPlan plan = makePlan(); ReconfigurationPlanMonitor exec = new DefaultReconfigurationPlanMonitor(plan); exec.commit(a3); }
@Test(dependsOnMethods = {"testInit", "testGoodCommits"}, expectedExceptions = InfeasibleActionException.class) public void testDoubleCommit() { ReconfigurationPlan plan = makePlan(); ReconfigurationPlanMonitor exec = new DefaultReconfigurationPlanMonitor(plan); Assert.assertNotNull(exec.commit(a1)); exec.commit(a1); } |
ContinuousViolationException extends SatConstraintViolationException { public Action getAction() { return action; } ContinuousViolationException(SatConstraint cstr, Action action); Action getAction(); } | @Test public void test() { SatConstraint c = Mockito.mock(SatConstraint.class); Action a = Mockito.mock(Action.class); ContinuousViolationException ex = new ContinuousViolationException(c, a); Assert.assertEquals(ex.getAction(), a); Assert.assertEquals(ex.getConstraint(), c); Assert.assertFalse(ex.toString().contains("null")); } |
DiscreteViolationException extends SatConstraintViolationException { public Model getModel() { return mo; } DiscreteViolationException(SatConstraint cstr, Model mo); Model getModel(); } | @Test public void test() { SatConstraint c = Mockito.mock(SatConstraint.class); Model m = new DefaultModel(); DiscreteViolationException ex = new DiscreteViolationException(c, m); Assert.assertEquals(ex.getModel(), m); Assert.assertEquals(ex.getConstraint(), c); Assert.assertFalse(ex.toString().contains("null")); } |
DefaultReconfigurationPlan implements ReconfigurationPlan { @Override public String toString() { List<Action> l = new ArrayList<>(actions); l.sort(sorter); StringJoiner joiner = new StringJoiner("\n"); for (Action a : l) { joiner.add(String.format("%d:%d %s", a.getStart(), a.getEnd(), a.toString())); } return joiner.toString(); } DefaultReconfigurationPlan(Model m); @Override Model getOrigin(); @Override boolean add(Action a); @Override int getSize(); @Override int getDuration(); @Override Set<Action> getActions(); @Override Iterator<Action> iterator(); @Override Model getResult(); @Override String toString(); @Override boolean isApplyable(); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<Action> getDirectDependencies(Action a); @Override ReconfigurationPlanApplier getReconfigurationApplier(); @Override void setReconfigurationApplier(ReconfigurationPlanApplier ra); } | @Test public void testToString() { Model mo = new DefaultModel(); VM v1 = mo.newVM(); VM v2 = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); mo.getMapping().addOnlineNode(n1); mo.getMapping().addOnlineNode(n2); mo.getMapping().addRunningVM(v1, n1); mo.getMapping().addRunningVM(v2, n1); ReconfigurationPlan p1 = new DefaultReconfigurationPlan(mo); p1.add(new MigrateVM(v1, n1, n2, 1, 2)); p1.add(new MigrateVM(v2, n1, n2, 1, 2)); String s = p1.toString(); Assert.assertNotEquals(s.indexOf("migrate("), s.lastIndexOf("migrate(")); System.err.println(p1.toString()); System.err.flush(); } |
DefaultReconfigurationPlan implements ReconfigurationPlan { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ReconfigurationPlan op = (ReconfigurationPlan) o; return actions.equals(op.getActions()) && src.equals(op.getOrigin()); } DefaultReconfigurationPlan(Model m); @Override Model getOrigin(); @Override boolean add(Action a); @Override int getSize(); @Override int getDuration(); @Override Set<Action> getActions(); @Override Iterator<Action> iterator(); @Override Model getResult(); @Override String toString(); @Override boolean isApplyable(); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<Action> getDirectDependencies(Action a); @Override ReconfigurationPlanApplier getReconfigurationApplier(); @Override void setReconfigurationApplier(ReconfigurationPlanApplier ra); } | @Test public void testEquals() { Model mo = new DefaultModel(); VM v = mo.newVM(); Node n1 = mo.newNode(); Node n2 = mo.newNode(); mo.getMapping().addOnlineNode(n1); mo.getMapping().addOnlineNode(n2); mo.getMapping().addRunningVM(v, n1); ReconfigurationPlan p1 = new DefaultReconfigurationPlan(mo); p1.add(new ShutdownNode(n1, 1, 2)); p1.add(new ShutdownNode(n2, 1, 2)); ReconfigurationPlan p2 = new DefaultReconfigurationPlan(mo.copy()); p2.add(new ShutdownNode(n1, 1, 2)); p2.add(new ShutdownNode(n2, 1, 2)); Assert.assertEquals(p1, p2); } |
RootConverter implements ConstraintConverter<Root> { @Override public String getJSONId() { return "root"; } @Override Class<Root> getSupportedConstraint(); @Override String getJSONId(); @Override Root fromJSON(Model mo, JSONObject o); @Override JSONObject toJSON(Root o); } | @Test public void testBundle() { Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJavaConstraints().contains(Root.class)); Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJSONConstraints().contains(new RootConverter().getJSONId())); } |
TimedBasedActionComparator implements Comparator<Action> { @Override public int compare(Action a1, Action a2) { if (a1.equals(a2)) { return 0; } int d = delay(a1, a2, startBased); if (d == 0) { d = delay(a1, a2, !startBased); if (diffSimultaneous && d == 0) { return -1; } } return d; } TimedBasedActionComparator(); TimedBasedActionComparator(boolean onStart, boolean diffSamePeriods); @Override int compare(Action a1, Action a2); } | @Test public void testPrecedence() { Action a = new MockAction(vm, 0, 4); Action b = new MockAction(vm, 4, 10); Assert.assertTrue(startCmp.compare(a, b) < 0); Assert.assertTrue(startCmp.compare(b, a) > 0); Assert.assertTrue(stopCmp.compare(a, b) < 0); Assert.assertTrue(stopCmp.compare(b, a) > 0); }
@Test public void testEquality() { Action a = new MockAction(vm, 0, 4); Action b = new MockAction(vm, 0, 4); Assert.assertEquals(startCmp.compare(a, b), 0); Assert.assertEquals(stopCmp.compare(a, b), 0); }
@Test public void testEqualityWithSimultaneousDisallowed() { VM vm2 = mo.newVM(); Action a = new MockAction(vm, 0, 4); Action b = new MockAction(vm2, 0, 4); Assert.assertNotEquals(new TimedBasedActionComparator(false, true).compare(a, b), 0); Assert.assertNotEquals(new TimedBasedActionComparator(true, true).compare(a, b), 0); }
@Test public void testOverlap1() { Action a = new MockAction(vm, 0, 4); Action b = new MockAction(vm, 2, 4); Assert.assertTrue(startCmp.compare(a, b) < 0); Assert.assertTrue(stopCmp.compare(a, b) < 0); }
@Test public void testOverlap2() { Action a = new MockAction(vm, 0, 4); Action b = new MockAction(vm, 0, 3); Assert.assertTrue(startCmp.compare(a, b) > 0); Assert.assertTrue(stopCmp.compare(a, b) > 0); } |
DependencyBasedPlanApplier extends DefaultPlanApplier { @Override public Model apply(ReconfigurationPlan p) { int nbCommitted = 0; ReconfigurationPlanMonitor rpm = new DefaultReconfigurationPlanMonitor(p); Set<Action> feasible = new HashSet<>(); for (Action a : p.getActions()) { if (!rpm.isBlocked(a)) { feasible.add(a); } } while (nbCommitted != p.getSize()) { Set<Action> newFeasible = new HashSet<>(); for (Action a : feasible) { Set<Action> s = rpm.commit(a); fireAction(a); newFeasible.addAll(s); nbCommitted++; } feasible = newFeasible; } return rpm.getCurrentModel(); } @Override Model apply(ReconfigurationPlan p); @Override String toString(ReconfigurationPlan p); } | @Test public void testApply() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 10); List<Node> ns = Util.newNodes(mo, 10); Mapping map = mo.getMapping(); map.addOnlineNode(ns.get(0)); map.addOnlineNode(ns.get(1)); map.addOnlineNode(ns.get(2)); map.addOfflineNode(ns.get(3)); map.addRunningVM(vms.get(0), ns.get(2)); map.addRunningVM(vms.get(1), ns.get(0)); map.addRunningVM(vms.get(2), ns.get(1)); map.addRunningVM(vms.get(3), ns.get(1)); BootNode bN4 = new BootNode(ns.get(3), 3, 5); MigrateVM mVM1 = new MigrateVM(vms.get(0), ns.get(2), ns.get(3), 6, 7); Allocate aVM3 = new Allocate(vms.get(2), ns.get(1), "cpu", 7, 8, 9); MigrateVM mVM2 = new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 1, 3); MigrateVM mVM4 = new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 7); ShutdownNode sN1 = new ShutdownNode(ns.get(0), 5, 7); ShareableResource rc = new ShareableResource("cpu"); rc.setConsumption(vms.get(2), 3); mo.attach(rc); ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo); plan.add(bN4); plan.add(mVM1); plan.add(aVM3); plan.add(mVM2); plan.add(mVM4); plan.add(sN1); Model res = new DependencyBasedPlanApplier().apply(plan); Assert.assertNotNull(res); Mapping resMapping = res.getMapping(); Assert.assertTrue(resMapping.isOffline(ns.get(0))); Assert.assertTrue(resMapping.isOnline(ns.get(3))); rc = ShareableResource.get(res, "cpu"); Assert.assertEquals(rc.getConsumption(vms.get(2)), 7); Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3)); Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1)); Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2)); } |
SuspendVM extends Action implements VMStateTransition { @Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } SuspendVM that = (SuspendVM) o; return this.vm.equals(that.vm) && this.src.equals(that.src) && this.dst.equals(that.dst); } SuspendVM(VM v, Node from, Node to, int start, int end); @Override String pretty(); @Override boolean applyAction(Model m); @Override boolean equals(Object o); @Override int hashCode(); Node getDestinationNode(); Node getSourceNode(); @Override VM getVM(); @Override VMState getCurrentState(); @Override VMState getNextState(); @Override Object visit(ActionVisitor v); } | @Test(dependsOnMethods = {"testInstantiate"}) public void testEquals() { SuspendVM a = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 3, 5); SuspendVM b = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 3, 5); Assert.assertFalse(a.equals(new Object())); Assert.assertTrue(a.equals(a)); Assert.assertEquals(a, b); Assert.assertEquals(a.hashCode(), b.hashCode()); Assert.assertNotSame(a, new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 4, 5)); Assert.assertNotSame(a, new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 3, 4)); Assert.assertNotSame(a, new SuspendVM(vms.get(1), ns.get(0), ns.get(1), 3, 5)); Assert.assertNotSame(a, new SuspendVM(vms.get(0), ns.get(2), ns.get(1), 3, 5)); Assert.assertNotSame(a, new SuspendVM(vms.get(0), ns.get(0), ns.get(2), 3, 5)); } |
SuspendVM extends Action implements VMStateTransition { @Override public Object visit(ActionVisitor v) { return v.visit(this); } SuspendVM(VM v, Node from, Node to, int start, int end); @Override String pretty(); @Override boolean applyAction(Model m); @Override boolean equals(Object o); @Override int hashCode(); Node getDestinationNode(); Node getSourceNode(); @Override VM getVM(); @Override VMState getCurrentState(); @Override VMState getNextState(); @Override Object visit(ActionVisitor v); } | @Test public void testVisit() { ActionVisitor visitor = mock(ActionVisitor.class); a.visit(visitor); verify(visitor).visit(a); } |
ResumeVM extends Action implements VMStateTransition, RunningVMPlacement { @Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } ResumeVM that = (ResumeVM) o; return this.vm.equals(that.vm) && this.src.equals(that.src) && this.dst.equals(that.dst); } ResumeVM(VM v, Node from, Node to, int start, int end); @Override VM getVM(); @Override Node getDestinationNode(); Node getSourceNode(); @Override String pretty(); @Override boolean applyAction(Model m); @Override boolean equals(Object o); @Override int hashCode(); @Override VMState getCurrentState(); @Override VMState getNextState(); @Override Object visit(ActionVisitor v); } | @Test(dependsOnMethods = {"testInstantiate"}) public void testEquals() { ResumeVM a = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 3, 5); ResumeVM b = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 3, 5); Assert.assertFalse(a.equals(new Object())); Assert.assertTrue(a.equals(a)); Assert.assertEquals(a, b); Assert.assertEquals(a.hashCode(), b.hashCode()); Assert.assertNotSame(a, new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 4, 5)); Assert.assertNotSame(a, new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 3, 4)); Assert.assertNotSame(a, new ResumeVM(vms.get(1), ns.get(0), ns.get(1), 3, 5)); Assert.assertNotSame(a, new ResumeVM(vms.get(0), ns.get(2), ns.get(1), 3, 5)); Assert.assertNotSame(a, new ResumeVM(vms.get(0), ns.get(0), ns.get(2), 3, 5)); } |
ResumeVM extends Action implements VMStateTransition, RunningVMPlacement { @Override public Object visit(ActionVisitor v) { return v.visit(this); } ResumeVM(VM v, Node from, Node to, int start, int end); @Override VM getVM(); @Override Node getDestinationNode(); Node getSourceNode(); @Override String pretty(); @Override boolean applyAction(Model m); @Override boolean equals(Object o); @Override int hashCode(); @Override VMState getCurrentState(); @Override VMState getNextState(); @Override Object visit(ActionVisitor v); } | @Test public void testVisit() { ActionVisitor visitor = mock(ActionVisitor.class); a.visit(visitor); verify(visitor).visit(a); } |
GatherConverter implements ConstraintConverter<Gather> { @Override public String getJSONId() { return "gather"; } @Override Class<Gather> getSupportedConstraint(); @Override String getJSONId(); @Override Gather fromJSON(Model mo, JSONObject o); @Override JSONObject toJSON(Gather o); } | @Test public void testBundle() { Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJavaConstraints().contains(Gather.class)); Assert.assertTrue(ConstraintsConverter.newBundle().getSupportedJSONConstraints().contains(new GatherConverter().getJSONId())); } |
Allocate extends Action implements VMEvent { @Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } Allocate that = (Allocate) o; return this.getVM().equals(that.getVM()) && this.node.equals(that.node) && this.getResourceId().equals(that.getResourceId()) && this.getAmount() == that.getAmount(); } Allocate(VM vm, Node on, String rc, int amount, int start, int end); Node getHost(); @Override VM getVM(); String getResourceId(); int getAmount(); @Override boolean applyAction(Model i); @Override String pretty(); @Override boolean equals(Object o); @Override int hashCode(); @Override Object visit(ActionVisitor v); } | @Test(dependsOnMethods = {"testInstantiation"}) public void testEquals() { Allocate a = new Allocate(vms.get(0), ns.get(0), "foo", 5, 3, 5); Allocate b = new Allocate(vms.get(0), ns.get(0), "foo", 5, 3, 5); Assert.assertFalse(a.equals(new Object())); Assert.assertTrue(a.equals(a)); Assert.assertEquals(a, b); Assert.assertEquals(a.hashCode(), b.hashCode()); Assert.assertNotSame(a, new Allocate(vms.get(2), ns.get(0), "foo", 5, 3, 5)); Assert.assertNotSame(a, new Allocate(vms.get(0), ns.get(1), "foo", 5, 3, 5)); Assert.assertNotSame(a, new Allocate(vms.get(0), ns.get(0), "bar", 5, 3, 5)); Assert.assertNotSame(a, new Allocate(vms.get(0), ns.get(0), "foo", 6, 3, 5)); Assert.assertNotSame(a, new Allocate(vms.get(0), ns.get(0), "foo", 5, 4, 5)); Assert.assertNotSame(a, new Allocate(vms.get(0), ns.get(0), "foo", 5, 3, 7)); } |
Allocate extends Action implements VMEvent { @Override public Object visit(ActionVisitor v) { return v.visit(this); } Allocate(VM vm, Node on, String rc, int amount, int start, int end); Node getHost(); @Override VM getVM(); String getResourceId(); int getAmount(); @Override boolean applyAction(Model i); @Override String pretty(); @Override boolean equals(Object o); @Override int hashCode(); @Override Object visit(ActionVisitor v); } | @Test public void testVisit() { ActionVisitor visitor = mock(ActionVisitor.class); a.visit(visitor); verify(visitor).visit(a); } |
BootNode extends Action implements NodeEvent { @Override public Node getNode() { return node; } BootNode(Node n, int start, int end); @Override boolean equals(Object o); @Override Node getNode(); @Override int hashCode(); @Override String pretty(); @Override boolean applyAction(Model c); @Override Object visit(ActionVisitor v); } | @Test public void testInstantiate() { BootNode a = new BootNode(ns.get(0), 3, 5); Assert.assertEquals(ns.get(0), a.getNode()); Assert.assertEquals(3, a.getStart()); Assert.assertEquals(5, a.getEnd()); Assert.assertFalse(a.toString().contains("null")); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.