Java Code Examples for org.junit.jupiter.api.Assertions#assertSame()

The following examples show how to use org.junit.jupiter.api.Assertions#assertSame() . 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: JavaClassLoaderTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwiceCompilation() throws Exception {
    JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "", new SpringBeanLoader()) {
        @Override
        protected Date getCurrentTimestamp() {
            return new Date();
        }
    };

    Class<?> class1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.DependentClass");
    Class<?> dependencyClass1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.pack1.DependencyClass");
    Class<?> dependency2Class1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.pack2.Dependency2Class");
    System.out.println("Class loaded");
    Assertions.assertEquals(javaClassLoader.compiled.size(), 3);
    modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test2/DependentClass.java");
    modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test2/pack1/DependencyClass.java");
    System.out.println("DependentClass modified");
    System.out.println("DependencyClass modified");

    Class<?> class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.DependentClass");
    Class<?> dependencyClass2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.pack1.DependencyClass");
    Class<?> dependency2Class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test2.pack2.Dependency2Class");
    Assertions.assertNotSame(class1, class2);
    Assertions.assertNotSame(dependencyClass1, dependencyClass2);
    Assertions.assertSame(dependency2Class1, dependency2Class2);
}
 
Example 2
Source File: FractionTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
void testConstructorZero() {
    Assertions.assertSame(Fraction.ZERO, Fraction.from(0.0));
    Assertions.assertSame(Fraction.ZERO, Fraction.from(0.0, 1e-10, 100));
    Assertions.assertSame(Fraction.ZERO, Fraction.from(0.0, 100));
    Assertions.assertSame(Fraction.ZERO, Fraction.of(0));
    Assertions.assertSame(Fraction.ZERO, Fraction.of(0, 1));
    Assertions.assertSame(Fraction.ZERO, Fraction.of(0, -1));
}
 
