org.hamcrest.core.IsSame Java Examples

The following examples show how to use org.hamcrest.core.IsSame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DenseMatrixTest.java    From symbol-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void matrixCanBeInitializedWithDefaultValues() {
    // Arrange:
    final double[] values = new double[]{1, 4, 5, 7, 2, 3};
    final DenseMatrix matrix = new DenseMatrix(2, 3, values);

    // Assert:
    MatcherAssert.assertThat(matrix.getRowCount(), IsEqual.equalTo(2));
    MatcherAssert.assertThat(matrix.getColumnCount(), IsEqual.equalTo(3));
    MatcherAssert.assertThat(matrix.getElementCount(), IsEqual.equalTo(6));
    MatcherAssert.assertThat(matrix.getRaw(), IsSame.sameInstance(values));
    MatcherAssert.assertThat(matrix.getAt(0, 0), IsEqual.equalTo(1.0));
    MatcherAssert.assertThat(matrix.getAt(0, 1), IsEqual.equalTo(4.0));
    MatcherAssert.assertThat(matrix.getAt(0, 2), IsEqual.equalTo(5.0));
    MatcherAssert.assertThat(matrix.getAt(1, 0), IsEqual.equalTo(7.0));
    MatcherAssert.assertThat(matrix.getAt(1, 1), IsEqual.equalTo(2.0));
    MatcherAssert.assertThat(matrix.getAt(1, 2), IsEqual.equalTo(3.0));
}
 
Example #2
Source File: CircularStackTest.java    From symbol-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void copyIsAShallowCopy() {
    // Arrange:
    final CircularStack<Integer> stack1 = this.createStack(3);
    final CircularStack<Integer> stack2 = this.createStack(3);

    // Act:
    for (int i = 0; i < 10; ++i) {
        stack1.push(i);
    }
    stack1.shallowCopyTo(stack2);

    // Assert:
    MatcherAssert.assertThat(stack1.size(), IsEqual.equalTo(3));
    MatcherAssert.assertThat(stack2.size(), IsEqual.equalTo(3));
    for (int i = 0; i < 3; ++i) {
        MatcherAssert.assertThat(stack1.peek(), IsSame.sameInstance(stack2.peek()));
        stack1.pop();
        stack2.pop();
    }
}
 
Example #3
Source File: ServiceProviderTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupportsMultipleAuthoritativeTierProviders() throws Exception {

  ServiceLocator.DependencySet dependencySet = dependencySet();

  OnHeapStore.Provider cachingTierProvider = new OnHeapStore.Provider();
  OffHeapStore.Provider authoritativeTierProvider = new OffHeapStore.Provider();
  OffHeapDiskStore.Provider diskStoreProvider = new OffHeapDiskStore.Provider();

  dependencySet.with(cachingTierProvider);
  dependencySet.with(authoritativeTierProvider);
  dependencySet.with(diskStoreProvider);
  dependencySet.with(mock(DiskResourceService.class));
  dependencySet.with(mock(CacheManagerProviderService.class, Answers.RETURNS_DEEP_STUBS));

  ServiceLocator serviceLocator = dependencySet.build();
  serviceLocator.startAllServices();

  assertThat(serviceLocator.getServicesOfType(CachingTier.Provider.class),
    IsCollectionContaining.<CachingTier.Provider>hasItem(IsSame.<CachingTier.Provider>sameInstance(cachingTierProvider)));
  assertThat(serviceLocator.getServicesOfType(AuthoritativeTier.Provider.class),
    IsCollectionContaining.<AuthoritativeTier.Provider>hasItem(IsSame.<AuthoritativeTier.Provider>sameInstance(authoritativeTierProvider)));
  assertThat(serviceLocator.getServicesOfType(OffHeapDiskStore.Provider.class),
    IsCollectionContaining.<OffHeapDiskStore.Provider>hasItem(IsSame.<OffHeapDiskStore.Provider>sameInstance(diskStoreProvider)));
}
 
