Package com.google.gwt.storage.client

Examples of com.google.gwt.storage.client.Storage


   }

   @Test
   public void clearSessionStorage() {
      // Arrange
      Storage session = Storage.getSessionStorageIfSupported();
      session.setItem("test", "my test");
      session.setItem("test2", "my test 2");

      // Pre-Assert
      assertThat(session.getLength()).isEqualTo(2);

      // Act
      session.clear();

      // Assert
      assertThat(session.getLength()).isEqualTo(0);
   }
View Full Code Here


   }

   @Test
   public void getLenghtLocalStorage() {
      // Arrange
      Storage local = Storage.getLocalStorageIfSupported();
      local.setItem("test", "my test");
      local.setItem("test", "my test bis");
      local.setItem("test2", "my test 2");

      // Act
      int length = local.getLength();

      // Assert
      assertThat(length).isEqualTo(2);
   }
View Full Code Here

   }

   @Test
   public void getLengthSessionStorage() {
      // Arrange
      Storage session = Storage.getSessionStorageIfSupported();
      session.setItem("test", "my test");
      session.setItem("test", "my test bis");
      session.setItem("test2", "my test 2");

      // Act
      int length = session.getLength();

      // Assert
      assertThat(length).isEqualTo(2);
   }
View Full Code Here

   }

   @Test
   public void itemLocalStorage() {
      // Arrange
      Storage local = Storage.getLocalStorageIfSupported();

      // Act
      local.setItem("test", "my test");

      // Assert
      assertThat(local.getItem("test")).isEqualTo("my test");
   }
View Full Code Here

   }

   @Test
   public void itemSessionStorage() {
      // Arrange
      Storage session = Storage.getSessionStorageIfSupported();

      // Act
      session.setItem("test", "my test");

      // Assert
      assertThat(session.getItem("test")).isEqualTo("my test");
   }
View Full Code Here

   }

   @Test
   public void keyLocalStorage() {
      // Arrange
      Storage local = Storage.getLocalStorageIfSupported();
      local.setItem("test0", "my test 0");
      local.setItem("test1", "my test 1");
      local.setItem("test2", "my test 2");

      // Act
      String key0 = local.key(0);
      String key1 = local.key(1);
      String key2 = local.key(2);

      // Assert
      assertThat(key0).isEqualTo("test0");
      assertThat(key1).isEqualTo("test1");
      assertThat(key2).isEqualTo("test2");
View Full Code Here

  /**
   * Saves the current to-do items to local storage
   */
  private void saveState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {

      // JSON encode the items
      JSONArray todoItems = new JSONArray();
      for (int i = 0; i < todos.getList().size(); i++) {
        ToDoItem toDoItem = todos.getList().get(i);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("task", new JSONString(toDoItem.getTitle()));
        jsonObject.put("complete", JSONBoolean.getInstance(toDoItem.isDone()));
        todoItems.set(i, jsonObject);
      }

      // save to local storage
      storage.setItem(STORAGE_KEY, todoItems.toString());
    }
  }
View Full Code Here

      storage.setItem(STORAGE_KEY, todoItems.toString());
    }
  }

  private void loadState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {
      try {
        // get state
        String state = storage.getItem(STORAGE_KEY);

        // parse the JSON array
        JSONArray todoItems = JSONParser.parseStrict(state).isArray();
        for (int i = 0; i < todoItems.size(); i++) {
          // extract the to-do item values
View Full Code Here

  /**
   * Saves the current to-do items to local storage
   */
  private void saveState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {

      // JSON encode the items
      JSONArray todoItems = new JSONArray();
      for (int i = 0; i < todos.getList().size(); i++) {
        ToDoItem toDoItem = todos.getList().get(i);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("task", new JSONString(toDoItem.getTitle()));
        jsonObject.put("complete", JSONBoolean.getInstance(toDoItem.isDone()));
        todoItems.set(i, jsonObject);
      }

      // save to local storage
      storage.setItem(STORAGE_KEY, todoItems.toString());
    }
  }
View Full Code Here

      storage.setItem(STORAGE_KEY, todoItems.toString());
    }
  }

  private void loadState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {
      try {
        // get state
        String state = storage.getItem(STORAGE_KEY);

        // parse the JSON array
        JSONArray todoItems = JSONParser.parseStrict(state).isArray();
        for (int i = 0; i < todoItems.size(); i++) {
          // extract the to-do item values
View Full Code Here

TOP

Related Classes of com.google.gwt.storage.client.Storage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.