Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add j2cl-tests #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gwt-storage-gwt2-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<properties>
<maven.gwt.plugin>1.0.0</maven.gwt.plugin>

<gwt.timer.version>1.0.0-RC1</gwt.timer.version>
<gwt.version>2.9.0</gwt.version>
<junit.version>4.13.1</junit.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ protected void gwtSetUp() throws Exception {

// setup for tests by removing event handler
if (handler != null) {
storage.removeStorageEventHandler(handler);
Storage.removeStorageEventHandler(handler);
handler = null;
}
if (handler2 != null) {
storage.removeStorageEventHandler(handler2);
Storage.removeStorageEventHandler(handler2);
handler2 = null;
}

Expand All @@ -62,18 +62,18 @@ protected void gwtSetUp() throws Exception {
}

@Override
protected void gwtTearDown() throws Exception {
protected void gwtTearDown() {
if (storage == null) {
return; // do not run if not supported
}

// clean up by removing event handler
if (handler != null) {
storage.removeStorageEventHandler(handler);
Storage.removeStorageEventHandler(handler);
handler = null;
}
if (handler2 != null) {
storage.removeStorageEventHandler(handler2);
Storage.removeStorageEventHandler(handler2);
handler2 = null;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public void testSet() {
return; // do not run if not supported
}

assertEquals(null, storage.getItem("foo"));
assertNull(storage.getItem("foo"));
assertEquals(0, storage.getLength());
storage.setItem("foo", "bar1");
assertEquals("bar1", storage.getItem("foo"));
Expand All @@ -163,9 +163,9 @@ public void testKey() {
}

// key(n) where n >= storage.length() should return null
assertEquals(null, storage.key(0));
assertNull(storage.key(0));
storage.setItem("a", "b");
assertEquals(null, storage.key(1));
assertNull(storage.key(1));
storage.clear();

storage.setItem("foo1", "bar");
Expand Down Expand Up @@ -196,10 +196,10 @@ public void testRemoveItem() {

// removing a key should remove that key and value
storage.removeItem("foo1");
assertEquals(null, storage.getItem("foo1"));
assertNull(storage.getItem("foo1"));
assertEquals("bar2", storage.getItem("foo2"));
storage.removeItem("foo2");
assertEquals(null, storage.getItem("foo2"));
assertNull(storage.getItem("foo2"));
}

public void testClearStorageEvent() {
Expand All @@ -210,19 +210,16 @@ public void testClearStorageEvent() {
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());
event -> {
assertNull(event.getKey());
assertNull(event.getOldValue());
assertNull(event.getNewValue());
assertEquals(storage, event.getStorageArea());
assertNotNull(event.getUrl());

finishTest();
}
finishTest();
};
storage.addStorageEventHandler(handler);
Storage.addStorageEventHandler(handler);
storage.clear();
}

Expand All @@ -235,19 +232,16 @@ public void testSetItemStorageEvent() {
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());
event -> {
assertEquals("tsiseFoo", event.getKey());
assertEquals("tsiseBarNew", event.getNewValue());
assertEquals("tsiseBarOld", event.getOldValue());
assertEquals(storage, event.getStorageArea());
assertNotNull(event.getUrl());

finishTest();
}
finishTest();
};
storage.addStorageEventHandler(handler);
Storage.addStorageEventHandler(handler);
storage.setItem("tsiseFoo", "tsiseBarNew");
}

Expand All @@ -260,14 +254,11 @@ public void testRemoveItemStorageEvent() {
storage.setItem("triseFoo", "triseBarOld");

handler =
new StorageEvent.Handler() {
@Override
public void onStorageChange(StorageEvent event) {
assertEquals("triseFoo", event.getKey());
finishTest();
}
event -> {
assertEquals("triseFoo", event.getKey());
finishTest();
};
storage.addStorageEventHandler(handler);
Storage.addStorageEventHandler(handler);
storage.removeItem("triseFoo");
}

Expand All @@ -277,20 +268,16 @@ public void testHandlerRegistration() {
}

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();
}
event -> {
fail("Storage change should not have fired.");
eventFired[0] = true;
finishTest();
};
HandlerRegistration registration = storage.addStorageEventHandler(handler);
HandlerRegistration registration = Storage.addStorageEventHandler(handler);
registration.removeHandler();

// these should fire events, but they should not be caught by handler
Expand All @@ -317,22 +304,19 @@ public void testEventInEvent() {
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();
}
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.addStorageEventHandler(handler);
storage.removeItem("teieFoo");
}

Expand All @@ -348,32 +332,26 @@ public void testMultipleEventHandlers() {
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();
}
event -> {
if ("tmehFoo".equals(event.getKey())) {
eventHandledCount[0]++;
if (eventHandledCount[0] == 2) {
finishTest();
}
}
};
storage.addStorageEventHandler(handler);
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();
}
event -> {
if ("tmehFoo".equals(event.getKey())) {
eventHandledCount[0]++;
if (eventHandledCount[0] == 2) {
finishTest();
}
}
};
storage.addStorageEventHandler(handler2);
Storage.addStorageEventHandler(handler2);
storage.removeItem("tmehFoo");
}

Expand All @@ -385,20 +363,17 @@ public void testEventStorageArea() {
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);
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();
}
finishTest();
};
storage.addStorageEventHandler(handler);
Storage.addStorageEventHandler(handler);
storage.clear();
}

Expand Down
8 changes: 8 additions & 0 deletions gwt-storage-j2cl-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- CI -->
<vertispan.j2cl.repo.url>https://repo.vertispan.com/j2cl/</vertispan.j2cl.repo.url>

<gwt.timer.version>1.0.0-RC1</gwt.timer.version>
<j2cl.version>0.8-SNAPSHOT</j2cl.version>
</properties>

Expand All @@ -47,6 +48,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.gwtproject.timer</groupId>
<artifactId>gwt-timer</artifactId>
<version>${gwt.timer.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.gwtproject.storage</groupId>
<artifactId>gwt-storage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import com.google.j2cl.junit.apt.J2clTestInput;

/** Tests Local {@link StorageMap}. */
@J2clTestInput(SessionStorageMapTest.class)
@J2clTestInput(LocalStorageMapTest.class)
public class LocalStorageMapTest extends StorageMapTest {
@Override
Storage getStorage() {
public Storage getStorage() {
return Storage.getLocalStorageIfSupported();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
*/
package org.gwtproject.storage.client;

import com.google.j2cl.junit.apt.J2clTestInput;

/** Tests Local {@link Storage}. */
@J2clTestInput(LocalStorageTest.class)
public class LocalStorageTest extends StorageTest {
@Override
Storage getStorage() {
public Storage getStorage() {
return Storage.getLocalStorageIfSupported();
}
}
Loading