예제 #1
0
 @Test
 public void testEqualsAndHashCode() {
   MutableList<String> one = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   List<String> oneA = new ArrayList<String>(one);
   Verify.assertEqualsAndHashCode(one, oneA);
   Verify.assertPostSerializedEqualsAndHashCode(one);
 }
예제 #2
0
 @Test
 public void without() {
   MutableList<Integer> list = new SextupletonList<Integer>(1, 2, 3, 2, 3, 4);
   Assert.assertSame(list, list.without(9));
   list = list.without(2);
   Verify.assertListsEqual(FastList.newListWith(1, 3, 2, 3, 4), list);
   Verify.assertInstanceOf(QuintupletonList.class, list);
 }
예제 #3
0
 @Override
 public void withoutKey() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A");
   MutableMap<Integer, String> mapWithout = map.withoutKey(2);
   Assert.assertSame(map, mapWithout);
   mapWithout = map.withoutKey(1);
   Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout);
   Verify.assertInstanceOf(EmptyMap.class, mapWithout);
 }
예제 #4
0
 @Override
 public void withoutAllKeys() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A");
   MutableMap<Integer, String> mapWithout = map.withoutAllKeys(FastList.newListWith(2, 3));
   Assert.assertSame(map, mapWithout);
   mapWithout = map.withoutAllKeys(FastList.newListWith(1, 2));
   Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout);
   Verify.assertInstanceOf(EmptyMap.class, mapWithout);
 }
 @Override
 @Test
 public void testNewWithout() {
   ImmutableSet<Integer> immutable = this.classUnderTest();
   Verify.assertSize(3, immutable.newWithout(4).castToSet());
   Verify.assertSize(3, immutable.newWithout(3).castToSet());
   Verify.assertSize(3, immutable.newWithout(2).castToSet());
   Verify.assertSize(3, immutable.newWithout(1).castToSet());
   Verify.assertSize(4, immutable.newWithout(0).castToSet());
 }
예제 #6
0
 @Test
 public void testGet() {
   Verify.assertStartsWith(this.list, "1", "2", "3", "4", "5", "6");
   Verify.assertThrows(
       IndexOutOfBoundsException.class,
       new Runnable() {
         public void run() {
           SextupletonListTest.this.list.get(6);
         }
       });
 }
예제 #7
0
  @Override
  @Test
  public void reject() {
    MutableMap<String, String> map = this.classUnderTest();

    MutableMap<String, String> empty = map.filterNot(Predicates2.alwaysTrue());
    Verify.assertInstanceOf(EmptyMap.class, empty);

    MutableMap<String, String> full = map.filterNot(Predicates2.alwaysFalse());
    Verify.assertInstanceOf(SingletonMap.class, full);
    Assert.assertEquals(map, full);
  }
예제 #8
0
  @Override
  public void withKeyValue() {
    MutableMap<Integer, String> map1 =
        new SingletonMap<Integer, String>(1, "A").withKeyValue(2, "B");
    Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "A", 2, "B"), map1);
    Verify.assertInstanceOf(DoubletonMap.class, map1);

    MutableMap<Integer, String> map2 = new SingletonMap<Integer, String>(1, "A");
    MutableMap<Integer, String> map2with = map2.withKeyValue(1, "AA");
    Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "AA"), map2with);
    Assert.assertSame(map2, map2with);
  }
예제 #9
0
 @Test
 public void testForLoop() {
   MutableList<String> list = Lists.fixedSize.of("one", "two", "three", "four", "five", "six");
   MutableList<String> upperList =
       Lists.fixedSize.of("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX");
   for (String each : list) {
     Verify.assertContains(each.toUpperCase(), upperList);
   }
 }
예제 #10
0
 @Test
 public void testAdd() {
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           SextupletonListTest.this.list.add("1");
         }
       });
   this.assertUnchanged();
 }
예제 #11
0
 @Override
 @Test
 public void getIfAbsentPutWith() {
   final MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           map.getIfAbsentPutWith(4, Functions.getToString(), 4);
         }
       });
   Assert.assertEquals("1", map.getIfAbsentPutWith(1, Functions.getToString(), 1));
 }
예제 #12
0
 @Override
 @Test
 public void getIfAbsentPut() {
   final MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           map.getIfAbsentPut(4, new Constant<String>("4"));
         }
       });
   Assert.assertEquals("1", map.getIfAbsentPut(1, new Constant<String>("1")));
 }
예제 #13
0
 @Test
 public void checkedCodeBlockRuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedGenerator<String> function =
               new CheckedGenerator<String>() {
                 @Override
                 public String safeValue() {
                   throw new LocalException();
                 }
               };
           function.value();
         }
       });
 }
예제 #14
0
 @Test
 public void checkedPredicate2RuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedPredicate2<String, String> block =
               new CheckedPredicate2<String, String>() {
                 @Override
                 public boolean safeAccept(String object, String param) {
                   throw new LocalException();
                 }
               };
           block.accept("1", "2");
         }
       });
 }
예제 #15
0
 @Test
 public void checkedProcedure2RuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedProcedure2<String, String> block =
               new CheckedProcedure2<String, String>() {
                 @Override
                 public void safeValue(String object, String parameter) {
                   throw new LocalException();
                 }
               };
           block.value("1", "2");
         }
       });
 }
