diff --git a/README.md b/README.md
index 642c0d8..d748955 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,10 @@ on the parent directory. This will build the artifact and run tests against the
## Dependencies
-GWT Storage does not depend on any other module.??????????
+GWT Storage depends on:
+
+* gwt-core
+* get-event
## Roadmap
diff --git a/old/README.md b/old/README.md
deleted file mode 100644
index 2d94e51..0000000
--- a/old/README.md
+++ /dev/null
@@ -1,27 +0,0 @@
-# Gwt3-Storage
-
-[](https://travis-ci.org/avierax/gwt-storage)
-
-Migration of gwt2-storage to ensure gwt3 compatibility.
-
-## Roadmap
-
- 1. ~~Migrate the current gwt-2.8.2 code and remove incompatible dependencies~~ [DONE]
- 2. ~~Remove dependency on JavaScriptObject~~ [DONE]
- 3. ~~Remove all jsni constructions~~ [DONE]
- 4. Add support for Native Events (pending issue from Gwt2)
- 5. Optionally support receiving notifications of current session modifications
- 6. Add support for automated testing multiple browser sessions from Gwt Unit Test
-
-## Known issues
-
-### Issues inherited from gwt2-storage
-
- - Native events are not yet correctly supported, they are emulated.
- - Testing multiple browser sessions in a single Gwt Unit Test is not supported by Gwt. Is it?
-
-### Issues resulting from migration
-
- - It's unknown what mechanism should be used to substitute `GWT.reportUncaughtException`. See
- method `org.gwtproject.storage.client.StorageImpl.handleStorageEvent`
-
\ No newline at end of file
diff --git a/old/pom.xml b/old/pom.xml
deleted file mode 100644
index 5b05009..0000000
--- a/old/pom.xml
+++ /dev/null
@@ -1,196 +0,0 @@
-
-
- 4.0.0
-
- org.gwtproject.storage
- storage
- 1.0.2-SNAPSHOT
- gwt-lib
-
- Gwt Storage Module
- The purpose of this module, what it provides and how it can be used
- https://github.com/avierax/gwt-storage
-
-
-
- The Apache Software License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
-
-
-
-
-
- Ariel Viera
- ariel.viera@gmail.com
- tissca
- www.tissca.com
-
-
-
-
- scm:git:git://github.com/avierax/gwt-storage.git
- scm:git:ssh://github.com:avierax/gwt-storage.git
- https://github.com/avierax/gwt-storage/tree/master
-
-
-
- UTF-8
- UTF-8
-
- 1.8
- 1.8
- 1.0.0-RC1
-
-
-
-
-
-
- junit
- junit
- 4.13.1
- test
-
-
- org.gwtproject.event
- gwt-event
- HEAD-SNAPSHOT
-
-
- com.google.gwt
- gwt-user
- 2.8.2
- test
-
-
- com.google.gwt
- gwt-dev
- 2.8.2
-
-
- com.google.elemental2
- elemental2-webstorage
- ${elemental2version}
-
-
- com.google.jsinterop
- base
- 1.0.0-RC1
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.5.1
-
- ${maven.compiler.source}
- ${maven.compiler.target}
-
-
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.17
-
-
- validate
- validate
-
- UTF-8
- true
- true
- gwt-checkstyle.xml
-
-
- check
-
-
-
-
-
-
- net.ltgt.gwt.maven
- gwt-maven-plugin
- 1.0-rc-9
- true
-
- org.gwtproject.storage.Storage
-
-
-
-
-
-
-
-
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
-
-
-
-
- release
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9.1
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.5
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/old/src/main/java/org/gwtproject/storage/client/GwtMigrationUtils.java b/old/src/main/java/org/gwtproject/storage/client/GwtMigrationUtils.java
deleted file mode 100644
index 2bbbc32..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/GwtMigrationUtils.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-import static elemental2.dom.DomGlobal.console;
-
-/**
- * A set of methods used as a temporary substitution of static GWT.* method calls.
- *
- * The actual behaviour should be decided later.
- */
-class GwtMigrationUtils {
-
- /**
- * This documentation is copied verbatim from GWT.reportUncaughtException.
- *
- * Reports an exception caught at the "top level" to a handler set via
- * {@link #setUncaughtExceptionHandler(UncaughtExceptionHandler)}. This is
- * used in places where the browser calls into user code such as event
- * callbacks, timers, and RPC.
- *
- * If no {@code UncaughtExceptionHandler} is set, the exception is reported
- * to browser. Browsers usually log these exceptions to the JavaScript
- * console.
- */
- public static void reportUncaughtException(Throwable t) {
- console.log(t.toString());
- }
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/Storage.java b/old/src/main/java/org/gwtproject/storage/client/Storage.java
deleted file mode 100644
index debfd2b..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/Storage.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import org.gwtproject.event.shared.HandlerRegistration;
-
-import elemental2.dom.DomGlobal;
-import elemental2.webstorage.WebStorageWindow;
-
-/**
- * Implements the HTML5 Storage interface.
- *
- *
- * You can obtain a Storage by either invoking
- * {@link #getLocalStorageIfSupported()} or
- * {@link #getSessionStorageIfSupported()}.
- *
- *
- *
- * Experimental API: This API is still under development
- * and is subject to change.
- *
- *
- *
- * If Web Storage is NOT supported in the browser, these methods return
- * null.
- *
- *
- *
- * Note: Storage events into other windows are not supported.
- *
- *
- *
- *
- * This may not be supported on all browsers.
- *
- *
- * @see W3C Web Storage -
- * Storage
- * @see Safari
- * Client-Side Storage and Offline Applications Programming Guide -
- * Key-Value Storage
- * @see Quirksmode.org -
- * HTML5 Compatibility - Storage
- * @see Wiki - Quickstart Guide
- */
-// TODO(pdr): Add support for Object values, instead of just Strings. The
-// Storage API spec specifies this, but browser support poor at the moment.
-// TODO(pdr): Add support for native events once browsers correctly implement
-// storage events.
-public final class Storage {
-
- static final StorageImpl impl = new StorageImplNonNativeEvents();
- private static Storage localStorage;
- private static Storage sessionStorage;
- // Contains either "localStorage" or "sessionStorage":
- private final String storage;
-
- /**
- * This class can never be instantiated externally. Use
- * {@link #getLocalStorageIfSupported()} or
- * {@link #getSessionStorageIfSupported()} instead.
- */
- private Storage(String storage) {
- this.storage = storage;
- }
-
- /**
- * Registers an event handler for StorageEvents.
- *
- * @param handler
- * @return {@link HandlerRegistration} used to remove this handler
- * @see W3C Web
- * Storage - the storage event
- */
- public static HandlerRegistration addStorageEventHandler(StorageEvent.Handler handler) {
- return impl.addStorageEventHandler(handler);
- }
-
- /**
- * Returns a Local Storage.
- *
- *
- * The returned storage is associated with the origin of the
- * Document.
- *
- *
- * @return the localStorage instance, or null if Web Storage is
- * NOT supported.
- * @see W3C Web
- * Storage - localStorage
- */
- public static Storage getLocalStorageIfSupported() {
- if (localStorage == null && isLocalStorageSupported()) {
- localStorage = new Storage(StorageImpl.LOCAL_STORAGE);
- }
- return localStorage;
- }
-
- /**
- * Returns a Session Storage.
- *
- *
- * The returned storage is associated with the current top-level browsing context .
- *
- *
- * @return the sessionStorage instance, or null if Web Storage is
- * NOT supported.
- * @see W3C Web
- * Storage - sessionStorage
- */
- public static Storage getSessionStorageIfSupported() {
- if (sessionStorage == null && isSessionStorageSupported()) {
- sessionStorage = new Storage(StorageImpl.SESSION_STORAGE);
- }
- return sessionStorage;
- }
-
- /**
- * Returns true if the localStorage part of the
- * Storage API is supported on the running platform.
- */
- public static boolean isLocalStorageSupported() {
- return StorageSupportDetector.localStorageSupported;
- }
-
- /**
- * Returns true if the sessionStorage part of the
- * Storage API is supported on the running platform.
- */
- public static boolean isSessionStorageSupported() {
- return StorageSupportDetector.sessionStorageSupported;
- }
-
- /**
- * Returns true if the Storage API (both localStorage and
- * sessionStorage) is supported on the running platform.
- */
- public static boolean isSupported() {
- return isLocalStorageSupported() && isSessionStorageSupported();
- }
-
- /**
- * De-registers an event handler for StorageEvents.
- *
- * @param handler
- * @see W3C Web
- * Storage - the storage event
- */
- public static void removeStorageEventHandler(StorageEvent.Handler handler) {
- impl.removeStorageEventHandler(handler);
- }
-
- /**
- * Removes all items in the Storage.
- *
- * @see W3C Web
- * Storage - Storage.clear()
- */
- public void clear() {
- impl.clear(storage);
- }
-
- /**
- * Returns the item in the Storage associated with the specified key.
- *
- * @param key the key to a value in the Storage
- * @return the value associated with the given key
- * @see W3C Web
- * Storage - Storage.getItem(k)
- */
- public String getItem(String key) {
- return impl.getItem(storage, key);
- }
-
- /**
- * Returns the number of items in this Storage.
- *
- * @return number of items in this Storage
- * @see W3C Web
- * Storage - Storage.length()
- */
- public int getLength() {
- return impl.getLength(storage);
- }
-
- /**
- * Returns the key at the specified index.
- *
- * @param index the index of the key
- * @return the key at the specified index in this Storage
- * @see W3C Web
- * Storage - Storage.key(n)
- */
- public String key(int index) {
- return impl.key(storage, index);
- }
-
- /**
- * Removes the item in the Storage associated with the specified key.
- *
- * @param key the key to a value in the Storage
- * @see W3C
- * Web Storage - Storage.removeItem(k)
- */
- public void removeItem(String key) {
- impl.removeItem(storage, key);
- }
-
- /**
- * Sets the value in the Storage associated with the specified key to the
- * specified data.
- *
- * Note: The empty string may not be used as a key.
- *
- * @param key the key to a value in the Storage
- * @param data the value associated with the key
- * @see W3C Web
- * Storage - Storage.setItem(k,v)
- */
- public void setItem(String key, String data) {
- // prevent the empty string due to a Firefox bug:
- // bugzilla.mozilla.org/show_bug.cgi?id=510849
- assert key.length() > 0;
- impl.setItem(storage, key, data);
- }
-
- // Still a separate class to prevent native calls on class load as it my break existing code.
- private static class StorageSupportDetector {
- static final boolean localStorageSupported = checkStorageSupport(StorageImpl.LOCAL_STORAGE);
- static final boolean sessionStorageSupported = checkStorageSupport(StorageImpl.SESSION_STORAGE);
-
- private static boolean checkStorageSupport(String storage) {
- String c = "_gwt_dummy_";
- WebStorageWindow window = WebStorageWindow.of(DomGlobal.window);
- final elemental2.webstorage.Storage storageObj =
- storage.equals(StorageImpl.LOCAL_STORAGE) ? window.localStorage : window.sessionStorage;
- try {
- storageObj.setItem(c, c);
- storageObj.removeItem(c);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- }
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/StorageEvent.java b/old/src/main/java/org/gwtproject/storage/client/StorageEvent.java
deleted file mode 100644
index fd9e8af..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/StorageEvent.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import jsinterop.annotations.JsConstructor;
-import jsinterop.annotations.JsOverlay;
-import jsinterop.annotations.JsPackage;
-import jsinterop.annotations.JsProperty;
-import jsinterop.annotations.JsType;
-import jsinterop.base.Js;
-import jsinterop.base.JsPropertyMap;
-
-/**
- * Represents a Storage Event.
- *
- *
- * Experimental API: This API is still under development
- * and is subject to change.
- *
- *
- *
- * A Storage Event is fired when a storage area changes, as described in these
- * two sections (for session
- * storage , for local storage ).
- *
- *
- * @see Handler
- * @see W3C Web
- * Storage - StorageEvent
- * @see Safari
- * StorageEvent reference
- */
-@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "StorageEvent")
-public final class StorageEvent {
-
- /**
- * Represents an Event handler for {@link StorageEvent}s.
- *
- *
- * Apply your StorageEventHandler using
- * {@link Storage#addStorageEventHandler(StorageEvent.Handler)}.
- *
- *
- * @see StorageEvent
- */
- public interface Handler {
- /**
- * Invoked when a StorageEvent is fired.
- *
- * @param event the fired StorageEvent
- * @see W3C Web
- * Storage - Storage Event
- */
- void onStorageChange(StorageEvent event);
- }
-
- @JsConstructor
- private StorageEvent(String type, Object init) {
- }
-
- /**
- * Returns a newly created and correctly initialized event.
- *
- * Note: Seemingly the embedded browser used in unit test does not have the StorageEvent
- * constructor. This forces us to emulate the actions performed by this constructor according
- * to the HTML5 Spec.
- *
- * @param init Dictionary with initial values for the event
- * @return the newly created event object
- */
- @JsOverlay
- static StorageEvent createEvent(Object init) {
- final StorageEvent storageEvent = new StorageEvent("storage", init);
- final JsPropertyMap se = Js.cast(storageEvent);
- final JsPropertyMap initSe = Js.cast(init);
- initSe.forEach(key -> se.set(key, initSe.get(key)));
- se.set("type", "storage");
- return storageEvent;
- }
-
- /**
- * Returns the key being changed.
- *
- * @return the key being changed
- * @see W3C
- * Web Storage - StorageEvent.key
- */
- @JsProperty
- public native String getKey();
-
- /**
- * Returns the new value of the key being changed.
- *
- * @return the new value of the key being changed
- * @see W3C
- * Web Storage - StorageEvent.newValue
- */
- @JsProperty
- public native String getNewValue();
-
- /**
- * Returns the old value of the key being changed.
- *
- * @return the old value of the key being changed
- * @see W3C
- * Web Storage - StorageEvent.oldValue
- */
- @JsProperty
- public native String getOldValue();
-
- /**
- * Returns the {@link Storage} object that was affected.
- *
- * @return the {@link Storage} object that was affected
- * @see W3C
- * Web Storage - StorageEvent.storageArea
- */
- @JsOverlay
- public Storage getStorageArea() {
- return Storage.impl.getStorageFromEvent(this);
- }
-
- /**
- * Returns the address of the document whose key changed.
- *
- * @return the address of the document whose key changed
- * @see W3C
- * Web Storage - StorageEvent.url
- */
- @JsProperty
- public native String getUrl();
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/StorageImpl.java b/old/src/main/java/org/gwtproject/storage/client/StorageImpl.java
deleted file mode 100644
index 7ac6876..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/StorageImpl.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static elemental2.dom.DomGlobal.window;
-
-import org.gwtproject.event.shared.HandlerRegistration;
-
-import elemental2.dom.Event;
-import elemental2.dom.EventListener;
-import elemental2.webstorage.WebStorageWindow;
-import jsinterop.annotations.JsFunction;
-import jsinterop.base.Js;
-
-/**
- * This is the HTML5 Storage implementation according to the standard
- * recommendation .
- *
- *
- * Never use this class directly, instead use {@link Storage}.
- *
- *
- * @see W3C Web Storage -
- * Storage
- */
-class StorageImpl {
-
- public static final String LOCAL_STORAGE = "localStorage";
- public static final String SESSION_STORAGE = "sessionStorage";
-
- protected static List storageEventHandlers;
-
- @JsFunction
- private interface NativeCallback {
- void onEvent(StorageEvent event);
- }
-
- protected static EventListener jsHandler;
-
- private static Map nameToStorage =
- new HashMap();
- static {
- nameToStorage.put(LOCAL_STORAGE, WebStorageWindow.of(window).localStorage);
- nameToStorage.put(SESSION_STORAGE, WebStorageWindow.of(window).sessionStorage);
- }
-
- /**
- * Handles StorageEvents if a {@link StorageEvent.Handler} is registered.
- */
- protected static final void handleStorageEvent(StorageEvent event) {
- if (!hasStorageEventHandlers()) {
- return;
- }
- for (StorageEvent.Handler handler : storageEventHandlers) {
- try {
- handler.onStorageChange(event);
- } catch (Throwable t) {
- GwtMigrationUtils.reportUncaughtException(t);
- }
- }
- }
-
- /**
- * Returns true if at least one StorageEvent handler is
- * registered, false otherwise.
- */
- protected static boolean hasStorageEventHandlers() {
- return storageEventHandlers != null && !storageEventHandlers.isEmpty();
- }
-
- /**
- * This class can never be instantiated by itself.
- */
- protected StorageImpl() {
- }
-
- /**
- * Registers an event handler for StorageEvents.
- *
- * @see W3C Web
- * Storage - the storage event
- * @param handler
- * @return {@link HandlerRegistration} used to remove this handler
- */
- public HandlerRegistration addStorageEventHandler(
- final StorageEvent.Handler handler) {
- getStorageEventHandlers().add(handler);
- if (storageEventHandlers.size() == 1) {
- addStorageEventHandler0();
- }
-
- return new HandlerRegistration() {
- @Override
- public void removeHandler() {
- removeStorageEventHandler(handler);
- }
- };
- }
-
- /**
- * Removes all items in the Storage.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @see W3C Web
- * Storage - Storage.clear()
- */
- public void clear(String storage) {
- nameToStorage.get(storage).clear();
- };
-
- /**
- * Returns the item in the Storage associated with the specified key.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @param key the key to a value in the Storage
- * @return the value associated with the given key
- * @see W3C Web
- * Storage - Storage.getItem(k)
- */
- public String getItem(String storage, String key) {
- return nameToStorage.get(storage).getItem(key);
- }
-
- /**
- * Returns the number of items in this Storage.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @return number of items in this Storage
- * @see W3C Web
- * Storage - Storage.length()
- */
- public int getLength(String storage) {
- return nameToStorage.get(storage).getLength();
- };
-
- /**
- * Returns the key at the specified index.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @param index the index of the key
- * @return the key at the specified index in this Storage
- * @see W3C Web
- * Storage - Storage.key(n)
- */
- public String key(String storage, int index) {
- // few browsers implement retrieval correctly when index is out of range.
- // compensate to preserve API expectation. According to W3C Web Storage spec
- //
- // "If n is greater than or equal to the number of key/value pairs in the
- // object, then this method must return null."
- return (index >= 0 && index < nameToStorage.get(storage).getLength()) ?
- nameToStorage.get(storage).key(index) : null;
- };
-
- /**
- * Removes the item in the Storage associated with the specified key.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @param key the key to a value in the Storage
- * @see W3C
- * Web Storage - Storage.removeItem(k)
- */
- public void removeItem(String storage, String key) {
- nameToStorage.get(storage).removeItem(key);
- }
-
- /**
- * De-registers an event handler for StorageEvents.
- *
- * @see W3C Web
- * Storage - the storage event
- * @param handler
- */
- public void removeStorageEventHandler(StorageEvent.Handler handler) {
- getStorageEventHandlers().remove(handler);
- if (storageEventHandlers.isEmpty()) {
- removeStorageEventHandler0();
- }
- }
-
- /**
- * Sets the value in the Storage associated with the specified key to the
- * specified data.
- *
- * @param storage either {@link #LOCAL_STORAGE} or {@link #SESSION_STORAGE}
- * @param key the key to a value in the Storage
- * @param data the value associated with the key
- * @see W3C Web
- * Storage - Storage.setItem(k,v)
- */
- public void setItem(String storage, String key, String data) {
- nameToStorage.get(storage).setItem(key, data);
- }
-
- protected void addStorageEventHandler0() {
- StorageImpl.jsHandler = new EventListener() {
- @Override public void handleEvent(Event event) {
- StorageImpl.handleStorageEvent(Js.uncheckedCast(event));
- }
- };
- window.addEventListener("storage", jsHandler, false);
- }
-
- /**
- * Returns the {@link List} of {@link StorageEvent.Handler}s
- * registered, which is never null.
- */
- protected List getStorageEventHandlers() {
- if (storageEventHandlers == null) {
- storageEventHandlers = new ArrayList();
- }
- return storageEventHandlers;
- }
-
- /**
- * Returns the {@link Storage} object that was affected in the event.
- *
- * @return the {@link Storage} object that was affected in the event.
- */
- protected Storage getStorageFromEvent(StorageEvent event) {
- elemental2.webstorage.StorageEvent event1 = Js.uncheckedCast(event);
- if (event1.storageArea == nameToStorage.get("localStorage")) {
- return Storage.getLocalStorageIfSupported();
- } else {
- return Storage.getSessionStorageIfSupported();
- }
- }
-
- protected void removeStorageEventHandler0() {
- window.removeEventListener("storage",
- StorageImpl.jsHandler, false);
- }
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/StorageImplNonNativeEvents.java b/old/src/main/java/org/gwtproject/storage/client/StorageImplNonNativeEvents.java
deleted file mode 100644
index 0c7f960..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/StorageImplNonNativeEvents.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import static elemental2.dom.DomGlobal.window;
-
-import elemental2.webstorage.WebStorageWindow;
-import jsinterop.base.JsPropertyMap;
-
-/**
- * Implementation of Storage with non-native events.
- *
- *
- * Implementation of StorageEvents is incomplete for many browsers. This class
- * amends the properties consistently with W3C's StorageEvent.
- *
- */
-class StorageImplNonNativeEvents extends StorageImpl {
-
- private static StorageEvent createStorageEvent(
- String key, String oldValue, String newValue, String storageName) {
- JsPropertyMap init = JsPropertyMap.of();
- init.set("key", key);
- init.set("oldValue", oldValue);
- init.set("newValue", newValue);
- init.set("url", window.location.getHref());
- init.set("storageArea", "localStorage".equals(storageName) ?
- WebStorageWindow.of(window).localStorage :
- WebStorageWindow.of(window).sessionStorage);
- return StorageEvent.createEvent(init);
- }
-
- private static void fireStorageEvent(
- String key, String oldValue, String newValue, String storage) {
- if (hasStorageEventHandlers()) {
- StorageEvent se = createStorageEvent(key, oldValue, newValue, storage);
- handleStorageEvent(se);
- }
- }
-
- @Override
- public void clear(String storage) {
- super.clear(storage);
- fireStorageEvent(null, null, null, storage);
- }
-
- @Override
- public void removeItem(String storage, String key) {
- String oldValue = getItem(storage, key);
- super.removeItem(storage, key);
- fireStorageEvent(key, oldValue, null, storage);
- }
-
- @Override
- public void setItem(String storage, String key, String data) {
- String oldValue = getItem(storage, key);
- super.setItem(storage, key, data);
- fireStorageEvent(key, oldValue, data, storage);
- }
-
- @Override
- protected void addStorageEventHandler0() {
- // no-op
- }
-
- @Override
- protected void removeStorageEventHandler0() {
- // no-op
- }
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/StorageMap.java b/old/src/main/java/org/gwtproject/storage/client/StorageMap.java
deleted file mode 100644
index 9f3ccb7..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/StorageMap.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * Exposes the local/session {@link Storage} as a standard {@link Map
- * Map<String, String>}.
- *
- *
- * Experimental API: This API is still under development
- * and is subject to change.
- *
- *
- *
- * The following characteristics are associated with this Map:
- *
- *
- * Mutable - All 'write' methods ({@link #put(String, String)},
- * {@link #putAll(Map)}, {@link #remove(Object)}, {@link #clear()},
- * {@link Entry#setValue(Object)}) operate as intended;
- * remove() on Iterators - All remove() operations on available
- * Iterators (from {@link #keySet()}, {@link #entrySet()} and {@link #values()})
- * operate as intended;
- * No null values and keys - The Storage doesn't
- * accept keys or values which are null;
- * String values and keys - All keys and values in this Map are
- * String types.
- *
- */
-public class StorageMap extends AbstractMap {
-
- /*
- * Represents a Map.Entry to a Storage item
- */
- private class StorageEntry implements Map.Entry {
- private final String key;
-
- StorageEntry(String key) {
- this.key = key;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry, ?> e = (Map.Entry, ?>) obj;
- return eq(key, e.getKey()) && eq(getValue(), e.getValue());
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- @Override
- public String getValue() {
- return get(key);
- }
-
- @Override
- public int hashCode() {
- return hashCode(key) ^ hashCode(getValue());
- }
-
- @Override
- public String setValue(String value) {
- return put(key, value);
- }
-
- // TODO: Use Objects.equals when GWT's source level >= 7.
- private boolean eq(Object a, Object b) {
- return (a == b) || (a != null && a.equals(b));
- }
-
- // TODO: Use Objects.hashCode when GWT's source level >= 7.
- private int hashCode(Object o) {
- return o != null ? o.hashCode() : 0;
- }
- }
-
- /*
- * Represents an Iterator over all Storage items
- */
- private class StorageEntryIterator implements Iterator> {
- private int index = -1;
- private String lastKey;
-
- @Override
- public boolean hasNext() {
- return index < size() - 1;
- }
-
- @Override
- public Map.Entry next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- index++;
- lastKey = storage.key(index);
- return new StorageEntry(lastKey);
- }
-
- @Override
- public void remove() {
- if (lastKey == null) {
- throw new IllegalStateException();
- }
-
- storage.removeItem(lastKey);
- lastKey = null;
- index--;
- }
- }
-
- /*
- * Represents a Set over all Storage items
- */
- private class StorageEntrySet extends AbstractSet> {
- @Override
- public void clear() {
- StorageMap.this.clear();
- }
-
- @Override
- public boolean contains(Object o) {
- if (!(o instanceof Map.Entry)) {
- return false;
- }
- Map.Entry, ?> e = (Map.Entry, ?>) o;
- Object key = e.getKey();
- Object value = e.getValue();
- return key != null && value != null && value.equals(get(key));
- }
-
- @Override
- public Iterator> iterator() {
- return new StorageEntryIterator();
- }
-
- @Override
- public boolean remove(Object o) {
- if (!contains(o)) {
- return false;
- }
- Map.Entry, ?> entry = (Map.Entry, ?>) o;
- return StorageMap.this.remove(entry.getKey()) != null;
- }
-
- @Override
- public int size() {
- return StorageMap.this.size();
- }
- }
-
- private final Storage storage;
-
- /**
- * Creates the Map with the specified Storage as data provider.
- *
- * @param storage a local/session Storage instance obtained by either
- * {@link Storage#getLocalStorageIfSupported()} or
- * {@link Storage#getSessionStorageIfSupported()}.
- */
- public StorageMap(Storage storage) {
- assert storage != null : "storage cannot be null";
- this.storage = storage;
- }
-
- /**
- * Removes all items from the Storage.
- *
- * @see Storage#clear()
- */
- @Override
- public void clear() {
- storage.clear();
- }
-
- /**
- * Returns true if the Storage contains the specified key,
- * false otherwise.
- */
- @Override
- public boolean containsKey(Object key) {
- return get(key) != null;
- }
-
- /**
- * Returns true if the Storage contains the specified value,
- * false otherwise (or if the specified key is null
- * ).
- */
- @Override
- public boolean containsValue(Object value) {
- if (value == null) {
- throw new NullPointerException();
- }
-
- int s = size();
- for (int i = 0; i < s; i++) {
- if (value.equals(storage.getItem(storage.key(i)))) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns a Set containing all entries of the Storage.
- */
- @Override
- public Set> entrySet() {
- return new StorageEntrySet();
- }
-
- /**
- * Returns the value associated with the specified key in the Storage.
- *
- * @param key the key identifying the value
- * @see Storage#getItem(String)
- */
- @Override
- public String get(Object key) {
- if (key == null) {
- throw new NullPointerException();
- }
-
- return storage.getItem(key.toString());
- }
-
- /**
- * Adds (or overwrites) a new key/value pair in the Storage.
- *
- * @param key the key identifying the value (not null)
- * @param value the value associated with the key (not null)
- * @see Storage#setItem(String, String)
- */
- @Override
- public String put(String key, String value) {
- if (key == null || value == null) {
- throw new NullPointerException();
- }
-
- String old = storage.getItem(key);
- storage.setItem(key, value);
- return old;
- }
-
- /**
- * Removes the key/value pair from the Storage.
- *
- * @param key the key identifying the item to remove
- * @return the value associated with the key - null if the key
- * was not present in the Storage
- * @see Storage#removeItem(String)
- */
- @Override
- public String remove(Object key) {
- if (key == null) {
- throw new NullPointerException();
- }
-
- String k = key.toString();
- String old = storage.getItem(k);
- storage.removeItem(k);
- return old;
- }
-
- /**
- * Returns the number of items in the Storage.
- *
- * @return the number of items
- * @see Storage#getLength()
- */
- @Override
- public int size() {
- return storage.getLength();
- }
-}
diff --git a/old/src/main/java/org/gwtproject/storage/client/package.html b/old/src/main/java/org/gwtproject/storage/client/package.html
deleted file mode 100644
index 4f8f128..0000000
--- a/old/src/main/java/org/gwtproject/storage/client/package.html
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Provides for key-value Storage services.
-
-
-Package Specification
-
-This package contains the public interface to the Storage API. All
-Storage services are to be accessed using types from this package,
-starting with {@link com.google.gwt.storage.client.Storage}.
-
-Related Documentation
-
-For tutorials, examples, guides, and background documentation, please see:
-
-
-
-
\ No newline at end of file
diff --git a/old/src/main/module.gwt.xml b/old/src/main/module.gwt.xml
deleted file mode 100644
index afea59f..0000000
--- a/old/src/main/module.gwt.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
diff --git a/old/src/test/java/org/gwtproject/storage/StorageMapSuite.java b/old/src/test/java/org/gwtproject/storage/StorageMapSuite.java
deleted file mode 100644
index dea3ca5..0000000
--- a/old/src/test/java/org/gwtproject/storage/StorageMapSuite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage;
-
-import com.google.gwt.junit.tools.GWTTestSuite;
-import org.gwtproject.storage.client.LocalStorageMapTest;
-import org.gwtproject.storage.client.SessionStorageMapTest;
-
-import junit.framework.Test;
-
-/**
- * Suite for all Storage Map tests.
- */
-public class StorageMapSuite {
- public static Test suite() {
- GWTTestSuite suite = new GWTTestSuite("Storage Map Tests");
-
- suite.addTestSuite(LocalStorageMapTest.class);
- suite.addTestSuite(SessionStorageMapTest.class);
-
- return suite;
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/StorageSuite.java b/old/src/test/java/org/gwtproject/storage/StorageSuite.java
deleted file mode 100644
index a215f31..0000000
--- a/old/src/test/java/org/gwtproject/storage/StorageSuite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage;
-
-import com.google.gwt.junit.tools.GWTTestSuite;
-import org.gwtproject.storage.client.LocalStorageTest;
-import org.gwtproject.storage.client.SessionStorageTest;
-
-import junit.framework.Test;
-
-/**
- * Suite for all Storage tests.
- */
-public class StorageSuite {
- public static Test suite() {
- GWTTestSuite suite = new GWTTestSuite("Storage Tests");
-
- suite.addTestSuite(LocalStorageTest.class);
- suite.addTestSuite(SessionStorageTest.class);
-
- return suite;
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/LocalStorageMapTest.java b/old/src/test/java/org/gwtproject/storage/client/LocalStorageMapTest.java
deleted file mode 100644
index b0e5a9f..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/LocalStorageMapTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-/**
- * Tests Local {@link StorageMap}.
- */
-public class LocalStorageMapTest extends StorageMapTest {
- @Override
- Storage getStorage() {
- return Storage.getLocalStorageIfSupported();
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/LocalStorageTest.java b/old/src/test/java/org/gwtproject/storage/client/LocalStorageTest.java
deleted file mode 100644
index 7b6ae9d..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/LocalStorageTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-/**
- * Tests Local {@link Storage}.
- */
-public class LocalStorageTest extends StorageTest {
- @Override
- Storage getStorage() {
- return Storage.getLocalStorageIfSupported();
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/MapInterfaceTest.java b/old/src/test/java/org/gwtproject/storage/client/MapInterfaceTest.java
deleted file mode 100644
index 3fe6887..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/MapInterfaceTest.java
+++ /dev/null
@@ -1,1544 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import static java.util.Collections.singleton;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.junit.client.GWTTestCase;
-import org.gwtproject.testutils.TestUtils;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Tests representing the contract of {@link Map}. Concrete subclasses of this
- * base class test conformance of concrete {@link Map} subclasses to that
- * contract.
- *
- * TODO: Descriptive assertion messages, with hints as to probable fixes.
- * TODO: Add another constructor parameter indicating whether the class under
- * test is ordered, and check the order if so.
- * TODO: Refactor to share code with SetTestBuilder.
- *
- * @param the type of keys used by the maps under test
- * @param the type of mapped values used the maps under test
- */
-public abstract class MapInterfaceTest extends GWTTestCase {
-
- protected final boolean supportsPut;
- protected final boolean supportsRemove;
- protected final boolean supportsClear;
- protected final boolean allowsNullKeys;
- protected final boolean allowsNullValues;
- protected final boolean supportsIteratorRemove;
-
- /**
- * Creates a new, empty instance of the class under test.
- *
- * @return a new, empty map instance.
- * @throws UnsupportedOperationException if it's not possible to make an empty
- * instance of the class under test.
- */
- protected abstract Map makeEmptyMap()
- throws UnsupportedOperationException;
-
- /**
- * Creates a new, non-empty instance of the class under test.
- *
- * @return a new, non-empty map instance.
- * @throws UnsupportedOperationException if it's not possible to make a
- * non-empty instance of the class under test.
- */
- protected abstract Map makePopulatedMap()
- throws UnsupportedOperationException;
-
- /**
- * Creates a new key that is not expected to be found in
- * {@link #makePopulatedMap()}.
- *
- * @return a key.
- * @throws UnsupportedOperationException if it's not possible to make a key
- * that will not be found in the map.
- */
- protected abstract K getKeyNotInPopulatedMap()
- throws UnsupportedOperationException;
-
- /**
- * Creates a new value that is not expected to be found in
- * {@link #makePopulatedMap()}.
- *
- * @return a value.
- * @throws UnsupportedOperationException if it's not possible to make a value
- * that will not be found in the map.
- */
- protected abstract V getValueNotInPopulatedMap()
- throws UnsupportedOperationException;
-
- /**
- * Constructor that assigns {@code supportsIteratorRemove} the same value as
- * {@code supportsRemove}.
- */
- protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues,
- boolean supportsPut, boolean supportsRemove, boolean supportsClear) {
- this(allowsNullKeys, allowsNullValues, supportsPut, supportsRemove,
- supportsClear, supportsRemove);
- }
-
- /**
- * Constructor with an explicit {@code supportsIteratorRemove} parameter.
- */
- protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues,
- boolean supportsPut, boolean supportsRemove, boolean supportsClear,
- boolean supportsIteratorRemove) {
- this.supportsPut = supportsPut;
- this.supportsRemove = supportsRemove;
- this.supportsClear = supportsClear;
- this.allowsNullKeys = allowsNullKeys;
- this.allowsNullValues = allowsNullValues;
- this.supportsIteratorRemove = supportsIteratorRemove;
- }
-
- /**
- * Used by tests that require a map, but don't care whether it's populated or
- * not.
- *
- * @return a new map instance.
- */
- protected Map makeEitherMap() {
- try {
- return makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return makeEmptyMap();
- }
- }
-
- protected final boolean supportsValuesHashCode(Map map) {
- // get the first non-null value
- Collection values = map.values();
- for (V value : values) {
- if (value != null) {
- try {
- value.hashCode();
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- }
- return true;
- }
-
- /**
- * Checks all the properties that should always hold of a map. Also calls {@link
- * #assertMoreInvariants} to check invariants that are peculiar to specific implementations.
- *
- * @see #assertMoreInvariants
- * @param map the map to check.
- */
- @SuppressWarnings("CollectionIncompatibleType")
- protected final void assertInvariants(Map map) {
- Set keySet = map.keySet();
- Collection valueCollection = map.values();
- Set> entrySet = map.entrySet();
-
- assertEquals(map.size() == 0, map.isEmpty());
- assertEquals(map.size(), keySet.size());
- assertEquals(keySet.size() == 0, keySet.isEmpty());
- assertEquals(!keySet.isEmpty(), keySet.iterator().hasNext());
-
- int expectedKeySetHash = 0;
- for (K key : keySet) {
- V value = map.get(key);
- expectedKeySetHash += key != null ? key.hashCode() : 0;
- assertTrue(map.containsKey(key));
- assertTrue(map.containsValue(value));
- assertTrue(valueCollection.contains(value));
- assertTrue(valueCollection.containsAll(Collections.singleton(value)));
- assertTrue(entrySet.contains(mapEntry(key, value)));
- assertTrue(allowsNullKeys || (key != null));
- }
- assertEquals(expectedKeySetHash, keySet.hashCode());
-
- assertEquals(map.size(), valueCollection.size());
- assertEquals(valueCollection.size() == 0, valueCollection.isEmpty());
- assertEquals(!valueCollection.isEmpty(),
- valueCollection.iterator().hasNext());
- for (V value : valueCollection) {
- assertTrue(map.containsValue(value));
- assertTrue(allowsNullValues || (value != null));
- }
-
- assertEquals(map.size(), entrySet.size());
- assertEquals(entrySet.size() == 0, entrySet.isEmpty());
- assertEquals(!entrySet.isEmpty(), entrySet.iterator().hasNext());
- assertFalse(entrySet.contains("foo"));
-
- boolean supportsValuesHashCode = supportsValuesHashCode(map);
- if (supportsValuesHashCode) {
- int expectedEntrySetHash = 0;
- for (Entry entry : entrySet) {
- assertTrue(map.containsKey(entry.getKey()));
- assertTrue(map.containsValue(entry.getValue()));
- int expectedHash = (entry.getKey() == null ? 0
- : entry.getKey().hashCode())
- ^ (entry.getValue() == null ? 0 : entry.getValue().hashCode());
- assertEquals(expectedHash, entry.hashCode());
- expectedEntrySetHash += expectedHash;
- }
- assertEquals(expectedEntrySetHash, entrySet.hashCode());
- assertTrue(entrySet.containsAll(new HashSet>(entrySet)));
- assertTrue(entrySet.equals(new HashSet>(entrySet)));
- }
-
- Object[] entrySetToArray1 = entrySet.toArray();
- assertEquals(map.size(), entrySetToArray1.length);
- assertTrue(Arrays.asList(entrySetToArray1).containsAll(entrySet));
-
- Entry, ?>[] entrySetToArray2 = new Entry, ?>[map.size() + 2];
- entrySetToArray2[map.size()] = mapEntry("foo", 1);
- assertSame(entrySetToArray2, entrySet.toArray(entrySetToArray2));
- assertNull(entrySetToArray2[map.size()]);
- assertTrue(Arrays.asList(entrySetToArray2).containsAll(entrySet));
-
- Object[] valuesToArray1 = valueCollection.toArray();
- assertEquals(map.size(), valuesToArray1.length);
- assertTrue(Arrays.asList(valuesToArray1).containsAll(valueCollection));
-
- Object[] valuesToArray2 = new Object[map.size() + 2];
- valuesToArray2[map.size()] = "foo";
- assertSame(valuesToArray2, valueCollection.toArray(valuesToArray2));
- assertNull(valuesToArray2[map.size()]);
- assertTrue(Arrays.asList(valuesToArray2).containsAll(valueCollection));
-
- if (supportsValuesHashCode) {
- int expectedHash = 0;
- for (Entry entry : entrySet) {
- expectedHash += entry.hashCode();
- }
- assertEquals(expectedHash, map.hashCode());
- }
-
- assertMoreInvariants(map);
- }
-
- /**
- * Override this to check invariants which should hold true for a particular
- * implementation, but which are not generally applicable to every instance of
- * Map.
- *
- * @param map the map whose additional invariants to check.
- */
- protected void assertMoreInvariants(Map map) {
- }
-
- public void testClear() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- if (supportsClear) {
- map.clear();
- assertTrue(map.isEmpty());
- } else {
- try {
- map.clear();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testContainsKey() {
- final Map map;
- final K unmappedKey;
- try {
- map = makePopulatedMap();
- unmappedKey = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertFalse(map.containsKey(unmappedKey));
- assertTrue(map.containsKey(map.keySet().iterator().next()));
- if (allowsNullKeys) {
- map.containsKey(null);
- } else {
- try {
- map.containsKey(null);
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testContainsValue() {
- final Map map;
- final V unmappedValue;
- try {
- map = makePopulatedMap();
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertFalse(map.containsValue(unmappedValue));
- assertTrue(map.containsValue(map.values().iterator().next()));
- if (allowsNullValues) {
- map.containsValue(null);
- } else {
- try {
- map.containsKey(null);
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySet() {
- final Map map;
- final Set> entrySet;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
-
- entrySet = map.entrySet();
- final K unmappedKey;
- final V unmappedValue;
- try {
- unmappedKey = getKeyNotInPopulatedMap();
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- for (Entry entry : entrySet) {
- assertFalse(unmappedKey.equals(entry.getKey()));
- assertFalse(unmappedValue.equals(entry.getValue()));
- }
- }
-
- public void testEntrySetForEmptyMap() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
- }
-
- public void testEntrySetContainsEntryNullKeyPresent() {
- if (!allowsNullKeys || !supportsPut) {
- return;
- }
- final Map map;
- final Set> entrySet;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
-
- entrySet = map.entrySet();
- final V unmappedValue;
- try {
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- map.put(null, unmappedValue);
- Entry entry = mapEntry(null, unmappedValue);
- assertTrue(entrySet.contains(entry));
- assertFalse(entrySet.contains(mapEntry(null, null)));
- }
-
- public void testEntrySetContainsEntryNullKeyMissing() {
- final Map map;
- final Set> entrySet;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
-
- entrySet = map.entrySet();
- final V unmappedValue;
- try {
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- Entry entry = mapEntry(null, unmappedValue);
- assertFalse(entrySet.contains(entry));
- assertFalse(entrySet.contains(mapEntry(null, null)));
- }
-
- public void testEntrySetIteratorRemove() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Iterator> iterator = entrySet.iterator();
- if (supportsIteratorRemove) {
- int initialSize = map.size();
- Entry entry = iterator.next();
- iterator.remove();
- assertEquals(initialSize - 1, map.size());
- assertFalse(entrySet.contains(entry));
- assertInvariants(map);
- try {
- iterator.remove();
- fail("Expected IllegalStateException.");
- } catch (IllegalStateException e) {
- // Expected.
- }
- } else {
- try {
- iterator.next();
- iterator.remove();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetRemove() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- if (supportsRemove) {
- int initialSize = map.size();
- boolean didRemove = entrySet.remove(entrySet.iterator().next());
- assertTrue(didRemove);
- assertEquals(initialSize - 1, map.size());
- } else {
- try {
- entrySet.remove(entrySet.iterator().next());
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetRemoveMissingKey() {
- final Map map;
- final K key;
- try {
- map = makeEitherMap();
- key = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Entry entry = mapEntry(key, getValueNotInPopulatedMap());
- int initialSize = map.size();
- if (supportsRemove) {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } else {
- try {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } catch (UnsupportedOperationException optional) {
- }
- }
- assertEquals(initialSize, map.size());
- assertFalse(map.containsKey(key));
- assertInvariants(map);
- }
-
- public void testEntrySetRemoveDifferentValue() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- K key = map.keySet().iterator().next();
- Entry entry = mapEntry(key, getValueNotInPopulatedMap());
- int initialSize = map.size();
- if (supportsRemove) {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } else {
- try {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } catch (UnsupportedOperationException optional) {
- }
- }
- assertEquals(initialSize, map.size());
- assertTrue(map.containsKey(key));
- assertInvariants(map);
- }
-
- public void testEntrySetRemoveNullKeyPresent() {
- if (!allowsNullKeys || !supportsPut || !supportsRemove) {
- return;
- }
- final Map map;
- final Set> entrySet;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
-
- entrySet = map.entrySet();
- final V unmappedValue;
- try {
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- map.put(null, unmappedValue);
- assertEquals(unmappedValue, map.get(null));
- assertTrue(map.containsKey(null));
- Entry entry = mapEntry(null, unmappedValue);
- assertTrue(entrySet.remove(entry));
- assertNull(map.get(null));
- assertFalse(map.containsKey(null));
- }
-
- public void testEntrySetRemoveNullKeyMissing() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Entry entry = mapEntry(null, getValueNotInPopulatedMap());
- int initialSize = map.size();
- if (supportsRemove) {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } else {
- try {
- boolean didRemove = entrySet.remove(entry);
- assertFalse(didRemove);
- } catch (UnsupportedOperationException optional) {
- }
- }
- assertEquals(initialSize, map.size());
- assertInvariants(map);
- }
-
- public void testEntrySetRemoveAll() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Set> entriesToRemove = singleton(entrySet.iterator().next());
- if (supportsRemove) {
- int initialSize = map.size();
- boolean didRemove = entrySet.removeAll(entriesToRemove);
- assertTrue(didRemove);
- assertEquals(initialSize - entriesToRemove.size(), map.size());
- for (Entry entry : entriesToRemove) {
- assertFalse(entrySet.contains(entry));
- }
- } else {
- try {
- entrySet.removeAll(entriesToRemove);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetRemoveAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- if (supportsRemove) {
- try {
- entrySet.removeAll(null);
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- entrySet.removeAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetRetainAll() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Set> entriesToRetain = singleton(entrySet.iterator().next());
- if (supportsRemove) {
- boolean shouldRemove = (entrySet.size() > entriesToRetain.size());
- boolean didRemove = entrySet.retainAll(entriesToRetain);
- assertEquals(shouldRemove, didRemove);
- assertEquals(entriesToRetain.size(), map.size());
- for (Entry entry : entriesToRetain) {
- assertTrue(entrySet.contains(entry));
- }
- } else {
- try {
- entrySet.retainAll(entriesToRetain);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetRetainAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- if (supportsRemove) {
- try {
- entrySet.retainAll(null);
- failForMissingNPE(map);
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- entrySet.retainAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetClear() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- if (supportsClear) {
- entrySet.clear();
- assertTrue(entrySet.isEmpty());
- } else {
- try {
- entrySet.clear();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testEntrySetAddAndAddAll() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- final Entry entryToAdd = mapEntry(null, null);
- try {
- entrySet.add(entryToAdd);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- assertInvariants(map);
-
- try {
- entrySet.addAll(singleton(entryToAdd));
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- assertInvariants(map);
- }
-
- public void testEntrySetSetValue() {
- // TODO: Investigate the extent to which, in practice, maps that support
- // put() also support Entry.setValue().
- if (!supportsPut) {
- return;
- }
-
- final Map map;
- final V valueToSet;
- try {
- map = makePopulatedMap();
- valueToSet = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Entry entry = entrySet.iterator().next();
- final V oldValue = entry.getValue();
- final V returnedValue = entry.setValue(valueToSet);
- assertEquals(oldValue, returnedValue);
- assertTrue(entrySet.contains(mapEntry(entry.getKey(), valueToSet)));
- assertEquals(valueToSet, map.get(entry.getKey()));
- assertInvariants(map);
- }
-
- public void testEntrySetSetValueSameValue() {
- // TODO: Investigate the extent to which, in practice, maps that support
- // put() also support Entry.setValue().
- if (!supportsPut) {
- return;
- }
-
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set> entrySet = map.entrySet();
- Entry entry = entrySet.iterator().next();
- final V oldValue = entry.getValue();
- final V returnedValue = entry.setValue(oldValue);
- assertEquals(oldValue, returnedValue);
- assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
- assertEquals(oldValue, map.get(entry.getKey()));
- assertInvariants(map);
- }
-
- public void testEqualsForEqualMap() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- assertEquals(map, map);
- assertEquals(makePopulatedMap(), map);
- assertFalse(map.equals(Collections.emptyMap()));
- // no-inspection ObjectEqualsNull
- assertFalse(map.equals(null));
- }
-
- /*
- * equals does not apply to Storage because there's only one instance so two
- * maps will always be equal.
- */
- public void disabled_testEqualsForLargerMap() {
- if (!supportsPut) {
- return;
- }
-
- final Map map;
- final Map largerMap;
- try {
- map = makePopulatedMap();
- largerMap = makePopulatedMap();
- largerMap.put(getKeyNotInPopulatedMap(), getValueNotInPopulatedMap());
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- assertFalse(map.equals(largerMap));
- }
-
- /*
- * equals does not apply to Storage because there's only one instance so two
- * maps will always be equal.
- */
- public void disabled_testEqualsForSmallerMap() {
- if (!supportsRemove) {
- return;
- }
-
- final Map map;
- final Map smallerMap;
- try {
- map = makePopulatedMap();
- smallerMap = makePopulatedMap();
- smallerMap.remove(smallerMap.keySet().iterator().next());
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- assertFalse(map.equals(smallerMap));
- }
-
- public void testEqualsForEmptyMap() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- assertEquals(map, map);
- assertEquals(makeEmptyMap(), map);
- assertEquals(Collections.emptyMap(), map);
- assertFalse(map.equals(Collections.emptySet()));
- // noinspection ObjectEqualsNull
- assertFalse(map.equals(null));
- }
-
- public void testGet() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- for (Entry entry : map.entrySet()) {
- assertEquals(entry.getValue(), map.get(entry.getKey()));
- }
-
- K unmappedKey = null;
- try {
- unmappedKey = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertNull(map.get(unmappedKey));
- }
-
- public void testGetForEmptyMap() {
- final Map map;
- K unmappedKey = null;
- try {
- map = makeEmptyMap();
- unmappedKey = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertNull(map.get(unmappedKey));
- }
-
- public void testGetNull() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- if (allowsNullKeys) {
- V value = map.get(null);
- if (!allowsNullValues) {
- assertEquals(map.containsKey(null), value != null);
- }
- } else {
- try {
- map.get(null);
- } catch (NullPointerException expected) {
- // in GWT client.
- }
- }
- assertInvariants(map);
- }
-
- public void testHashCode() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
- }
-
- public void testHashCodeForEmptyMap() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
- }
-
- public void testPutNewKey() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- final K keyToPut;
- final V valueToPut;
- try {
- keyToPut = getKeyNotInPopulatedMap();
- valueToPut = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- if (supportsPut) {
- int initialSize = map.size();
- V oldValue = map.put(keyToPut, valueToPut);
- assertEquals(valueToPut, map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(valueToPut));
- assertEquals(initialSize + 1, map.size());
- assertNull(oldValue);
- } else {
- try {
- map.put(keyToPut, valueToPut);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testPutExistingKey() {
- final Map map;
- final K keyToPut;
- final V valueToPut;
- try {
- map = makePopulatedMap();
- valueToPut = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- keyToPut = map.keySet().iterator().next();
- if (supportsPut) {
- int initialSize = map.size();
- map.put(keyToPut, valueToPut);
- assertEquals(valueToPut, map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(valueToPut));
- assertEquals(initialSize, map.size());
- } else {
- try {
- map.put(keyToPut, valueToPut);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testPutNullKey() {
- if (!supportsPut) {
- return;
- }
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- final V valueToPut;
- try {
- valueToPut = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- if (allowsNullKeys) {
- final V oldValue = map.get(null);
- final V returnedValue = map.put(null, valueToPut);
- assertEquals(oldValue, returnedValue);
- assertEquals(valueToPut, map.get(null));
- assertTrue(map.containsKey(null));
- assertTrue(map.containsValue(valueToPut));
- } else {
- try {
- map.put(null, valueToPut);
- fail("Expected RuntimeException");
- } catch (RuntimeException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testPutNullValue() {
- if (!supportsPut) {
- return;
- }
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- final K keyToPut;
- try {
- keyToPut = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- if (allowsNullValues) {
- int initialSize = map.size();
- final V oldValue = map.get(keyToPut);
- final V returnedValue = map.put(keyToPut, null);
- assertEquals(oldValue, returnedValue);
- assertNull(map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(null));
- assertEquals(initialSize + 1, map.size());
- } else {
- try {
- map.put(keyToPut, null);
- fail("Expected RuntimeException");
- } catch (RuntimeException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testPutNullValueForExistingKey() {
- if (!supportsPut) {
- return;
- }
- final Map map;
- final K keyToPut;
- try {
- map = makePopulatedMap();
- keyToPut = map.keySet().iterator().next();
- } catch (UnsupportedOperationException e) {
- return;
- }
- if (allowsNullValues) {
- int initialSize = map.size();
- final V oldValue = map.get(keyToPut);
- final V returnedValue = map.put(keyToPut, null);
- assertEquals(oldValue, returnedValue);
- assertNull(map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(null));
- assertEquals(initialSize, map.size());
- } else {
- try {
- map.put(keyToPut, null);
- fail("Expected RuntimeException");
- } catch (RuntimeException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testPutAllNewKey() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- final K keyToPut;
- final V valueToPut;
- try {
- keyToPut = getKeyNotInPopulatedMap();
- valueToPut = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- final Map mapToPut = Collections.singletonMap(keyToPut, valueToPut);
- if (supportsPut) {
- int initialSize = map.size();
- map.putAll(mapToPut);
- assertEquals(valueToPut, map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(valueToPut));
- assertEquals(initialSize + 1, map.size());
- } else {
- try {
- map.putAll(mapToPut);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testPutAllExistingKey() {
- final Map map;
- final K keyToPut;
- final V valueToPut;
- try {
- map = makePopulatedMap();
- valueToPut = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- keyToPut = map.keySet().iterator().next();
- final Map mapToPut = Collections.singletonMap(keyToPut, valueToPut);
- int initialSize = map.size();
- if (supportsPut) {
- map.putAll(mapToPut);
- assertEquals(valueToPut, map.get(keyToPut));
- assertTrue(map.containsKey(keyToPut));
- assertTrue(map.containsValue(valueToPut));
- } else {
- try {
- map.putAll(mapToPut);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertEquals(initialSize, map.size());
- assertInvariants(map);
- }
-
- public void testRemove() {
- final Map map;
- final K keyToRemove;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- keyToRemove = map.keySet().iterator().next();
- if (supportsRemove) {
- int initialSize = map.size();
- V expectedValue = map.get(keyToRemove);
- V oldValue = map.remove(keyToRemove);
- assertEquals(expectedValue, oldValue);
- assertFalse(map.containsKey(keyToRemove));
- assertEquals(initialSize - 1, map.size());
- } else {
- try {
- map.remove(keyToRemove);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testRemoveMissingKey() {
- final Map map;
- final K keyToRemove;
- try {
- map = makePopulatedMap();
- keyToRemove = getKeyNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- if (supportsRemove) {
- int initialSize = map.size();
- assertNull(map.remove(keyToRemove));
- assertEquals(initialSize, map.size());
- } else {
- try {
- map.remove(keyToRemove);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testSize() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
- }
-
- public void testKeySetClear() {
- final Map map;
- try {
- map = makeEitherMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set keySet = map.keySet();
- if (supportsClear) {
- keySet.clear();
- assertTrue(keySet.isEmpty());
- } else {
- try {
- keySet.clear();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testKeySetRemoveAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set keySet = map.keySet();
- if (supportsRemove) {
- try {
- keySet.removeAll(null);
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- keySet.removeAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testKeySetRetainAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Set keySet = map.keySet();
- if (supportsRemove) {
- try {
- keySet.retainAll(null);
- failForMissingNPE(map);
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- keySet.retainAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testValues() {
- final Map map;
- final Collection valueCollection;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- assertInvariants(map);
-
- valueCollection = map.values();
- final V unmappedValue;
- try {
- unmappedValue = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
- for (V value : valueCollection) {
- assertFalse(unmappedValue.equals(value));
- }
- }
-
- public void testValuesIteratorRemove() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- Iterator iterator = valueCollection.iterator();
- if (supportsIteratorRemove) {
- int initialSize = map.size();
- iterator.next();
- iterator.remove();
- assertEquals(initialSize - 1, map.size());
- // (We can't assert that the values collection no longer contains the
- // removed value, because the underlying map can have multiple mappings
- // to the same value.)
- assertInvariants(map);
- try {
- iterator.remove();
- fail("Expected IllegalStateException.");
- } catch (IllegalStateException e) {
- // Expected.
- }
- } else {
- try {
- iterator.next();
- iterator.remove();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesRemove() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- if (supportsRemove) {
- int initialSize = map.size();
- valueCollection.remove(valueCollection.iterator().next());
- assertEquals(initialSize - 1, map.size());
- // (We can't assert that the values collection no longer contains the
- // removed value, because the underlying map can have multiple mappings
- // to the same value.)
- } else {
- try {
- valueCollection.remove(valueCollection.iterator().next());
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesRemoveMissing() {
- final Map map;
- final V valueToRemove;
- try {
- map = makeEitherMap();
- valueToRemove = getValueNotInPopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- int initialSize = map.size();
- if (supportsRemove) {
- assertFalse(valueCollection.remove(valueToRemove));
- } else {
- try {
- assertFalse(valueCollection.remove(valueToRemove));
- } catch (UnsupportedOperationException e) {
- // Tolerated.
- }
- }
- assertEquals(initialSize, map.size());
- assertInvariants(map);
- }
-
- public void testValuesRemoveAll() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- Set valuesToRemove = singleton(valueCollection.iterator().next());
- if (supportsRemove) {
- valueCollection.removeAll(valuesToRemove);
- for (V value : valuesToRemove) {
- assertFalse(valueCollection.contains(value));
- }
- for (V value : valueCollection) {
- assertFalse(valuesToRemove.contains(value));
- }
- } else {
- try {
- valueCollection.removeAll(valuesToRemove);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesRemoveAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection values = map.values();
- if (supportsRemove) {
- try {
- values.removeAll(null);
- failForMissingNPE(map);
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- values.removeAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesRetainAll() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- Set valuesToRetain = singleton(valueCollection.iterator().next());
- if (supportsRemove) {
- valueCollection.retainAll(valuesToRetain);
- for (V value : valuesToRetain) {
- assertTrue(valueCollection.contains(value));
- }
- for (V value : valueCollection) {
- assertTrue(valuesToRetain.contains(value));
- }
- } else {
- try {
- valueCollection.retainAll(valuesToRetain);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesRetainAllNullFromEmpty() {
- final Map map;
- try {
- map = makeEmptyMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection values = map.values();
- if (supportsRemove) {
- try {
- values.retainAll(null);
- failForMissingNPE(map);
- } catch (NullPointerException expected) {
- }
- } else {
- try {
- values.retainAll(null);
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException expected) {
- }
- }
- assertInvariants(map);
- }
-
- public void testValuesClear() {
- final Map map;
- try {
- map = makePopulatedMap();
- } catch (UnsupportedOperationException e) {
- return;
- }
-
- Collection valueCollection = map.values();
- if (supportsClear) {
- valueCollection.clear();
- assertTrue(valueCollection.isEmpty());
- } else {
- try {
- valueCollection.clear();
- fail("Expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // Expected.
- }
- }
- assertInvariants(map);
- }
-
- private void failForMissingNPE(Map map) {
- if (map.isEmpty() && !GWT.isScript() && TestUtils.getJdkVersion() < 8) {
- // JDK < 8 does not conform to the specification if the map is empty.
- return;
- }
- fail("Should have thrown NullPointerException");
- }
-
- private static Entry mapEntry(K key, V value) {
- return Collections.singletonMap(key, value).entrySet().iterator().next();
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/SessionStorageMapTest.java b/old/src/test/java/org/gwtproject/storage/client/SessionStorageMapTest.java
deleted file mode 100644
index 9452242..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/SessionStorageMapTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-/**
- * Tests Session {@link StorageMap}.
- *
- * Because HtmlUnit does not support Storage, you will need to run these tests
- * manually by adding this line to your VM args: -Dgwt.args="-runStyle Manual:1"
- * If you are using Eclipse and GPE, go to "run configurations" or
- * "debug configurations", select the test you would like to run, and put this
- * line in the VM args under the arguments tab: -Dgwt.args="-runStyle Manual:1"
- */
-public class SessionStorageMapTest extends StorageMapTest {
- @Override
- Storage getStorage() {
- return Storage.getLocalStorageIfSupported();
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/SessionStorageTest.java b/old/src/test/java/org/gwtproject/storage/client/SessionStorageTest.java
deleted file mode 100644
index ca929c7..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/SessionStorageTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-/**
- * Tests Session {@link Storage}.
- */
-public class SessionStorageTest extends StorageTest {
- @Override
- Storage getStorage() {
- return Storage.getSessionStorageIfSupported();
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/StorageMapTest.java b/old/src/test/java/org/gwtproject/storage/client/StorageMapTest.java
deleted file mode 100644
index 098829e..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/StorageMapTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.gwtproject.storage.client;
-
-import java.util.Map;
-
-/**
- * Tests {@link StorageMap}.
- */
-public abstract class StorageMapTest extends MapInterfaceTest {
- protected Storage storage;
-
- public StorageMapTest() {
- super(false, false, true, true, true);
- }
-
- @Override
- public String getModuleName() {
- return "org.gwtproject.storage.StorageTestModule";
- }
-
- @Override
- protected void gwtSetUp() throws Exception {
- storage = getStorage();
- if (storage == null) {
- return; // do not run if not supported
- }
-
- // setup for tests by emptying storage
- storage.clear();
- }
-
- /**
- * Returns a {@link Storage} object.
- *
- * Override to return either a LocalStorage or a SessionStorage
- *
- * @return a {@link Storage} object
- */
- abstract Storage getStorage();
-
- @Override
- protected String getKeyNotInPopulatedMap()
- throws UnsupportedOperationException {
- return "nonExistingKey";
- }
-
- @Override
- protected String getValueNotInPopulatedMap()
- throws UnsupportedOperationException {
- return "nonExistingValue";
- }
-
- @Override
- protected Map makeEmptyMap()
- throws UnsupportedOperationException {
- if (storage == null) {
- throw new UnsupportedOperationException("StorageMap not supported because Storage is not supported.");
- }
-
- storage.clear();
-
- return new StorageMap(storage);
- }
-
- @Override
- protected Map makePopulatedMap()
- throws UnsupportedOperationException {
- if (storage == null) {
- throw new UnsupportedOperationException("StorageMap not supported because Storage is not supported.");
- }
-
- storage.clear();
-
- storage.setItem("one", "January");
- storage.setItem("two", "February");
- storage.setItem("three", "March");
- storage.setItem("four", "April");
- storage.setItem("five", "May");
-
- return new StorageMap(storage);
- }
-}
diff --git a/old/src/test/java/org/gwtproject/storage/client/StorageTest.java b/old/src/test/java/org/gwtproject/storage/client/StorageTest.java
deleted file mode 100644
index 8e045be..0000000
--- a/old/src/test/java/org/gwtproject/storage/client/StorageTest.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.storage.client;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.user.client.Timer;
-import org.gwtproject.event.shared.HandlerRegistration;
-
-/**
- * Tests {@link Storage}.
- */
-public abstract class StorageTest extends GWTTestCase {
- protected Storage storage;
- protected StorageEvent.Handler handler;
- protected StorageEvent.Handler handler2;
-
- private native boolean isFirefox35OrLater() /*-{
- var geckoVersion = @com.google.gwt.dom.client.DOMImplMozilla::getGeckoVersion()();
- return (geckoVersion != -1) && (geckoVersion >= 1009001);
- }-*/;
-
- private native boolean isSafari3OrBefore() /*-{
- return @com.google.gwt.dom.client.DOMImplWebkit::isWebkit525OrBefore()();
- }-*/;
-
- @Override
- public String getModuleName() {
- return "org.gwtproject.storage.Storage";
- }
-
- @Override
- protected void gwtSetUp() throws Exception {
- storage = getStorage();
- if (storage == null) {
- return; // do not run if not supported
- }
-
- // setup for tests by removing event handler
- if (handler != null) {
- storage.removeStorageEventHandler(handler);
- handler = null;
- }
- if (handler2 != null) {
- storage.removeStorageEventHandler(handler2);
- handler2 = null;
- }
-
- // setup for tests by emptying storage
- storage.clear();
- }
-
- @Override
- protected void gwtTearDown() throws Exception {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- // clean up by removing event handler
- if (handler != null) {
- storage.removeStorageEventHandler(handler);
- handler = null;
- }
- if (handler2 != null) {
- storage.removeStorageEventHandler(handler2);
- handler2 = null;
- }
-
- // clean up by emptying storage
- storage.clear();
- }
-
- /**
- * Returns a {@link Storage} object.
- *
- * Override to return either a LocalStorage or a SessionStorage
- *
- * @return a {@link Storage} object
- */
- abstract Storage getStorage();
-
- public void testClear() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- storage.setItem("foo", "bar");
- assertEquals(1, storage.getLength());
- storage.clear();
- assertEquals(0, storage.getLength());
- }
-
- public void testGet() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- storage.setItem("foo1", "bar1");
- storage.setItem("foo2", "bar2");
- assertEquals("bar1", storage.getItem("foo1"));
- assertEquals("bar2", storage.getItem("foo2"));
-
- // getting a value of a key that hasn't been set should return null
- assertNull(
- "Getting a value of a key that hasn't been set should return null",
- storage.getItem("notset"));
- }
-
- public void testLength() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- storage.clear();
- assertEquals(0, storage.getLength());
- storage.setItem("abc", "def");
- assertEquals(1, storage.getLength());
- storage.setItem("ghi", "jkl");
- assertEquals(2, storage.getLength());
- storage.clear();
- assertEquals(0, storage.getLength());
- }
-
- public void testSet() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- assertEquals(null, storage.getItem("foo"));
- assertEquals(0, storage.getLength());
- storage.setItem("foo", "bar1");
- assertEquals("bar1", storage.getItem("foo"));
- assertEquals(1, storage.getLength());
- storage.setItem("foo", "bar2");
- assertEquals("Should be able to overwrite an existing value", "bar2",
- storage.getItem("foo"));
- assertEquals(1, storage.getLength());
-
- // test that using the empty string as a key throws an exception in devmode
- if (!GWT.isScript()) {
- try {
- storage.setItem("", "baz");
- throw new Error("Empty string should be disallowed as a key.");
- } catch (AssertionError e) {
- // expected
- }
- }
- }
-
- public void testKey() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- // key(n) where n >= storage.length() should return null
- assertEquals(null, storage.key(0));
- storage.setItem("a", "b");
- assertEquals(null, storage.key(1));
- storage.clear();
-
- storage.setItem("foo1", "bar");
- assertEquals("foo1", storage.key(0));
- storage.setItem("foo2", "bar");
- // key(0) should be either foo1 or foo2
- assertTrue(storage.key(0).equals("foo1") || storage.key(0).equals("foo2"));
- // foo1 should be either key(0) or key(1)
- assertTrue(storage.key(0).equals("foo1") || storage.key(1).equals("foo1"));
- // foo2 should be either key(0) or key(1)
- assertTrue(storage.key(0).equals("foo2") || storage.key(1).equals("foo2"));
- }
-
- public void testRemoveItem() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- storage.setItem("foo1", "bar1");
- storage.setItem("foo2", "bar2");
- assertEquals("bar1", storage.getItem("foo1"));
- assertEquals("bar2", storage.getItem("foo2"));
-
- // removing a non-existent key should have no effect
- storage.removeItem("abc");
- assertEquals("bar1", storage.getItem("foo1"));
- assertEquals("bar2", storage.getItem("foo2"));
-
- // removing a key should remove that key and value
- storage.removeItem("foo1");
- assertEquals(null, storage.getItem("foo1"));
- assertEquals("bar2", storage.getItem("foo2"));
- storage.removeItem("foo2");
- assertEquals(null, storage.getItem("foo2"));
- }
-
- public void testClearStorageEvent() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(2000);
- storage.setItem("tcseFoo", "tcseBar");
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- assertNull(event.getKey());
- assertNull(event.getOldValue());
- assertNull(event.getNewValue());
- assertEquals(storage, event.getStorageArea());
- assertNotNull(event.getUrl());
-
- finishTest();
- }
- };
- storage.addStorageEventHandler(handler);
- storage.clear();
- }
-
- public void testSetItemStorageEvent() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(2000);
- storage.setItem("tsiseFoo", "tsiseBarOld");
-
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- assertEquals("tsiseFoo", event.getKey());
- assertEquals("tsiseBarNew", event.getNewValue());
- assertEquals("tsiseBarOld", event.getOldValue());
- assertEquals(storage, event.getStorageArea());
- assertNotNull(event.getUrl());
-
- finishTest();
- }
- };
- storage.addStorageEventHandler(handler);
- storage.setItem("tsiseFoo", "tsiseBarNew");
- }
-
- public void testRemoveItemStorageEvent() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(2000);
- storage.setItem("triseFoo", "triseBarOld");
-
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- assertEquals("triseFoo", event.getKey());
- finishTest();
- }
- };
- storage.addStorageEventHandler(handler);
- storage.removeItem("triseFoo");
- }
-
- public void testHandlerRegistration() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- final boolean[] eventFired = new boolean[1];
- eventFired[0] = false;
-
- delayTestFinish(3000);
-
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- fail("Storage change should not have fired.");
- eventFired[0] = true;
- finishTest();
- }
- };
- HandlerRegistration registration = storage.addStorageEventHandler(handler);
- registration.removeHandler();
-
- // these should fire events, but they should not be caught by handler
- storage.setItem("thrFoo", "thrBar");
- storage.clear();
-
- // schedule timer to make sure event didn't fire async
- new Timer() {
- @Override
- public void run() {
- if (!eventFired[0]) {
- finishTest();
- }
- }
- }.schedule(1000);
- }
-
- public void testEventInEvent() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(3000);
- storage.setItem("teieFoo", "teieBar");
-
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- if ("teieFoo".equals(event.getKey())) {
- storage.clear();
- storage.setItem("teieFoo2", "teieBar2");
- // firing events from within a handler should not corrupt the values.
- assertEquals("teieFoo", event.getKey());
- storage.setItem("teieFooEndTest", "thanks");
- }
- if ("teieFooEndTest".equals(event.getKey())) {
- finishTest();
- }
- }
- };
- storage.addStorageEventHandler(handler);
- storage.removeItem("teieFoo");
- }
-
- public void testMultipleEventHandlers() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(3000);
-
- final int[] eventHandledCount = new int[]{0};
-
- storage.setItem("tmehFoo", "tmehBar");
-
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- if ("tmehFoo".equals(event.getKey())) {
- eventHandledCount[0]++;
- if (eventHandledCount[0] == 2) {
- finishTest();
- }
- }
- }
- };
- storage.addStorageEventHandler(handler);
-
- handler2 = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- if ("tmehFoo".equals(event.getKey())) {
- eventHandledCount[0]++;
- if (eventHandledCount[0] == 2) {
- finishTest();
- }
- }
- }
- };
- storage.addStorageEventHandler(handler2);
- storage.removeItem("tmehFoo");
- }
-
- public void testEventStorageArea() {
- if (storage == null) {
- return; // do not run if not supported
- }
-
- delayTestFinish(2000);
- storage.setItem("tesaFoo", "tesaBar");
- handler = new StorageEvent.Handler() {
- @Override
- public void onStorageChange(StorageEvent event) {
- Storage eventStorage = event.getStorageArea();
- assertEquals(storage, eventStorage);
- boolean equalsLocal = Storage.getLocalStorageIfSupported().equals(
- eventStorage);
- boolean equalsSession = Storage.getSessionStorageIfSupported().equals(
- eventStorage);
- // assert that storage is either local or session, but not both.
- assertFalse(equalsLocal == equalsSession);
-
- finishTest();
- }
- };
- storage.addStorageEventHandler(handler);
- storage.clear();
- }
-
- public void testSupported() {
- // test the isxxxSupported() call
- if (isFirefox35OrLater()) {
- assertNotNull(storage);
- assertTrue(Storage.isLocalStorageSupported());
- assertTrue(Storage.isSessionStorageSupported());
- assertTrue(Storage.isSupported());
- }
- if (isSafari3OrBefore()) {
- assertNull(storage);
- assertFalse(Storage.isLocalStorageSupported());
- assertFalse(Storage.isSessionStorageSupported());
- assertFalse(Storage.isSupported());
- }
- }
-}
diff --git a/old/src/test/java/org/gwtproject/testutils/TestUtils.gwt.xml b/old/src/test/java/org/gwtproject/testutils/TestUtils.gwt.xml
deleted file mode 100644
index d485f79..0000000
--- a/old/src/test/java/org/gwtproject/testutils/TestUtils.gwt.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/old/src/test/java/org/gwtproject/testutils/TestUtils.java b/old/src/test/java/org/gwtproject/testutils/TestUtils.java
deleted file mode 100644
index 5126ced..0000000
--- a/old/src/test/java/org/gwtproject/testutils/TestUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.gwtproject.testutils;
-
-/**
- * Utility functions needed by various tests.
- */
-public class TestUtils {
-
- public static int getJdkVersion() {
- String versionString = System.getProperty("java.version", "none");
- if (versionString.equals("none")) {
- return -1;
- }
-
- return getMajorVersion(versionString);
- }
-
- public static boolean isJvm() {
- return getJdkVersion() != -1;
- }
-
- private static int getMajorVersion(String versionString) {
- String[] split = versionString.split("\\.");
- assert split.length >= 1;
- return Integer.parseInt(split[1]);
- }
-}
diff --git a/old/src/test/resources/org/gwtproject/storage/StorageTest.gwt.xml b/old/src/test/resources/org/gwtproject/storage/StorageTest.gwt.xml
deleted file mode 100644
index 82cb0d2..0000000
--- a/old/src/test/resources/org/gwtproject/storage/StorageTest.gwt.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-