Example #4
Source File: EnumTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void shiftingInstanceSerialization() throws ClassNotFoundException {
  StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null);
  s.init(new TransientStateRepository());

  ClassLoader wLoader = createClassNameRewritingLoader(Foo_W.class);
  ClassLoader rLoader = createClassNameRewritingLoader(Foo_R.class);

  Class<?> wClass = wLoader.loadClass(newClassName(Foo_W.class));
  Class<?> rClass = rLoader.loadClass(newClassName(Foo_R.class));

  Object[] wInstances = wClass.getEnumConstants();
  Object[] rInstances = rClass.getEnumConstants();

  pushTccl(rLoader);
  try {
    for (int i = 0; i < wInstances.length; i++) {
      Assert.assertThat(s.read(s.serialize((Serializable) wInstances[i])), IsSame.sameInstance(rInstances[i]));
    }
  } finally {
    popTccl();
  }
}
 
Example #5
Source File: EnumTest.java    From offheap-store with Apache License 2.0 6 votes vote down vote up
@Test
public void shiftingInstanceSerialization() throws Exception {
  Portability<Serializable> p = new SerializablePortability();

  System.out.println(Arrays.toString(Foo_W.class.getDeclaredClasses()));
  System.out.println(Foo_W.c.getClass().getEnclosingClass());

  ClassLoader wLoader = createClassNameRewritingLoader(Foo_W.class);
  ClassLoader rLoader = createClassNameRewritingLoader(Foo_R.class);

  Class<?> wClass = wLoader.loadClass(newClassName(Foo_W.class));
  Class<?> rClass = rLoader.loadClass(newClassName(Foo_R.class));

  Object[] wInstances = wClass.getEnumConstants();
  Object[] rInstances = rClass.getEnumConstants();

  pushTccl(rLoader);
  try {
    for (int i = 0; i < wInstances.length; i++) {
      Assert.assertThat(p.decode(p.encode((Serializable) wInstances[i])), IsSame.sameInstance(rInstances[i]));
    }
  } finally {
    popTccl();
  }
}
 
Example #6
Source File: ConfigurationDerivation.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void withCustomClassLoader() {
  Configuration configuration = ConfigurationBuilder.newConfigurationBuilder()
    .withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
    .build();

  ClassLoader classLoader = MockitoUtil.mock(ClassLoader.class);

  // tag::customClassLoader[]
  Configuration withClassLoader = configuration.derive()
    .withClassLoader(classLoader)
    .build();
  // end::customClassLoader[]

  Assert.assertThat(configuration.getClassLoader(), Is.is(IsSame.sameInstance(ClassLoading.getDefaultClassLoader())));
  Assert.assertThat(withClassLoader.getClassLoader(), Is.is(IsSame.sameInstance(classLoader)));
}
 
Example #7
Source File: AbstractTwoLevelMapTest.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sameValueIsReturnedForSameKeys() {
    // Arrange:
    final AbstractTwoLevelMap<String, MockValue> map = new MockTwoLevelMap();

    // Act:
    final MockValue value1 = map.getItem("foo", "bar");
    final MockValue value2 = map.getItem("foo", "bar");

    // Assert:
    MatcherAssert.assertThat(value2, IsSame.sameInstance(value1));
}
 
Example #8
Source File: TrimFunctionTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompileTrimFunctionResultingInSameFunction() {
    assertCompile("trim(leading ' ' from name)", IsSame::sameInstance);
    assertCompile("trim(both 'ab' from name)", IsSame::sameInstance);
    assertCompile("trim(both name from name)", IsSame::sameInstance);
    assertCompile("trim('ab' from name)", IsSame::sameInstance);
    assertCompile("trim(name)", IsSame::sameInstance);
    assertCompile("trim(initCap(name) from name)", IsSame::sameInstance);
}
 
Example #9
Source File: TrimFunctionTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompileTrimFunctionResultingInOptimisedTrim() {
    assertCompile("trim(both ' ' from name)", (s) -> not(IsSame.sameInstance(s)));
    assertCompile("trim(both 'a' from name)", (s) -> not(IsSame.sameInstance(s)));
    assertCompile("trim('a' from name)", (s) -> not(IsSame.sameInstance(s)));
    assertCompile("trim(initCap('a') from name)", (s) -> not(IsSame.sameInstance(s)));
}
 
Example #10
Source File: CoreMatchers.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void hamcrest_core_isSame_string () {
	
	String wiBrewery = "Capital Brewery";
	String wiRegionalBrewery = "Capital Brewery";
	
	assertThat(wiRegionalBrewery, IsSame.<String>sameInstance(wiBrewery));
}
 
