Class TeamCityAsserts


  • public final class TeamCityAsserts
    extends Object
    Useful assert methods.
    Since:
    9.0
    Author:
    Leonid Bushuev from JetBrains
    • Constructor Detail

      • TeamCityAsserts

        public TeamCityAsserts()
    • Method Detail

      • assertTime

        public static void assertTime​(double maxAllowedExecutionTimeInSecs,
                                      String message,
                                      Runnable r)
      • assertTime

        public static void assertTime​(double maxAllowedExecutionTimeInSecs,
                                      String message,
                                      int numberOfAttempts,
                                      Runnable r)
      • measureRunsAndPrintStats

        public static void measureRunsAndPrintStats​(Runnable r,
                                                    int runCount)
      • assertMatches

        public static void assertMatches​(String actual,
                                         Pattern pattern)
      • assertMatches

        public static void assertMatches​(String actual,
                                         String pattern)
      • assertContains

        public static <T> void assertContains​(@Nullable
                                              Collection<T> collection,
                                              T... items)
        Checks that the collection contains the given item.
        Type Parameters:
        T - type of items.
        Parameters:
        collection - collection to check.
        items - items to found.
      • assertContains

        public static <K,​V> void assertContains​(@NotNull
                                                      Map<K,​V> includingMap,
                                                      @NotNull
                                                      Map<K,​V> includedMap)
      • assertNotContains

        public static <T> void assertNotContains​(@Nullable
                                                 Collection<T> collection,
                                                 T... items)
        Checks that the collection contains the given item.
        Type Parameters:
        T - type of items.
        Parameters:
        collection - collection to check.
        items - items to found.
      • assertEmpty

        public static void assertEmpty​(@Nullable
                                       Collection collection)
        Asserts that collection is empty or null.
        Parameters:
        collection - the collection to check.
      • assertEmpty

        public static void assertEmpty​(@Nullable
                                       Collection collection,
                                       @Nullable
                                       String message)
        Asserts that collection is empty or null.
        Parameters:
        collection - the collection to check.
      • assertNotEmpty

        public static <T> void assertNotEmpty​(@Nullable
                                              T[] array)
        Asserts that the array is not empty (and is not null).
        Parameters:
        array - array to check.
      • assertNotEmpty

        public static void assertNotEmpty​(@Nullable
                                          Collection<?> collection)
        Asserts that the collections is not empty (and is not null).
        Parameters:
        collection - the collection to check.
      • assertInstanceOf

        public static <T> void assertInstanceOf​(Object instance,
                                                Class<T> expectedClass)
      • assertNull2

        public static void assertNull2​(@Nullable
                                       Object object)
        More descriptive assertion than the Assert from junit. If object is not null, it says the object's value (using Object.toString()).
        Parameters:
        object - object that is checking to be null.
      • assertMeaningTextEquals

        public static void assertMeaningTextEquals​(@Nullable
                                                   String actual,
                                                   @Nullable
                                                   String expected)
      • assertContains

        public static void assertContains​(String textToCheck,
                                          String substring)
      • assertContainsAll

        public static void assertContainsAll​(@Nullable
                                             String text,
                                             @NotNull
                                             String... messages)
      • assertContainsAny

        public static void assertContainsAny​(@Nullable
                                             String text,
                                             @NotNull
                                             String... messages)
      • assertContains

        public static void assertContains​(@Nullable
                                          String textToCheck,
                                          @NotNull
                                          String substring,
                                          boolean caseSensitive)
      • assertContains

        public static void assertContains​(String textToCheck,
                                          Pattern pattern)
      • assertNotContains

        public static void assertNotContains​(@Nullable
                                             String textToCheck,
                                             @NotNull
                                             String substring,
                                             boolean caseSensitive)
      • assertNotContains

        public static void assertNotContains​(String textToCheck,
                                             Pattern pattern)
      • assertHasWithCount

        public static void assertHasWithCount​(String textToCheck,
                                              String substring,
                                              int expectedCount)
      • assertContainsWithCount

        public static void assertContainsWithCount​(String textToCheck,
                                                   String substring,
                                                   int expectedCount)
      • assertSameElements

        public static <T> void assertSameElements​(T[] collection,
                                                  T... expected)
      • assertSameElements

        public static <T> void assertSameElements​(Collection<? extends T> collection,
                                                  T... expected)
      • assertSameElements

        public static <T> void assertSameElements​(Collection<? extends T> collection,
                                                  Collection<T> expected)
      • assertEquals

        public static void assertEquals​(Date exp,
                                        Date got,
                                        long limit)
        Asserts sate and time.
        Parameters:
        exp - what is expected.
        got - what's got (actual).
        limit - max allowed difference, in seconds.
      • assertEquals

        public static void assertEquals​(String message,
                                        Date exp,
                                        Date got,
                                        long limit)
        Asserts sate and time.
        Parameters:
        message - message that will be outputted in case of a fail.
        exp - what is expected.
        got - what's got (actual).
        limit - max allowed difference, in seconds.
      • assertEqualsIgnoreNonBMP

        public static void assertEqualsIgnoreNonBMP​(@Nullable
                                                    String expected,
                                                    @Nullable
                                                    String got)
      • assertArraysEqual

        public static void assertArraysEqual​(int[] expected,
                                             int[] got)
      • assertArraysEqual

        public static void assertArraysEqual​(byte[] expected,
                                             byte[] got)
      • assertSetEquals

        public static <T> void assertSetEquals​(Set<T> actual,
                                               T... expected)
        Applicable for both sorted set and has set. In case of sorted one, the actual set's comparator is used.
        Type Parameters:
        T - type of items
        Parameters:
        actual - the set to check
        expected - expected items, must be no duplicates
        Since:
        8.1
      • assertListEquals

        public static <T> void assertListEquals​(List<T> actual,
                                                @NotNull
                                                T... expected)
      • assertMapping

        public static <K,​V> void assertMapping​(@NotNull
                                                     Map<K,​V> map,
                                                     @NotNull
                                                     K key,
                                                     @NotNull
                                                     V expectedValue)
      • assertMap

        public static <K,​V> void assertMap​(@Nullable
                                                 Map<K,​V> map,
                                                 Object... expected)
      • assertTimestampEquals

        public static void assertTimestampEquals​(Date actual,
                                                 Date expected)
      • assertGreater

        public static void assertGreater​(int actual,
                                         int lowBound)
      • assertGreater

        public static void assertGreater​(long actual,
                                         long lowBound)
      • assertLess

        public static void assertLess​(int actual,
                                      int upperBound)
      • assertLess

        public static void assertLess​(long actual,
                                      long upperBound)
      • assertGreaterOrEquals

        public static void assertGreaterOrEquals​(int actual,
                                                 int lowBound)
      • assertGreaterOrEquals

        public static void assertGreaterOrEquals​(long actual,
                                                 long lowBound)
      • assertLessOrEquals

        public static void assertLessOrEquals​(int actual,
                                              int upperBound)
      • assertLessOrEquals

        public static void assertLessOrEquals​(long actual,
                                              long upperBound)