Skip to content

Commit

Permalink
Merge pull request #9 from TareqK/develop
Browse files Browse the repository at this point in the history
Added Proper Inheritance to memory bus impl
  • Loading branch information
TareqK authored Mar 18, 2021
2 parents f977fe2 + 3a9084d commit ff48df1
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 14 deletions.
4 changes: 2 additions & 2 deletions easybus-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.kisoft</groupId>
<artifactId>easybus-core</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<parent>
<groupId>me.kisoft</groupId>
<artifactId>easybus-parent</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>

<name>Easybus Core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MemoryBusImpl() {
@Override
public void post(Object event) {
handlers.parallelStream()
.filter(handler -> StringUtils.equals(handler.getEventClassName(), event.getClass().getCanonicalName()))
.filter(handler -> handler.getEventClass().isInstance(event))
.collect(Collectors.toList())
.stream()
.forEach(handler -> doHandle(handler, event));
Expand Down
37 changes: 31 additions & 6 deletions easybus-core/src/test/java/me/kisoft/easybus/test/EasyBusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import me.kisoft.easybus.EasyBus;
import me.kisoft.easybus.MemoryBusImpl;
import me.kisoft.easybus.test.events.AsyncEvent;
import me.kisoft.easybus.test.events.ChildClassEvent;
import me.kisoft.easybus.test.events.ParentClassEvent;
import me.kisoft.easybus.test.events.SyncEvent;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
Expand All @@ -19,7 +21,6 @@
*/
public class EasyBusTest {


MemoryBusImpl memBus = new MemoryBusImpl();
EasyBus bus = new EasyBus(memBus);

Expand All @@ -31,21 +32,45 @@ public void clearBus() {
@Test
public void packageScanningTest() {
bus.search("me.kisoft.easybus.test.handlers");
assertEquals(memBus.getHandlers().size(), 2);
assertEquals(memBus.getHandlers().size(), 4);
}

@Test
public void classScanningTest() {
bus.search(this.getClass());
assertEquals(memBus.getHandlers().size(), 2);
assertEquals(memBus.getHandlers().size(), 4);
}

@Test
public void subClassEventTest() {
ChildClassEvent.checked = false;
ChildClassEvent.checkedSpecific = false;
ParentClassEvent.checked = false;
bus.search("me.kisoft.easybus.test.handlers");
bus.post(new ChildClassEvent());
assertEquals(ChildClassEvent.checked, true);
assertEquals(ChildClassEvent.checkedSpecific, true);
assertEquals(ParentClassEvent.checked, true);
}

@Test
public void specificityHandlerTest() {
ChildClassEvent.checked = false;
ChildClassEvent.checkedSpecific = false;
ParentClassEvent.checked = false;
bus.search("me.kisoft.easybus.test.handlers");
bus.post(new ParentClassEvent());
assertEquals(ChildClassEvent.checked, true);
assertEquals(ChildClassEvent.checkedSpecific, false);
assertEquals(ParentClassEvent.checked, true);
}

@Test
public void syncEventTest() {
bus.search("me.kisoft.easybus.test.handlers");
SyncEvent.checked = false;
bus.post(new SyncEvent());
assertEquals(SyncEvent.checked,true);
assertEquals(SyncEvent.checked, true);
}

@Test(timeout = 1000)
Expand All @@ -56,7 +81,7 @@ public void asyncEventTest() throws InterruptedException {
while (AsyncEvent.checked == false) {
Thread.sleep(20);
}
assertEquals(AsyncEvent.checked,true);
assertEquals(AsyncEvent.checked, true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021 tareq.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.kisoft.easybus.test.events;

import me.kisoft.easybus.Event;

/**
*
* @author tareq
*/
@Event
public class ChildClassEvent extends ParentClassEvent{
public static boolean checked = false;
public static boolean checkedSpecific = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 tareq.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.kisoft.easybus.test.events;

import me.kisoft.easybus.Event;

/**
*
* @author tareq
*/
@Event
public class ParentClassEvent {

public static boolean checked = false;

public static void doChildCheck() {
ChildClassEvent.checked = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 tareq.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.kisoft.easybus.test.handlers;

import me.kisoft.easybus.Handle;
import me.kisoft.easybus.test.events.ChildClassEvent;

/**
*
* @author tareq
*/
@Handle(event = ChildClassEvent.class, async = false)
public class ChildClassHandler {

public void handle(ChildClassEvent event) {
ChildClassEvent.checkedSpecific = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 tareq.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.kisoft.easybus.test.handlers;

import me.kisoft.easybus.Handle;
import me.kisoft.easybus.test.events.ParentClassEvent;

/**
*
* @author tareq
*/
@Handle(event = ParentClassEvent.class, async = false)
public class ParentClassHandler {

public void handle(ParentClassEvent event) {
ParentClassEvent.checked = true;
ParentClassEvent.doChildCheck();
}
}
4 changes: 2 additions & 2 deletions easybus-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>me.kisoft</groupId>
<artifactId>easybus-parent</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>
<groupId>me.kisoft</groupId>
<artifactId>easybus-mongodb</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<name>Easybus Mongodb</name>
<description>Simple, No Frills Event Bus for Java - Mongodb Backing Bus</description>
Expand Down
4 changes: 2 additions & 2 deletions easybus-rabbitmq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<parent>
<groupId>me.kisoft</groupId>
<artifactId>easybus-parent</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>
<artifactId>easybus-rabbitmq</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<name>Easybus RabbitMQ</name>
<description>Simple, No Frills Event Bus for Java Backed by RabbitMQ</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.kisoft</groupId>
<artifactId>easybus-parent</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<name>EasyBus</name>
<packaging>pom</packaging>
<properties>
Expand Down

0 comments on commit ff48df1

Please sign in to comment.