Example #11
Source File: ServerManagerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameInstance() throws InterruptedException {

  ServerManager server = kurentoClient.getServerManager();
  ServerManager server2 = kurentoClient.getServerManager();

  assertThat(server, IsSame.sameInstance(server2));
}
 
Example #12
Source File: EnumTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Test
public void classSerialization() throws ClassNotFoundException {
  StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null);
  s.init(new TransientStateRepository());

  Assert.assertThat(s.read(s.serialize(Enum.class)), IsSame.sameInstance(Enum.class));
  Assert.assertThat(s.read(s.serialize(Dogs.Handel.getClass())), IsSame.sameInstance(Dogs.Handel.getClass()));
  Assert.assertThat(s.read(s.serialize(Dogs.Cassie.getClass())), IsSame.sameInstance(Dogs.Cassie.getClass()));
  Assert.assertThat(s.read(s.serialize(Dogs.Penny.getClass())), IsSame.sameInstance(Dogs.Penny.getClass()));
}
 
Example #13
Source File: EnumTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Test
public void basicInstanceSerialization() throws ClassNotFoundException {
  StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null);
  s.init(new TransientStateRepository());

  Assert.assertThat(s.read(s.serialize(People.Alice)), IsSame.sameInstance(People.Alice));
  Assert.assertThat(s.read(s.serialize(People.Bob)), IsSame.sameInstance(People.Bob));
  Assert.assertThat(s.read(s.serialize(People.Eve)), IsSame.sameInstance(People.Eve));
}
 
Example #14
Source File: BasicSerializationTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrimitiveClasses() throws ClassNotFoundException {
  StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null);
  s.init(new TransientStateRepository());

  Class<?>[] out = (Class<?>[]) s.read(s.serialize(PRIMITIVE_CLASSES));

  Assert.assertThat(out, IsNot.not(IsSame.sameInstance(PRIMITIVE_CLASSES)));
  Assert.assertThat(out, IsEqual.equalTo(PRIMITIVE_CLASSES));
}
 
Example #15
Source File: CacheConfigurationBuilderTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyingOfExistingConfiguration() {
  Class<Integer> keyClass = Integer.class;
  Class<String> valueClass = String.class;
  ClassLoader loader = mock(ClassLoader.class);
  @SuppressWarnings("unchecked")
  EvictionAdvisor<Integer, String> eviction = mock(EvictionAdvisor.class);
  @SuppressWarnings("unchecked")
  ExpiryPolicy<Integer, String> expiry = mock(ExpiryPolicy.class);
  ServiceConfiguration<?, ?> service = mock(ServiceConfiguration.class);

  CacheConfiguration<Integer, String> configuration = newCacheConfigurationBuilder(Integer.class, String.class, heap(10))
    .withClassLoader(loader)
    .withEvictionAdvisor(eviction)
    .withExpiry(expiry)
    .withService(service)
    .build();

  CacheConfiguration<Integer, String> copy = newCacheConfigurationBuilder(configuration).build();

  assertThat(copy.getKeyType(), equalTo(keyClass));
  assertThat(copy.getValueType(), equalTo(valueClass));
  assertThat(copy.getClassLoader(), equalTo(loader));

  assertThat(copy.getEvictionAdvisor(), IsSame.sameInstance(eviction));
  assertThat(copy.getExpiryPolicy(), IsSame.sameInstance(expiry));
  assertThat(copy.getServiceConfigurations(), contains(IsSame.sameInstance(service)));
}
 
Example #16
Source File: ServiceGraphTest.java    From datakernel with Apache License 2.0 5 votes vote down vote up
@Test
public void testProperClosingForFailingServiceTwoComponents() throws Exception {
	Injector injector = Injector.of(new FailingModule());
	injector.getInstance(Key.ofName(BlockingService.class, "TopService1"));
	injector.getInstance(Key.ofName(BlockingService.class, "TopService2"));
	ServiceGraph graph = injector.getInstance(ServiceGraph.class);
	expected.expectCause(IsSame.sameInstance(FailingModule.INTERRUPTED));
	graph.startFuture().get();
}
 
