github.com/braveheart12/just@v0.8.7/network/state/message_bus_locker_mock.go (about) 1 package state 2 3 /* 4 DO NOT EDIT! 5 This code was generated automatically using github.com/gojuno/minimock v1.9 6 The original interface "messageBusLocker" can be found in github.com/insolar/insolar/network/state 7 */ 8 import ( 9 context "context" 10 "sync/atomic" 11 "time" 12 13 "github.com/gojuno/minimock" 14 15 testify_assert "github.com/stretchr/testify/assert" 16 ) 17 18 //messageBusLockerMock implements github.com/insolar/insolar/network/state.messageBusLocker 19 type messageBusLockerMock struct { 20 t minimock.Tester 21 22 LockFunc func(p context.Context) 23 LockCounter uint64 24 LockPreCounter uint64 25 LockMock mmessageBusLockerMockLock 26 27 UnlockFunc func(p context.Context) 28 UnlockCounter uint64 29 UnlockPreCounter uint64 30 UnlockMock mmessageBusLockerMockUnlock 31 } 32 33 //NewmessageBusLockerMock returns a mock for github.com/insolar/insolar/network/state.messageBusLocker 34 func NewmessageBusLockerMock(t minimock.Tester) *messageBusLockerMock { 35 m := &messageBusLockerMock{t: t} 36 37 if controller, ok := t.(minimock.MockController); ok { 38 controller.RegisterMocker(m) 39 } 40 41 m.LockMock = mmessageBusLockerMockLock{mock: m} 42 m.UnlockMock = mmessageBusLockerMockUnlock{mock: m} 43 44 return m 45 } 46 47 type mmessageBusLockerMockLock struct { 48 mock *messageBusLockerMock 49 mainExpectation *messageBusLockerMockLockExpectation 50 expectationSeries []*messageBusLockerMockLockExpectation 51 } 52 53 type messageBusLockerMockLockExpectation struct { 54 input *messageBusLockerMockLockInput 55 } 56 57 type messageBusLockerMockLockInput struct { 58 p context.Context 59 } 60 61 //Expect specifies that invocation of messageBusLocker.Lock is expected from 1 to Infinity times 62 func (m *mmessageBusLockerMockLock) Expect(p context.Context) *mmessageBusLockerMockLock { 63 m.mock.LockFunc = nil 64 m.expectationSeries = nil 65 66 if m.mainExpectation == nil { 67 m.mainExpectation = &messageBusLockerMockLockExpectation{} 68 } 69 m.mainExpectation.input = &messageBusLockerMockLockInput{p} 70 return m 71 } 72 73 //Return specifies results of invocation of messageBusLocker.Lock 74 func (m *mmessageBusLockerMockLock) Return() *messageBusLockerMock { 75 m.mock.LockFunc = nil 76 m.expectationSeries = nil 77 78 if m.mainExpectation == nil { 79 m.mainExpectation = &messageBusLockerMockLockExpectation{} 80 } 81 82 return m.mock 83 } 84 85 //ExpectOnce specifies that invocation of messageBusLocker.Lock is expected once 86 func (m *mmessageBusLockerMockLock) ExpectOnce(p context.Context) *messageBusLockerMockLockExpectation { 87 m.mock.LockFunc = nil 88 m.mainExpectation = nil 89 90 expectation := &messageBusLockerMockLockExpectation{} 91 expectation.input = &messageBusLockerMockLockInput{p} 92 m.expectationSeries = append(m.expectationSeries, expectation) 93 return expectation 94 } 95 96 //Set uses given function f as a mock of messageBusLocker.Lock method 97 func (m *mmessageBusLockerMockLock) Set(f func(p context.Context)) *messageBusLockerMock { 98 m.mainExpectation = nil 99 m.expectationSeries = nil 100 101 m.mock.LockFunc = f 102 return m.mock 103 } 104 105 //Lock implements github.com/insolar/insolar/network/state.messageBusLocker interface 106 func (m *messageBusLockerMock) Lock(p context.Context) { 107 counter := atomic.AddUint64(&m.LockPreCounter, 1) 108 defer atomic.AddUint64(&m.LockCounter, 1) 109 110 if len(m.LockMock.expectationSeries) > 0 { 111 if counter > uint64(len(m.LockMock.expectationSeries)) { 112 m.t.Fatalf("Unexpected call to messageBusLockerMock.Lock. %v", p) 113 return 114 } 115 116 input := m.LockMock.expectationSeries[counter-1].input 117 testify_assert.Equal(m.t, *input, messageBusLockerMockLockInput{p}, "messageBusLocker.Lock got unexpected parameters") 118 119 return 120 } 121 122 if m.LockMock.mainExpectation != nil { 123 124 input := m.LockMock.mainExpectation.input 125 if input != nil { 126 testify_assert.Equal(m.t, *input, messageBusLockerMockLockInput{p}, "messageBusLocker.Lock got unexpected parameters") 127 } 128 129 return 130 } 131 132 if m.LockFunc == nil { 133 m.t.Fatalf("Unexpected call to messageBusLockerMock.Lock. %v", p) 134 return 135 } 136 137 m.LockFunc(p) 138 } 139 140 //LockMinimockCounter returns a count of messageBusLockerMock.LockFunc invocations 141 func (m *messageBusLockerMock) LockMinimockCounter() uint64 { 142 return atomic.LoadUint64(&m.LockCounter) 143 } 144 145 //LockMinimockPreCounter returns the value of messageBusLockerMock.Lock invocations 146 func (m *messageBusLockerMock) LockMinimockPreCounter() uint64 { 147 return atomic.LoadUint64(&m.LockPreCounter) 148 } 149 150 //LockFinished returns true if mock invocations count is ok 151 func (m *messageBusLockerMock) LockFinished() bool { 152 // if expectation series were set then invocations count should be equal to expectations count 153 if len(m.LockMock.expectationSeries) > 0 { 154 return atomic.LoadUint64(&m.LockCounter) == uint64(len(m.LockMock.expectationSeries)) 155 } 156 157 // if main expectation was set then invocations count should be greater than zero 158 if m.LockMock.mainExpectation != nil { 159 return atomic.LoadUint64(&m.LockCounter) > 0 160 } 161 162 // if func was set then invocations count should be greater than zero 163 if m.LockFunc != nil { 164 return atomic.LoadUint64(&m.LockCounter) > 0 165 } 166 167 return true 168 } 169 170 type mmessageBusLockerMockUnlock struct { 171 mock *messageBusLockerMock 172 mainExpectation *messageBusLockerMockUnlockExpectation 173 expectationSeries []*messageBusLockerMockUnlockExpectation 174 } 175 176 type messageBusLockerMockUnlockExpectation struct { 177 input *messageBusLockerMockUnlockInput 178 } 179 180 type messageBusLockerMockUnlockInput struct { 181 p context.Context 182 } 183 184 //Expect specifies that invocation of messageBusLocker.Unlock is expected from 1 to Infinity times 185 func (m *mmessageBusLockerMockUnlock) Expect(p context.Context) *mmessageBusLockerMockUnlock { 186 m.mock.UnlockFunc = nil 187 m.expectationSeries = nil 188 189 if m.mainExpectation == nil { 190 m.mainExpectation = &messageBusLockerMockUnlockExpectation{} 191 } 192 m.mainExpectation.input = &messageBusLockerMockUnlockInput{p} 193 return m 194 } 195 196 //Return specifies results of invocation of messageBusLocker.Unlock 197 func (m *mmessageBusLockerMockUnlock) Return() *messageBusLockerMock { 198 m.mock.UnlockFunc = nil 199 m.expectationSeries = nil 200 201 if m.mainExpectation == nil { 202 m.mainExpectation = &messageBusLockerMockUnlockExpectation{} 203 } 204 205 return m.mock 206 } 207 208 //ExpectOnce specifies that invocation of messageBusLocker.Unlock is expected once 209 func (m *mmessageBusLockerMockUnlock) ExpectOnce(p context.Context) *messageBusLockerMockUnlockExpectation { 210 m.mock.UnlockFunc = nil 211 m.mainExpectation = nil 212 213 expectation := &messageBusLockerMockUnlockExpectation{} 214 expectation.input = &messageBusLockerMockUnlockInput{p} 215 m.expectationSeries = append(m.expectationSeries, expectation) 216 return expectation 217 } 218 219 //Set uses given function f as a mock of messageBusLocker.Unlock method 220 func (m *mmessageBusLockerMockUnlock) Set(f func(p context.Context)) *messageBusLockerMock { 221 m.mainExpectation = nil 222 m.expectationSeries = nil 223 224 m.mock.UnlockFunc = f 225 return m.mock 226 } 227 228 //Unlock implements github.com/insolar/insolar/network/state.messageBusLocker interface 229 func (m *messageBusLockerMock) Unlock(p context.Context) { 230 counter := atomic.AddUint64(&m.UnlockPreCounter, 1) 231 defer atomic.AddUint64(&m.UnlockCounter, 1) 232 233 if len(m.UnlockMock.expectationSeries) > 0 { 234 if counter > uint64(len(m.UnlockMock.expectationSeries)) { 235 m.t.Fatalf("Unexpected call to messageBusLockerMock.Unlock. %v", p) 236 return 237 } 238 239 input := m.UnlockMock.expectationSeries[counter-1].input 240 testify_assert.Equal(m.t, *input, messageBusLockerMockUnlockInput{p}, "messageBusLocker.Unlock got unexpected parameters") 241 242 return 243 } 244 245 if m.UnlockMock.mainExpectation != nil { 246 247 input := m.UnlockMock.mainExpectation.input 248 if input != nil { 249 testify_assert.Equal(m.t, *input, messageBusLockerMockUnlockInput{p}, "messageBusLocker.Unlock got unexpected parameters") 250 } 251 252 return 253 } 254 255 if m.UnlockFunc == nil { 256 m.t.Fatalf("Unexpected call to messageBusLockerMock.Unlock. %v", p) 257 return 258 } 259 260 m.UnlockFunc(p) 261 } 262 263 //UnlockMinimockCounter returns a count of messageBusLockerMock.UnlockFunc invocations 264 func (m *messageBusLockerMock) UnlockMinimockCounter() uint64 { 265 return atomic.LoadUint64(&m.UnlockCounter) 266 } 267 268 //UnlockMinimockPreCounter returns the value of messageBusLockerMock.Unlock invocations 269 func (m *messageBusLockerMock) UnlockMinimockPreCounter() uint64 { 270 return atomic.LoadUint64(&m.UnlockPreCounter) 271 } 272 273 //UnlockFinished returns true if mock invocations count is ok 274 func (m *messageBusLockerMock) UnlockFinished() bool { 275 // if expectation series were set then invocations count should be equal to expectations count 276 if len(m.UnlockMock.expectationSeries) > 0 { 277 return atomic.LoadUint64(&m.UnlockCounter) == uint64(len(m.UnlockMock.expectationSeries)) 278 } 279 280 // if main expectation was set then invocations count should be greater than zero 281 if m.UnlockMock.mainExpectation != nil { 282 return atomic.LoadUint64(&m.UnlockCounter) > 0 283 } 284 285 // if func was set then invocations count should be greater than zero 286 if m.UnlockFunc != nil { 287 return atomic.LoadUint64(&m.UnlockCounter) > 0 288 } 289 290 return true 291 } 292 293 //ValidateCallCounters checks that all mocked methods of the interface have been called at least once 294 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 295 func (m *messageBusLockerMock) ValidateCallCounters() { 296 297 if !m.LockFinished() { 298 m.t.Fatal("Expected call to messageBusLockerMock.Lock") 299 } 300 301 if !m.UnlockFinished() { 302 m.t.Fatal("Expected call to messageBusLockerMock.Unlock") 303 } 304 305 } 306 307 //CheckMocksCalled checks that all mocked methods of the interface have been called at least once 308 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 309 func (m *messageBusLockerMock) CheckMocksCalled() { 310 m.Finish() 311 } 312 313 //Finish checks that all mocked methods of the interface have been called at least once 314 //Deprecated: please use MinimockFinish or use Finish method of minimock.Controller 315 func (m *messageBusLockerMock) Finish() { 316 m.MinimockFinish() 317 } 318 319 //MinimockFinish checks that all mocked methods of the interface have been called at least once 320 func (m *messageBusLockerMock) MinimockFinish() { 321 322 if !m.LockFinished() { 323 m.t.Fatal("Expected call to messageBusLockerMock.Lock") 324 } 325 326 if !m.UnlockFinished() { 327 m.t.Fatal("Expected call to messageBusLockerMock.Unlock") 328 } 329 330 } 331 332 //Wait waits for all mocked methods to be called at least once 333 //Deprecated: please use MinimockWait or use Wait method of minimock.Controller 334 func (m *messageBusLockerMock) Wait(timeout time.Duration) { 335 m.MinimockWait(timeout) 336 } 337 338 //MinimockWait waits for all mocked methods to be called at least once 339 //this method is called by minimock.Controller 340 func (m *messageBusLockerMock) MinimockWait(timeout time.Duration) { 341 timeoutCh := time.After(timeout) 342 for { 343 ok := true 344 ok = ok && m.LockFinished() 345 ok = ok && m.UnlockFinished() 346 347 if ok { 348 return 349 } 350 351 select { 352 case <-timeoutCh: 353 354 if !m.LockFinished() { 355 m.t.Error("Expected call to messageBusLockerMock.Lock") 356 } 357 358 if !m.UnlockFinished() { 359 m.t.Error("Expected call to messageBusLockerMock.Unlock") 360 } 361 362 m.t.Fatalf("Some mocks were not called on time: %s", timeout) 363 return 364 default: 365 time.Sleep(time.Millisecond) 366 } 367 } 368 } 369 370 //AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled, 371 //it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled()) 372 func (m *messageBusLockerMock) AllMocksCalled() bool { 373 374 if !m.LockFinished() { 375 return false 376 } 377 378 if !m.UnlockFinished() { 379 return false 380 } 381 382 return true 383 }