/v3.2/nimbits-tds/test/TestGson.java

http://nimbits-server.googlecode.com/ · Java · 53 lines · 24 code · 11 blank · 18 comment · 0 complexity · c5482cecfc5ea19df113d1d49249eb32 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * 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.
  12. */
  13. import com.google.gson.Gson;
  14. import com.nimbits.client.model.common.CommonFactoryLocator;
  15. import com.nimbits.client.model.user.User;
  16. import com.nimbits.client.model.user.UserModel;
  17. import com.nimbits.server.gson.GsonFactory;
  18. import com.nimbits.server.user.UserModelFactory;
  19. import org.junit.Test;
  20. import static org.junit.Assert.assertNotNull;
  21. /**
  22. * Created by bsautner
  23. * User: benjamin
  24. * Date: 8/6/11
  25. * Time: 10:11 AM
  26. */
  27. public class TestGson {
  28. Gson gson = GsonFactory.getInstance();
  29. @Test
  30. public void testConvertUser() {
  31. User u = UserModelFactory.createUserModel(0);
  32. u.setEmail(CommonFactoryLocator.getInstance().createEmailAddress("bsautner@gmail.com"));
  33. String json = gson.toJson(u);
  34. User u2 = gson.fromJson(json, UserModel.class);
  35. assertNotNull(u2);
  36. }
  37. @Test
  38. public void testGetType() {
  39. User u = UserModelFactory.createUserModel(0);
  40. String json = gson.toJson(u);
  41. }
  42. }