Example #17
Source File: ServiceGraphTest.java    From datakernel with Apache License 2.0 5 votes vote down vote up
@Test
public void testProperClosingForFailingServiceOneComponent() throws Exception {
	Injector injector = Injector.of(new FailingModule());
	injector.getInstance(Key.ofName(BlockingService.class, "TopService1"));
	ServiceGraph graph = injector.getInstance(ServiceGraph.class);
	expected.expectCause(IsSame.sameInstance(FailingModule.INTERRUPTED));
	graph.startFuture().get();
}
 
Example #18
Source File: EnumTest.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void classSerialization() {
  Portability<Serializable> p = new SerializablePortability();

  Assert.assertThat(p.decode(p.encode(Enum.class)), IsSame.sameInstance(Enum.class));
  Assert.assertThat(p.decode(p.encode(Dogs.Handel.getClass())), IsSame.sameInstance(Dogs.Handel.getClass()));
  Assert.assertThat(p.decode(p.encode(Dogs.Cassie.getClass())), IsSame.sameInstance(Dogs.Cassie.getClass()));
  Assert.assertThat(p.decode(p.encode(Dogs.Penny.getClass())), IsSame.sameInstance(Dogs.Penny.getClass()));
}
 
Example #19
Source File: EnumTest.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void basicInstanceSerialization() {
  Portability<Serializable> p = new SerializablePortability();

  Assert.assertThat(p.decode(p.encode(People.Alice)), IsSame.sameInstance(People.Alice));
  Assert.assertThat(p.decode(p.encode(People.Bob)), IsSame.sameInstance(People.Bob));
  Assert.assertThat(p.decode(p.encode(People.Eve)), IsSame.sameInstance(People.Eve));
}
 
Example #20
Source File: BasicSerializationTest.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrimitiveClasses() {
  Portability<Serializable> p = new SerializablePortability();

  Class[] out = (Class[]) p.decode(p.encode(PRIMITIVE_CLASSES));

  Assert.assertThat(out, IsNot.not(IsSame.sameInstance(PRIMITIVE_CLASSES)));
  Assert.assertThat(out, IsEqual.equalTo(PRIMITIVE_CLASSES));
}
 
Example #21
Source File: ArrayUtilsTest.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void duplicateIsNotReference() {
    // Arrange:
    final byte[] src = new byte[]{1, 2, 3, 4};

    // Act:
    final byte[] result = ArrayUtils.duplicate(src);

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsSame.sameInstance(src)));
}
 
Example #22
Source File: AbstractTwoLevelMapTest.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getItemAndGetItemsReturnSameValueForSameKeys() {
    // Arrange:
    final AbstractTwoLevelMap<String, MockValue> map = new MockTwoLevelMap();

    // Act:
    final MockValue value1 = map.getItem("foo", "bar");
    final MockValue value2 = map.getItems("foo").get("bar");

    // Assert:
    MatcherAssert.assertThat(value2, IsSame.sameInstance(value1));
}
 
Example #23
Source File: AbstractTwoLevelMapTest.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void valueIsDirectional() {
    // Arrange:
    final AbstractTwoLevelMap<String, MockValue> map = new MockTwoLevelMap();

    // Act:
    final MockValue value1 = map.getItem("foo", "bar");
    final MockValue value2 = map.getItem("bar", "foo");

    // Assert:
    MatcherAssert.assertThat(value2, IsNot.not(IsSame.sameInstance(value1)));
}
 
Example #24
Source File: ArrayDifferenceFunctionTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompileWithValues() throws Exception {
    assertCompile("array_difference(int_array, [3, 4, 5])", (s) -> not(IsSame.sameInstance(s)));
}
 
Example #25
Source File: ArrayDifferenceFunctionTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompileWithRefs() throws Exception {
    assertCompile("array_difference(int_array, int_array)", IsSame::sameInstance);
}
 
Example #26
Source File: DateTruncFunctionTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompile() throws Exception {
    assertCompile("date_trunc(interval, timezone, timestamp_tz)", IsSame::sameInstance);
    assertCompile("date_trunc('day', 'UTC', timestamp_tz)", (s) -> not(IsSame.sameInstance(s)) );
}
 
Example #27
Source File: CoreMatchers.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void hamcrest_core_is_same_list () {
			
	List<String> someList = new ArrayList<String>();
	
	assertThat(someList, IsSame.<List<String>>sameInstance(someList));
}