/*
* This file is part of the Intuitive DSL project.
* Copyright (c) 2026 DBA Labs - Switzerland. All rights reserved.
*
* This program is dual-licensed under a commercial license and the AGPLv3.
* For commercial licensing, contact us at [email protected] or visit https://www.dbalabs.ch.
*
* AGPLv3 licensing:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 (19 November 2007).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
*/
package ch.dbalabs.intuitivedsl.binding;
import ch.dbalabs.intuitivedsl.annotation.Bind;
import ch.dbalabs.intuitivedsl.annotation.OnClause;
import ch.dbalabs.intuitivedsl.parser.ParseResult;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the DslBinder component.
*
* @author DBA Labs
*/
class DslBinderTest {
/**
* Dummy class to act as an injection target for the binder.
*/
static class DummyTarget {
@Bind("username")
@SuppressWarnings("unused")
private String user;
@Bind("age")
@SuppressWarnings("unused")
private Integer userAge;
@OnClause("FORCE")
@SuppressWarnings("unused")
private boolean isForced;
public String getUser() { return user; }
public Integer getUserAge() { return userAge; }
public boolean isForced() { return isForced; }
}
@Test
void shouldInjectValuesUsingMethodHandles() {
// Arrange
DslBinder binder = new DslBinder(DummyTarget.class);
DummyTarget target = new DummyTarget();
// Simulate a successful parsing result
ParseResult result = new ParseResult();
result.addParameter("username", "", "john_doe");
result.addParameter("age", "", "35");
result.addKeyword("FORCE");
// Act
binder.bind(target, result);
// Assert
assertThat(target.getUser()).isEqualTo("john_doe");
// The binder should have automatically converted the string "35" to an Integer
assertThat(target.getUserAge()).isEqualTo(35);
// The boolean flag should have been flipped to true
assertThat(target.isForced()).isTrue();
}
}