Example 3
Source File: PanacheMockingTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testPanacheRepositoryMocking() throws Throwable {
    Assertions.assertEquals(0, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenReturn(23l);
    Assertions.assertEquals(23, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenReturn(42l);
    Assertions.assertEquals(42, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenCallRealMethod();
    Assertions.assertEquals(0, mockablePersonRepository.count());

    Mockito.verify(mockablePersonRepository, Mockito.times(4)).count();

    Person p = new Person();
    Mockito.when(mockablePersonRepository.findById(12l)).thenReturn(p);
    Assertions.assertSame(p, mockablePersonRepository.findById(12l));
    Assertions.assertNull(mockablePersonRepository.findById(42l));

    Mockito.when(mockablePersonRepository.findById(12l)).thenThrow(new WebApplicationException());
    try {
        mockablePersonRepository.findById(12l);
        Assertions.fail();
    } catch (WebApplicationException x) {
    }

    Mockito.when(mockablePersonRepository.findOrdered()).thenReturn(Collections.emptyList());
    Assertions.assertTrue(mockablePersonRepository.findOrdered().isEmpty());

    Mockito.verify(mockablePersonRepository).findOrdered();
    Mockito.verify(mockablePersonRepository, Mockito.atLeastOnce()).findById(Mockito.any());
    Mockito.verifyNoMoreInteractions(mockablePersonRepository);
}
 
Example 4
Source File: ComplexTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
void testProj() {
    final Complex z = Complex.ofCartesian(3.0, 4.0);
    Assertions.assertSame(z, z.proj());
    // Sign must be the same for projection
    TestUtils.assertSame(infZero, Complex.ofCartesian(inf, 4.0).proj());
    TestUtils.assertSame(infZero, Complex.ofCartesian(inf, inf).proj());
    TestUtils.assertSame(infZero, Complex.ofCartesian(inf, nan).proj());
    TestUtils.assertSame(infZero, Complex.ofCartesian(3.0, inf).proj());
    TestUtils.assertSame(infZero, Complex.ofCartesian(nan, inf).proj());
    TestUtils.assertSame(infNegZero, Complex.ofCartesian(inf, -4.0).proj());
    TestUtils.assertSame(infNegZero, Complex.ofCartesian(inf, -inf).proj());
    TestUtils.assertSame(infNegZero, Complex.ofCartesian(3.0, -inf).proj());
    TestUtils.assertSame(infNegZero, Complex.ofCartesian(nan, -inf).proj());
}
 
Example 5
Source File: QuaternionTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
final void testPositivePolarFormWhenScalarNegative() {
    Quaternion q = Quaternion.of(-3, 3, -3, 3).positivePolarForm();
    Quaternion expected = Quaternion.of(0.5, -0.5, 0.5, -0.5);
    assertEquals(q, expected, EPS);

    Assertions.assertSame(q.positivePolarForm(), q);
}
 
Example 6
Source File: RegistryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testGaugeHelpersWithCustomFunction2() {
  AtomicLong al1 = new AtomicLong(1L);
  Registry r = new DefaultRegistry(new ManualClock(40, 0));
  ToDoubleFunction<AtomicLong> f = (obj) -> (r.clock().wallTime() - obj.doubleValue()) / 1000.0;

  AtomicLong v1 = r.gauge("foo", al1, f);
  Assertions.assertSame(v1, al1);
  Id id1 = r.createId("foo");
  assertGaugeValue(r, id1, 39.0 / 1000.0);
}
 
Example 7
Source File: QuaternionTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
final void testPositivePolarFormWhenScalarPositiveAndNormalized() {
    Quaternion q = Quaternion.of(123, 45, 67, 89).normalize().positivePolarForm();

    Assertions.assertTrue(q.getW() >= 0);
    Assertions.assertSame(q.positivePolarForm(), q);
}
 
Example 8
Source File: FactDefTokenTest.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testValidStringNo()
{
	assertNull(fd.getFactName());
	assertNull(fd.getUsableLocation());
	assertTrue(token.parseToken(context, fd, "DOMAIN|Caster").passed());
	assertNotNull(fd.getFactName());
	assertNotNull(fd.getUsableLocation());
	assertEquals("Caster", fd.getFactName());
	Assertions.assertSame(Domain.class, fd.getUsableLocation());
	String[] unparsed = token.unparse(context, fd);
	assertNotNull(unparsed);
	assertEquals(1, unparsed.length);
	assertEquals("DOMAIN|Caster", unparsed[0]);
}
 
Example 9
Source File: RegistryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapSizeHelpers() {
  Registry r = newRegistry(true, 10000);
  ConcurrentHashMap<String, String> q1 = new ConcurrentHashMap<>();
  ConcurrentHashMap<String, String> q2 = r.mapSize("mapSize", q1);
  Assertions.assertSame(q1, q2);
  Id id = r.createId("mapSize");
  assertGaugeValue(r, id, 0.0);
  q2.put("foo", "bar");
  assertGaugeValue(r, id, 1.0);
}
 
Example 10
Source File: VisualModelTests.java    From workcraft with MIT License 5 votes vote down vote up
@Test
public void testUngroupRoot() throws VisualModelInstantiationException {
    VisualModel model = new MockConcreteVisualModel();

    Container root = model.getCurrentLevel();

    VisualGroup node1 = new VisualGroup();
    VisualGroup node2 = new VisualGroup();
    VisualGroup node3 = new VisualGroup();
    VisualGroup node4 = new VisualGroup();
    VisualGroup node5 = new VisualGroup();

    node2.add(node3);
    node1.add(node2);
    node1.add(node4);
    root.add(node1);
    root.add(node5);

    model.addToSelection(node1);
    model.ungroupSelection();

    VisualNode[] newList = root.getChildren().toArray(new VisualNode[0]);

    Assertions.assertEquals(3, newList.length);
    Assertions.assertSame(node5, newList[0]);
    Assertions.assertSame(node2, newList[1]);
    Assertions.assertSame(node4, newList[2]);

    VisualNode[] n2Children = node2.getChildren().toArray(new VisualNode[0]);
    Assertions.assertEquals(1, n2Children.length);
    Assertions.assertSame(node3, n2Children[0]);
}
 
Example 11
Source File: CanonObjectEventImplTest.java    From canon-sdk-java with MIT License 5 votes vote down vote up
@Test
void getBaseRef() {
    final EdsBaseRef ref = canonObjectEvent.getBaseRef();
    Assertions.assertNotNull(ref);
    Assertions.assertEquals(baseRef, ref);
    Assertions.assertSame(baseRef, canonObjectEvent.getBaseRef());
}
 
Example 12
Source File: FactDefTokenTest.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testValidStringNo()
{
	assertNull(fd.getFactName());
	assertNull(fd.getUsableLocation());
	assertTrue(token.parseToken(context, fd, "DOMAIN|Caster").passed());
	assertNotNull(fd.getFactName());
	assertNotNull(fd.getUsableLocation());
	assertEquals("Caster", fd.getFactName());
	Assertions.assertSame(Domain.class, fd.getUsableLocation());
	String[] unparsed = token.unparse(context, fd);
	assertNotNull(unparsed);
	assertEquals(1, unparsed.length);
	assertEquals("DOMAIN|Caster", unparsed[0]);
}
 
Example 13
Source File: CanonStateEventImplTest.java    From canon-sdk-java with MIT License 5 votes vote down vote up
@Test
void getCameraRef() {
    final EdsCameraRef ref = canonStateEvent.getCameraRef();
    Assertions.assertNotNull(ref);
    Assertions.assertEquals(cameraRef, ref);
    Assertions.assertSame(cameraRef, canonStateEvent.getCameraRef());
}
 
Example 14
Source File: QuaternionTest.java    From commons-numbers with Apache License 2.0 4 votes vote down vote up
@Test
final void testNormalize() {

    final Quaternion q = Quaternion.of(2, 1, -4, -2);

    final Quaternion versor = q.normalize();

    Assertions.assertEquals(2.0 / 5.0, versor.getW(), 0);
    Assertions.assertEquals(1.0 / 5.0, versor.getX(), 0);
    Assertions.assertEquals(-4.0 / 5.0, versor.getY(), 0);
    Assertions.assertEquals(-2.0 / 5.0, versor.getZ(), 0);

    Assertions.assertEquals(1, versor.norm(), 0);

    Assertions.assertSame(versor.normalize(), versor);
}
 
Example 15
Source File: BufferTest.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void ContinuousArrayBufferIterationTest()
{

    ContinuousArrayBuffer<String> buffer = new ContinuousArrayBuffer<>(10);
    buffer.bufferObject("1");
    buffer.bufferObject("2");
    buffer.bufferObject("3");
    buffer.bufferObject("4");
    buffer.bufferObject("5");
    buffer.bufferObject("6");
    buffer.bufferObject("7");
    buffer.bufferObject("8");
    buffer.bufferObject("9");
    buffer.bufferObject("10");
    buffer.bufferObject("11");
    buffer.bufferObject("12");

    List<String> expected = ImmutableList.of("3", "4", "5", "6", "7", "8", "9", "10", "11", "12");

    Assertions.assertSame(expected.size(), buffer.size(), "Different sizes: EXPECTED: " + expected.size() + " ACTUAL: " + buffer.size());
    int dotSize = 0;
    for (String s : buffer) {
        dotSize++;
        Assertions.assertTrue(expected.contains(s), "Wrong element: " + s);
    }
    Assertions.assertSame(expected.size(), dotSize, "Different dot sizes: EXPECTED: " + expected.size() + " ACTUAL: " + dotSize);

    Iterator<String> ascendingIterator = buffer.iterator();
    int ascSize = 0;
    String next;
    while (ascendingIterator.hasNext()) {
        next = ascendingIterator.next();
        ascSize++;

        Assertions.assertTrue(expected.contains(next), "Wrong element: " + next);
    }
    Assertions.assertSame(expected.size(), ascSize, "Wrong amount of elements ASC.");

    Iterator<String> descendingIterator = buffer.descendingIterator();
    int desSize = 0;
    while (descendingIterator.hasNext()) {
        next = descendingIterator.next();
        desSize++;

        Assertions.assertTrue(expected.contains(next), "Wrong element: " + next);
    }
    Assertions.assertSame(expected.size(), desSize, "Wrong amount of elements DESC.");
}
 
Example 16
Source File: QueryTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
@Test
public void simplifyEqualsNoValueForKey() {
  Query q = Parser.parseQuery("nf.cluster,foo,:eq");
  Assertions.assertSame(q, q.simplify(tags("nf.app", "foo")));
}
 
Example 17
Source File: KafkaBrokersTest.java    From kafka-junit with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Tests the getBrokerById.
 */
@Test
void testGetBrokerById() {
    // Create mocks
    final KafkaTestServer mockServer1 = mock(KafkaTestServer.class);
    when(mockServer1.getBrokerId()).thenReturn(1);

    final KafkaTestServer mockServer2 = mock(KafkaTestServer.class);
    when(mockServer2.getBrokerId()).thenReturn(2);

    final KafkaTestServer mockServer3 = mock(KafkaTestServer.class);
    when(mockServer3.getBrokerId()).thenReturn(3);

    final KafkaTestServer mockServer5 = mock(KafkaTestServer.class);
    when(mockServer5.getBrokerId()).thenReturn(5);

    // Build brokers
    final KafkaBroker broker1 = new KafkaBroker(mockServer1);
    final KafkaBroker broker2 = new KafkaBroker(mockServer2);
    final KafkaBroker broker3 = new KafkaBroker(mockServer3);
    final KafkaBroker broker5 = new KafkaBroker(mockServer5);
    final List<KafkaBroker> brokerList = new ArrayList<>();
    brokerList.add(broker2);
    brokerList.add(broker1);
    brokerList.add(broker5);
    brokerList.add(broker3);

    // Create KafkaBrokers instance.
    final KafkaBrokers kafkaBrokers = new KafkaBrokers(brokerList);

    // Validate
    Assertions.assertSame(broker1, kafkaBrokers.getBrokerById(1));
    Assertions.assertSame(broker2, kafkaBrokers.getBrokerById(2));
    Assertions.assertSame(broker3, kafkaBrokers.getBrokerById(3));
    Assertions.assertSame(broker5, kafkaBrokers.getBrokerById(5));

    // Attempt to get invalid brokerId
    Assertions.assertThrows(IllegalArgumentException.class, () -> kafkaBrokers.getBrokerById(0));
    Assertions.assertThrows(IllegalArgumentException.class, () -> kafkaBrokers.getBrokerById(4));
    Assertions.assertThrows(IllegalArgumentException.class, () -> kafkaBrokers.getBrokerById(6));
}
 
Example 18
Source File: BeanNameTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testBeanName() {
    Assertions.assertSame(consumer, Arc.container().instance("bean").get());
}
 
Example 19
Source File: CameraLogicDefaultMockTest.java    From canon-sdk-java with MIT License 4 votes vote down vote up
@Test
void openSessionByBodyIDEx() {
    cameraLogicDefaultExtended.setCameraListRefByRef(mockCameraListRefByRef);
    cameraLogicDefaultExtended.setNativeLongByReference(mockNativeLongByReference);
    cameraLogicDefaultExtended.setCameraRefByRef(mockCameraRefByRef);

    when(edsdkLibrary().EdsRelease(any())).thenReturn(new NativeLong(0));

    when(edsdkLibrary().EdsGetCameraList(same(mockCameraListRefByRef))).thenReturn(new NativeLong(0));

    when(edsdkLibrary().EdsGetChildCount(any(), same(mockNativeLongByReference))).thenReturn(new NativeLong(0));

    final EdsdkLibrary.EdsCameraListRef cameraListRef = new EdsdkLibrary.EdsCameraListRef();
    when(mockCameraListRefByRef.getValue()).thenReturn(cameraListRef);

    when(mockNativeLongByReference.getValue()).thenReturn(new NativeLong(3));

    when(mockCameraRefByRef.getValue()).thenReturn(fakeCamera);

    when(edsdkLibrary().EdsGetChildAtIndex(eq(cameraListRef), any(NativeLong.class), same(mockCameraRefByRef))).thenReturn(new NativeLong(0));

    final String serial = "serial999";

    when(CanonFactory.propertyGetShortcutLogic().getBodyIDEx(fakeCamera))
        .thenThrow(EdsdkCommDisconnectedErrorException.class)
        .thenReturn("firstCameraIsOther")
        .thenReturn("serial999");

    when(edsdkLibrary().EdsOpenSession(same(fakeCamera))).thenReturn(new NativeLong(0));


    final OpenSessionOption option = new OpenSessionOptionBuilder()
        .setRegisterObjectEvent(true)
        .setRegisterPropertyEvent(true)
        .setRegisterStateEvent(true)
        .setCameraBySerialNumber(serial)
        .build();

    final EdsCameraRef result = cameraLogicDefaultExtended.openSession(option);

    Assertions.assertSame(fakeCamera, result);
    Assertions.assertEquals(fakeCamera, result);

    verify(edsdkLibrary(), times(2)).EdsRelease(any());
    verify(edsdkLibrary()).EdsRelease(same(cameraListRef));
    verify(edsdkLibrary(), times(1)).EdsRelease(same(fakeCamera));
    verify(CanonFactory.propertyGetShortcutLogic(), times(4)).getBodyIDEx(same(fakeCamera));
    verify(edsdkLibrary()).EdsOpenSession(same(fakeCamera));
    verify(edsdkLibrary(), times(1)).EdsCloseSession(same(fakeCamera));
    verify(cameraObjectEventLogic).registerCameraObjectEvent(same(fakeCamera));
    verify(cameraPropertyEventLogic).registerCameraPropertyEvent(same(fakeCamera));
    verify(cameraStateEventLogic).registerCameraStateEvent(same(fakeCamera));
}
 
Example 20
Source File: DefaultIdTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
@Test
public void testRollupJustName() {
  DefaultId id = new DefaultId("foo");
  Assertions.assertSame(id, id.normalize());
}