예제 #16
0
 @Test
 public void checkedFunction2RuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedFunction2<String, String, String> block =
               new CheckedFunction2<String, String, String>() {
                 @Override
                 public String safeValue(String argument1, String argument2) {
                   throw new LocalException();
                 }
               };
           block.value("1", "2");
         }
       });
 }
예제 #17
0
 @Test
 public void checkedFunctionRuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedFunction<String, String> block =
               new CheckedFunction<String, String>() {
                 @Override
                 public String safeValueOf(String object) {
                   throw new LocalException();
                 }
               };
           block.valueOf("1");
         }
       });
 }
예제 #18
0
 @Test
 public void checkedObjectIntProcedureRuntimeException() {
   Verify.assertThrows(
       LocalException.class,
       new Runnable() {
         public void run() {
           CheckedObjectIntProcedure<String> block =
               new CheckedObjectIntProcedure<String>() {
                 @Override
                 public void safeValue(String object, int index) {
                   throw new LocalException();
                 }
               };
           block.value("1", 1);
         }
       });
 }
예제 #19
0
 @Test
 public void checkedObjectIntProcedureCheckedException() {
   Verify.assertThrowsWithCause(
       RuntimeException.class,
       IOException.class,
       new Runnable() {
         public void run() {
           CheckedObjectIntProcedure<String> block =
               new CheckedObjectIntProcedure<String>() {
                 @Override
                 public void safeValue(String object, int index) throws IOException {
                   throw new IOException("fail");
                 }
               };
           block.value("1", 1);
         }
       });
 }
예제 #20
0
 @Test
 public void testSet() {
   final MutableList<String> list = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   Assert.assertEquals("1", list.set(0, "6"));
   Assert.assertEquals("2", list.set(1, "5"));
   Assert.assertEquals("3", list.set(2, "4"));
   Assert.assertEquals("4", list.set(3, "3"));
   Assert.assertEquals("5", list.set(4, "2"));
   Assert.assertEquals("6", list.set(5, "1"));
   Assert.assertEquals(FastList.newListWith("6", "5", "4", "3", "2", "1"), list);
   Verify.assertThrows(
       IndexOutOfBoundsException.class,
       new Runnable() {
         public void run() {
           list.set(6, "0");
         }
       });
 }
예제 #21
0
 @Test
 public void checkedCodeBlockCheckedException() {
   Verify.assertThrowsWithCause(
       RuntimeException.class,
       IOException.class,
       new Runnable() {
         public void run() {
           CheckedGenerator<String> function =
               new CheckedGenerator<String>() {
                 @Override
                 public String safeValue() throws IOException {
                   throw new IOException("fail");
                 }
               };
           function.value();
         }
       });
 }
예제 #22
0
 @Test
 public void checkedFunction2CheckedException() {
   Verify.assertThrowsWithCause(
       RuntimeException.class,
       IOException.class,
       new Runnable() {
         public void run() {
           CheckedFunction2<String, String, String> block =
               new CheckedFunction2<String, String, String>() {
                 @Override
                 public String safeValue(String argument1, String argument2) throws IOException {
                   throw new IOException("fail");
                 }
               };
           block.value("1", "2");
         }
       });
 }
예제 #23
0
 @Test
 public void checkedProcedure2CheckedException() {
   Verify.assertThrowsWithCause(
       RuntimeException.class,
       IOException.class,
       new Runnable() {
         public void run() {
           CheckedProcedure2<String, String> block =
               new CheckedProcedure2<String, String>() {
                 @Override
                 public void safeValue(String object, String parameter) throws IOException {
                   throw new IOException("fail");
                 }
               };
           block.value("1", "2");
         }
       });
 }
예제 #24
0
 @Test
 public void checkedPredicate2CheckedException() {
   Verify.assertThrowsWithCause(
       RuntimeException.class,
       IOException.class,
       new Runnable() {
         public void run() {
           CheckedPredicate2<String, String> block =
               new CheckedPredicate2<String, String>() {
                 @Override
                 public boolean safeAccept(String object, String param) throws IOException {
                   throw new IOException("fail");
                 }
               };
           block.accept("1", "2");
         }
       });
 }
예제 #25
0
 @Test
 public void testClone() {
   MutableList<String> growableList = this.list.clone();
   Verify.assertEqualsAndHashCode(this.list, growableList);
   Verify.assertInstanceOf(SextupletonList.class, growableList);
 }
예제 #26
0
 @Test
 public void testAddingAllToOtherList() {
   List<String> newList = new ArrayList<String>(this.list);
   newList.add("7");
   Verify.assertStartsWith(newList, "1", "2", "3", "4", "5", "6", "7");
 }
예제 #27
0
 @Override
 @Test
 public void testEqualsAndHashCode() {
   Verify.assertEqualsAndHashCode(UnifiedMap.newWithKeysValues("1", "One"), this.classUnderTest());
 }
예제 #28
0
 private void assertUnchanged() {
   Verify.assertSize(6, this.list);
   Verify.assertNotContains("7", this.list);
   Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), this.list);
 }
예제 #29
0
 @Test
 public void testSerializableEqualsAndHashCode() {
   Verify.assertPostSerializedEqualsAndHashCode(this.list);
   MutableList<String> copyOfList = SerializeTestHelper.serializeDeserialize(this.list);
   Assert.assertNotSame(this.list, copyOfList);
 }