How to use method of org.easymock.tests2.ConstraintsToStringTest class

Best Easymock code snippet using org.easymock.tests2.ConstraintsToStringTest.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/*
2 * Copyright 2001-2021 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.easymock.tests2;
17
18import org.easymock.IArgumentMatcher;
19import org.easymock.internal.matchers.*;
20import org.junit.Before;
21import org.junit.Test;
22
23import java.util.ArrayList;
24import java.util.List;
25
26import static org.junit.Assert.*;
27
28/**
29 * @author OFFIS, Tammo Freese
30 */
31public class ConstraintsToStringTest {
32    private StringBuffer buffer;
33
34    @Before
35    public void setup() {
36        buffer = new StringBuffer();
37    }
38
39    @Test
40    public void sameToStringWithString() {
41        new Same("X").appendTo(buffer);
42        assertEquals("same(\"X\")", buffer.toString());
43
44    }
45
46    @Test
47    public void nullToString() {
48        Null.NULL.appendTo(buffer);
49        assertEquals("isNull()", buffer.toString());
50    }
51
52    @Test
53    public void notNullToString() {
54        NotNull.NOT_NULL.appendTo(buffer);
55        assertEquals("notNull()", buffer.toString());
56    }
57
58    @Test
59    public void anyToString() {
60        Any.ANY.appendTo(buffer);
61        assertEquals("<any>", buffer.toString());
62    }
63
64    @Test
65    public void sameToStringWithChar() {
66        new Same('x').appendTo(buffer);
67        assertEquals("same('x')", buffer.toString());
68    }
69
70    @Test
71    public void sameToStringWithObject() {
72        Object o = new Object() {
73            @Override
74            public String toString() {
75                return "X";
76            }
77        };
78        new Same(o).appendTo(buffer);
79        assertEquals("same(X)", buffer.toString());
80    }
81
82    @Test
83    public void equalsToStringWithString() {
84        new Equals("X").appendTo(buffer);
85        assertEquals("\"X\"", buffer.toString());
86
87    }
88
89    @Test
90    public void equalsToStringWithChar() {
91        new Equals('x').appendTo(buffer);
92        assertEquals("'x'", buffer.toString());
93    }
94
95    @Test
96    public void equalsToStringWithObject() {
97        Object o = new Object() {
98            @Override
99            public String toString() {
100                return "X";
101            }
102        };
103        new Equals(o).appendTo(buffer);
104        assertEquals("X", buffer.toString());
105    }
106
107    @Test
108    public void equalsToStringWithArray() {
109        String[] s = new String[] { "a", "b", null, "c" };
110        new Equals(s).appendTo(buffer);
111        assertEquals("[\"a\", \"b\", null, \"c\"]", buffer.toString());
112    }
113
114    @Test
115    public void orToString() {
116        List<IArgumentMatcher> matchers = new ArrayList<>();
117        matchers.add(new Equals(1));
118        matchers.add(new Equals(2));
119        new Or(matchers).appendTo(buffer);
120        assertEquals("or(1 (int), 2 (int))", buffer.toString());
121    }
122
123    @Test
124    public void notToString() {
125        new Not(new Equals(1)).appendTo(buffer);
126        assertEquals("not(1 (int))", buffer.toString());
127    }
128
129    @Test
130    public void andToString() {
131        List<IArgumentMatcher> matchers = new ArrayList<>();
132        matchers.add(new Equals(1));
133        matchers.add(new Equals(2));
134        new And(matchers).appendTo(buffer);
135        assertEquals("and(1 (int), 2 (int))", buffer.toString());
136    }
137
138    @Test
139    public void startsWithToString() {
140        new StartsWith("AB").appendTo(buffer);
141        assertEquals("startsWith(\"AB\")", buffer.toString());
142    }
143
144    @Test
145    public void endsWithToString() {
146        new EndsWith("AB").appendTo(buffer);
147        assertEquals("endsWith(\"AB\")", buffer.toString());
148    }
149
150    @Test
151    public void containsToString() {
152        new Contains("AB").appendTo(buffer);
153        assertEquals("contains(\"AB\")", buffer.toString());
154    }
155
156    @Test
157    public void findToString() {
158        new Find("\\s+").appendTo(buffer);
159        assertEquals("find(\"\\\\s+\")", buffer.toString());
160    }
161
162    @Test
163    public void matchesToString() {
164        new Matches("\\s+").appendTo(buffer);
165        assertEquals("matches(\"\\\\s+\")", buffer.toString());
166    }
167
168    @Test
169    public void equalsWithDeltaToString() {
170        new EqualsWithDelta(2.1d, 0.2d).appendTo(buffer);
171        assertEquals("eq(2.1, 0.2)", buffer.toString());
172    }
173
174    @Test
175    public void arrayEqualsToString() {
176        new ArrayEquals(new Object[] { 1, "a", null }).appendTo(buffer);
177        assertEquals("[1 (int), \"a\", null]", buffer.toString());
178    }
179}
180
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)