|
| 1 | +/* |
| 2 | + * Copyright (c) 2017 Otávio Santana and others |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * and Apache License v2.0 which accompanies this distribution. |
| 6 | + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. |
| 8 | + * |
| 9 | + * You may elect to redistribute this code under either of these licenses. |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * |
| 13 | + * Otavio Santana |
| 14 | + */ |
| 15 | + |
| 16 | +package org.jnosql.diana.redis.key; |
| 17 | + |
| 18 | + |
| 19 | +import org.jnosql.diana.api.key.BucketManagerFactory; |
| 20 | +import org.junit.After; |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import java.util.Set; |
| 25 | + |
| 26 | +import static org.junit.Assert.assertTrue; |
| 27 | + |
| 28 | +public class RedisSetStringTest { |
| 29 | + |
| 30 | + |
| 31 | + private BucketManagerFactory keyValueEntityManagerFactory; |
| 32 | + |
| 33 | + private Set<String> users; |
| 34 | + |
| 35 | + @Before |
| 36 | + public void init() { |
| 37 | + keyValueEntityManagerFactory = RedisTestUtils.get(); |
| 38 | + users = keyValueEntityManagerFactory.getSet("social-media", String.class); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void shouldAddUsers() { |
| 43 | + assertTrue(users.isEmpty()); |
| 44 | + users.add("otaviojava"); |
| 45 | + assertTrue(users.size() == 1); |
| 46 | + |
| 47 | + users.remove("otaviojava"); |
| 48 | + assertTrue(users.isEmpty()); |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + @SuppressWarnings("unused") |
| 53 | + @Test |
| 54 | + public void shouldIterate() { |
| 55 | + |
| 56 | + users.add("otaviojava"); |
| 57 | + users.add("otaviojava"); |
| 58 | + users.add("felipe"); |
| 59 | + users.add("otaviojava"); |
| 60 | + users.add("felipe"); |
| 61 | + int count = 0; |
| 62 | + for (String user : users) { |
| 63 | + count++; |
| 64 | + } |
| 65 | + assertTrue(count == 2); |
| 66 | + users.remove("otaviojava"); |
| 67 | + users.remove("felipe"); |
| 68 | + count = 0; |
| 69 | + for (String user : users) { |
| 70 | + count++; |
| 71 | + } |
| 72 | + assertTrue(count == 0); |
| 73 | + } |
| 74 | + |
| 75 | + @After |
| 76 | + public void dispose() { |
| 77 | + users.clear(); |
| 78 | + } |
| 79 | +} |
0 commit comments